diff --git a/prisma/migrations/20260529071403_add_hnsw_index_to_asset_embeddings/migration.sql b/prisma/migrations/20260529071403_add_hnsw_index_to_asset_embeddings/migration.sql index 5091cdd6..37fb8b1b 100644 --- a/prisma/migrations/20260529071403_add_hnsw_index_to_asset_embeddings/migration.sql +++ b/prisma/migrations/20260529071403_add_hnsw_index_to_asset_embeddings/migration.sql @@ -1,5 +1,11 @@ --- Enable iterative index scans for HNSW so filtered queries don't fall back to seq scan -SET hnsw.iterative_scan = relaxed_order; +-- Enable iterative index scans for HNSW so filtered queries don't fall back to seq scan. +-- Uses current_database() so this works across all environments without hardcoding the DB name. +-- ALTER DATABASE ... SET persists the GUC for all future connections to this database. +DO $$ +BEGIN + EXECUTE format('ALTER DATABASE %I SET hnsw.iterative_scan = ''relaxed_order''', current_database()); +END; +$$; -- CreateIndex: HNSW index on asset_embeddings.embedding -- Uses cosine distance ops (suited for normalized OpenAI-style embeddings)