From ea64a51129d6b5585adfd0886c7502023a20ed47 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Mon, 8 Jun 2026 12:20:03 +0800 Subject: [PATCH] fix(migrations): update migration comments for HNSW index Corrected the migration comments in both the up and down SQL files to reflect the accurate migration version (000059) for the 1024-dim HNSW index. This ensures clarity and consistency in the migration history. --- .../000059_embeddings_hnsw_1024.down.sql | 2 +- .../versioned/000059_embeddings_hnsw_1024.up.sql | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/migrations/versioned/000059_embeddings_hnsw_1024.down.sql b/migrations/versioned/000059_embeddings_hnsw_1024.down.sql index 3d0cf2bc..78c130c1 100644 --- a/migrations/versioned/000059_embeddings_hnsw_1024.down.sql +++ b/migrations/versioned/000059_embeddings_hnsw_1024.down.sql @@ -1,2 +1,2 @@ --- Down migration: drop the 1024-dim HNSW partial index added in 000044. +-- Down migration: drop the 1024-dim HNSW partial index added in 000059. DROP INDEX IF EXISTS embeddings_embedding_idx_1024; diff --git a/migrations/versioned/000059_embeddings_hnsw_1024.up.sql b/migrations/versioned/000059_embeddings_hnsw_1024.up.sql index 450dae9f..cef82240 100644 --- a/migrations/versioned/000059_embeddings_hnsw_1024.up.sql +++ b/migrations/versioned/000059_embeddings_hnsw_1024.up.sql @@ -1,4 +1,4 @@ --- Migration 000044: HNSW index for bge-m3 / 1024-dim embeddings +-- Migration 000059: HNSW index for bge-m3 / 1024-dim embeddings -- -- Upstream's 000002 only created HNSW partial indexes for dim=3584 (OpenAI -- text-embedding-3-large) and dim=798. Both queries fall through to a @@ -21,19 +21,25 @@ -- CREATE INDEX CONCURRENTLY before applying this migration, then this -- block becomes idempotent via IF NOT EXISTS. +-- Guard on the embeddings table's existence (not the vector extension): +-- deployments whose RETRIEVE_DRIVER excludes postgres run 000002 with +-- app.skip_embedding=true, so neither the table nor the vector extension is +-- created. Checking the table directly matches the established convention +-- (see 000007) and avoids a hard CREATE INDEX failure that would leave +-- schema_migrations dirty and block every later migration. DO $$ BEGIN - IF EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'vector') THEN + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'embeddings') THEN IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_embedding_idx_1024' OR indexname LIKE 'embeddings_embedding%1024%') THEN CREATE INDEX embeddings_embedding_idx_1024 ON embeddings USING hnsw ((embedding::halfvec(1024)) halfvec_cosine_ops) WITH (m = 16, ef_construction = 64) WHERE (dimension = 1024); - RAISE NOTICE '[Migration 000044] Created HNSW index for dimension 1024 (bge-m3)'; + RAISE NOTICE '[Migration 000059] Created HNSW index for dimension 1024 (bge-m3)'; ELSE - RAISE NOTICE '[Migration 000044] HNSW index for dimension 1024 already exists'; + RAISE NOTICE '[Migration 000059] HNSW index for dimension 1024 already exists'; END IF; ELSE - RAISE NOTICE '[Migration 000044] pgvector extension not installed · skipping'; + RAISE NOTICE '[Migration 000059] embeddings table does not exist · skipping'; END IF; END $$;