Overview
Chroma uses a migration system to safely upgrade database schemas across versions. Migrations ensure your data remains consistent and compatible as Chroma evolves. This guide covers the migration system, upgrading procedures, and best practices.Migration System
Chroma’s migration system is built into the database layer and manages schema changes across multiple subsystems.How Migrations Work
Migrations are:- Version-numbered - Each migration has a unique version number (e.g.,
00001,00002) - Scope-specific - Different database implementations (SQLite, PostgreSQL) have separate migrations
- Hash-verified - Migration file contents are hashed to detect tampering
- Sequential - Migrations must be applied in order
- Idempotent - Safe to run multiple times
Migration Files
Migration files follow the naming convention:00001-collections.sqlite.sql00002-segments.sqlite.sql00003-collection-dimension.sqlite.sql00004-tenants-databases.sqlite.sql
Migration Subsystems
Chroma manages migrations for three subsystems:- SysDB (
chromadb/migrations/sysdb/) - System database for collections, segments, tenants - Embeddings Queue (
chromadb/migrations/embeddings_queue/) - Write-ahead log for embeddings - MetaDB (
chromadb/migrations/metadb/) - Metadata and configuration storage
Configuration
Migration Modes
Control migration behavior with themigrations setting:
Migration Mode Descriptions
apply(default) - Automatically apply all pending migrationsvalidate- Check that all migrations are applied, raise error if notnone- Skip migration checks entirely (not recommended)
Hash Algorithm
Migrations use a hash algorithm to verify file integrity:Upgrading Chroma
Standard Upgrade Process
For most upgrades, simply update the package:Upgrading from Legacy Versions
If upgrading from versions before 0.4.0, use thechroma-migrate tool:
Version Compatibility
Chroma follows semantic versioning:- Major versions (e.g., 1.0.0 → 2.0.0) - May require manual migration
- Minor versions (e.g., 0.4.0 → 0.5.0) - Automatic migrations
- Patch versions (e.g., 0.4.1 → 0.4.2) - No migrations needed
Migration Validation
Pre-Upgrade Validation
Before upgrading, validate your current state:Migration Status
Check applied migrations in the database:Manual Migration Procedures
Backing Up Data
Always backup before migrating:Applying Migrations Manually
In rare cases, you may need to apply migrations manually:Rolling Back Migrations
Chroma does not support automatic rollback. To rollback:- Stop Chroma
- Restore from backup
- Downgrade Chroma version
Migration Errors
UninitializedMigrationsError
Error:Migrations have not been initialized
Cause: Migration table doesn’t exist
Solution:
UnappliedMigrationsError
Error:Unapplied migrations in <dir>, starting with version <N>
Cause: New migrations exist that haven’t been applied
Solution:
InconsistentVersionError
Error:Inconsistent migration versions in <dir>
Cause: Migration sequence has been modified
Solution:
- Restore original migration files
- Or restore from backup and re-migrate
InconsistentHashError
Error:Inconsistent hashes in <path>
Cause: Migration file has been modified after being applied
Solution:
- Restore original migration file from the correct Chroma version
- Or restore from backup
Custom Migrations
Creating Custom Migrations
For advanced use cases, you can add custom migrations:Production Migration Strategy
Pre-Production Testing
-
Test in staging environment
-
Verify migration success
-
Performance testing
Production Migration
- Schedule maintenance window
-
Backup production data
-
Stop Chroma server
-
Upgrade package
-
Apply migrations
-
Verify migration
-
Start Chroma server
-
Monitor for issues
Rollback Plan
Prepare rollback procedures:Best Practices
- Always backup before upgrading - No exceptions
- Test in staging first - Never upgrade production directly
- Use
migrations="validate"in CI/CD - Catch migration issues early - Monitor migration logs - Watch for warnings or errors
- Keep migration history - Maintain records of when migrations were applied
- Use consistent hash algorithm - Choose
sha256for production, stick with it - Schedule maintenance windows - Don’t migrate during peak traffic
- Verify after migration - Test queries, check data integrity
- Have rollback plan ready - Document and test rollback procedures
- Follow release notes - Read migration notes for each version
Migration History
Key migrations in Chroma history:Version 0.4.0
- Introduced new migration system
- Added tenant and database support
- Migrated from legacy DuckDB format
Version 0.5.0
- Added collection dimension tracking
- Improved segment management
- Enhanced metadata indexing
Version 0.5.6
- Automatic purging improvements
- Storage optimization
Troubleshooting
Migration hangs or takes too long
-
Check database size:
-
Monitor migration progress:
-
For very large databases, consider:
- Increasing timeouts
- Running during off-peak hours
- Temporarily increasing resources
Database locked errors
Cause: Another process has the database open Solution:- Ensure Chroma is stopped
- Check for stale connections:
- Kill any processes holding locks
Corruption after failed migration
Solution:- Restore from backup immediately
- Investigate failure cause
- Fix underlying issue
- Re-attempt migration
Next Steps
- Configure Observability to monitor migrations
- Review Configuration options
- Optimize Performance after migrations