Files
FabledScribe/alembic/versions/0052_clear_note_embeddings_for_fastembed.py
bvandeusen 12d0ebeb84 migration: clear note_embeddings for fastembed swap (768d → 384d)
JSONB column so no type change needed — just wipe and let the
startup backfill regenerate at the new dimension.
2026-05-26 21:01:23 -04:00

34 lines
1012 B
Python

"""clear note_embeddings for fastembed swap
Revision ID: 0052
Revises: 0051
Create Date: 2026-05-26
Embeddings stored in `note_embeddings.embedding` (JSONB) were generated by
Ollama's nomic-embed-text model (768-dim). The fastembed swap uses
BAAI/bge-small-en-v1.5 (384-dim). Mixed-dim vectors would break the
Python-side cosine similarity (length mismatch), so we wipe the table.
The startup hook `services.embeddings.backfill_note_embeddings` regenerates
everything at the new dimension on next boot. There's no column-type change
because the column is JSONB — dimensionless on the storage side.
Downgrade is the same operation: a fresh deployment of the prior code would
backfill with the old model. No data is lost that the next boot won't restore.
"""
from alembic import op
revision = "0052"
down_revision = "0051"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute("DELETE FROM note_embeddings")
def downgrade() -> None:
op.execute("DELETE FROM note_embeddings")