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.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""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")
|
||||
Reference in New Issue
Block a user