Migration

Upgrade Mnemosyne versions and migrate data between instances.

Version Upgrade

Check Current Version

python -c "import mnemosyne; print(mnemosyne.__version__)"

Upgrade Steps

# 1. Backup current database
cp mnemosyne.db mnemosyne-pre-upgrade.db

# 2. Upgrade package
pip install --upgrade mnemosyne-memory

# 3. Verify (schema migrations run automatically on first connection)
python -c "from mnemosyne import Memory; m = Memory(); print(m.stats())"
Automatic Migrations

Mnemosyne uses automatic schema migrations that run on first connection after an upgrade. There is no python -m mnemosyne.migrate command. If migration fails, check logs with MNEMOSYNE_LOG_LEVEL=debug.

Schema Migrations

Mnemosyne uses automatic schema migrations:

VersionMigrationDescription
1.0 → 2.0m_1_0_to_2_0Add semantic memory, FTS5 indices
2.0 → 2.1m_2_0_to_2_1Add session_id to episodic
2.1 → 2.2m_2_1_to_2_2Add temporal graph indexes

Migrations run automatically on first connection. No manual intervention needed.

Cross-Instance Migration

Export from old instance, import to new using the Python SDK:

from mnemosyne import Memory

# Export from old database
old_mem = Memory(db_path="old.db")
old_mem.export_to_file("export.json")

# Import into new database
new_mem = Memory(db_path="new.db")
new_mem.import_from_file("export.json")

# Verify
print(new_mem.stats())

Export Formats

FormatUse CaseSize
JSONHuman-readable, version controlLarge
SQLiteFast, preserves all metadataCompact

Legacy Migration

For migrating from pre-2.0 data formats, use the migration script:

python scripts/migrate_from_legacy.py --db mnemosyne.db

Rollback

If upgrade fails:

# Stop application
# Restore pre-upgrade backup
cp mnemosyne-pre-upgrade.db mnemosyne.db

# Downgrade package
pip install mnemosyne-memory==1.0.0

# Restart
Breaking Changes

Major version upgrades (1.x → 2.x) may include breaking changes. Always read the changelog and test in staging before production deployment.