"""Record which model produced each stored embedding. Without this a model change silently mixes vectors from different embedding spaces, and cosine distance between them is meaningless. Revision ID: r0d1e2f3a475 Revises: q9c0d1e2f364 """ from alembic import op revision = "r0d1e2f3a475" down_revision = "q9c0d1e2f364" branch_labels = None depends_on = None def upgrade(): op.execute("ALTER TABLE questions ADD COLUMN IF NOT EXISTS embedding_model VARCHAR(120)") op.execute("ALTER TABLE questions ADD COLUMN IF NOT EXISTS embedded_at TIMESTAMP") op.execute("CREATE INDEX IF NOT EXISTS ix_questions_embedding_model ON questions(embedding_model)") def downgrade(): op.execute("DROP INDEX IF EXISTS ix_questions_embedding_model") op.execute("ALTER TABLE questions DROP COLUMN IF EXISTS embedded_at") op.execute("ALTER TABLE questions DROP COLUMN IF EXISTS embedding_model")