INCIDENT: Drop HNSW index before vector dimension ALTER #159
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/pal-e-api!159
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "158-fix-migration-drop-hnsw-index"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes CrashLoopBackOff on both pal-e-docs pods. The Alembic migration from PR #157 tried to ALTER the embedding column to vector(2560), but the existing HNSW index has a hard 2000-dimension limit in pgvector. The fix drops the index before the ALTER.
Changes
alembic/versions/o5j6k7l8m9n0_fix_embedding_vector_dimension.py-- AddedDROP INDEX IF EXISTS ix_blocks_embeddingbefore the ALTER TABLE statement. Downgrade restores the HNSW index on vector(768) for reversibility. No index recreation in upgrade (sequential scan is fine for ~5600 blocks).Test Plan
pytest tests/ -v-- 497 passedruff check+ruff format --check-- cleanReview Checklist
Related
plan-pal-e-docsCloses #158
PR #159 Review
BLOCKERS
None.
CODE ANALYSIS
Upgrade path (correct):
DROP INDEX IF EXISTS ix_blocks_embedding-- removes the HNSW index that has a hard 2000-dimension limit in pgvectorALTER TABLE blocks ALTER COLUMN embedding TYPE vector(2560)-- now succeeds without the index blocking itUPDATE blocks SET embedding_status = 'pending' WHERE embedding_status = 'error'-- requeues previously-failed blocksThe ordering is correct. The
IF EXISTSguard makes the migration idempotent (safe to re-run if the first attempt partially succeeded). No index recreation is intentional -- sequential scan on ~5,600 blocks is fine, and HNSW cannot support 2560 dimensions anyway.Downgrade path (correct):
ALTER TABLE blocks ALTER COLUMN embedding TYPE vector(768)-- shrinks column first (will fail if 2560-dim data exists, documented in comment)CREATE INDEX ix_blocks_embedding ON blocks USING hnsw (embedding vector_cosine_ops)-- recreates index on 768-dim column (within 2000-dim limit)Ordering is correct: column must be 768-dim before the HNSW index can be created on it.
Cross-reference verified:
l2g3h4i5j6k7_add_vector_embeddings.py(line 47-49). That is the onlyCREATE INDEXon the embedding column in the migration history. No other indexes reference the embedding column./home/ldraney/pal-e-docs/src/pal_e_docs/models.py:207already hasVector(2560), confirming the model matches the migration target.down_revisionpoints ton4i5j6k7l8m9(the boards migration), which is the correct parent in the chain.NITS
None. This is a clean, minimal incident fix.
SOP COMPLIANCE
158-fix-migration-drop-hnsw-indexreferences issue #158plan-pal-e-docsCloses #158present in PR bodyVERDICT: APPROVED
Clean incident fix. Correct ordering, idempotent, symmetric downgrade, no scope creep. Ship it.