Skip to main content

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:
Examples:
  • 00001-collections.sqlite.sql
  • 00002-segments.sqlite.sql
  • 00003-collection-dimension.sqlite.sql
  • 00004-tenants-databases.sqlite.sql

Migration Subsystems

Chroma manages migrations for three subsystems:
  1. SysDB (chromadb/migrations/sysdb/) - System database for collections, segments, tenants
  2. Embeddings Queue (chromadb/migrations/embeddings_queue/) - Write-ahead log for embeddings
  3. MetaDB (chromadb/migrations/metadb/) - Metadata and configuration storage

Configuration

Migration Modes

Control migration behavior with the migrations setting:
Or via environment variable:

Migration Mode Descriptions

  • apply (default) - Automatically apply all pending migrations
  • validate - Check that all migrations are applied, raise error if not
  • none - Skip migration checks entirely (not recommended)

Hash Algorithm

Migrations use a hash algorithm to verify file integrity:
Or via environment variable:
Important: Once set and migrations are applied, you cannot change the hash algorithm without manual intervention.

Upgrading Chroma

Standard Upgrade Process

For most upgrades, simply update the package:
Migrations run automatically on first startup:

Upgrading from Legacy Versions

If upgrading from versions before 0.4.0, use the chroma-migrate tool:
See the Migration Guide for detailed instructions.

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:
Output:

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:
  1. Stop Chroma
  2. Restore from backup
  3. 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:
  1. Restore original migration files
  2. Or restore from backup and re-migrate

InconsistentHashError

Error: Inconsistent hashes in <path> Cause: Migration file has been modified after being applied Solution:
  1. Restore original migration file from the correct Chroma version
  2. Or restore from backup

Custom Migrations

Creating Custom Migrations

For advanced use cases, you can add custom migrations:
Place in migration directory:
Warning: Custom migrations may conflict with future Chroma updates. Use version numbers > 90000 to minimize conflicts.

Production Migration Strategy

Pre-Production Testing

  1. Test in staging environment
  2. Verify migration success
  3. Performance testing

Production Migration

  1. Schedule maintenance window
  2. Backup production data
  3. Stop Chroma server
  4. Upgrade package
  5. Apply migrations
  6. Verify migration
  7. Start Chroma server
  8. Monitor for issues

Rollback Plan

Prepare rollback procedures:

Best Practices

  1. Always backup before upgrading - No exceptions
  2. Test in staging first - Never upgrade production directly
  3. Use migrations="validate" in CI/CD - Catch migration issues early
  4. Monitor migration logs - Watch for warnings or errors
  5. Keep migration history - Maintain records of when migrations were applied
  6. Use consistent hash algorithm - Choose sha256 for production, stick with it
  7. Schedule maintenance windows - Don’t migrate during peak traffic
  8. Verify after migration - Test queries, check data integrity
  9. Have rollback plan ready - Document and test rollback procedures
  10. 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

  1. Check database size:
  2. Monitor migration progress:
  3. 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:
  1. Ensure Chroma is stopped
  2. Check for stale connections:
  3. Kill any processes holding locks

Corruption after failed migration

Solution:
  1. Restore from backup immediately
  2. Investigate failure cause
  3. Fix underlying issue
  4. Re-attempt migration

Next Steps