From f22e66b869d316c75c866281648b051c9e89f257 Mon Sep 17 00:00:00 2001 From: aakashb95 Date: Tue, 14 Jul 2026 23:17:34 +0530 Subject: [PATCH] fix(captain): require iterative vector scans --- ...assistant_response_embedding_index_with_cosine.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/db/migrate/20260714230000_replace_captain_assistant_response_embedding_index_with_cosine.rb b/db/migrate/20260714230000_replace_captain_assistant_response_embedding_index_with_cosine.rb index be2f4b449..163e3a5da 100644 --- a/db/migrate/20260714230000_replace_captain_assistant_response_embedding_index_with_cosine.rb +++ b/db/migrate/20260714230000_replace_captain_assistant_response_embedding_index_with_cosine.rb @@ -3,8 +3,11 @@ class ReplaceCaptainAssistantResponseEmbeddingIndexWithCosine < ActiveRecord::Mi OLD_INDEX_NAME = 'vector_idx_knowledge_entries_embedding'.freeze NEW_INDEX_NAME = 'vector_idx_captain_assistant_responses_embedding_cosine'.freeze + MINIMUM_PGVECTOR_VERSION = Gem::Version.new('0.8.0') def up + ensure_iterative_scans_supported! + add_index :captain_assistant_responses, :embedding, using: :ivfflat, @@ -23,4 +26,13 @@ class ReplaceCaptainAssistantResponseEmbeddingIndexWithCosine < ActiveRecord::Mi algorithm: :concurrently remove_index :captain_assistant_responses, name: NEW_INDEX_NAME, algorithm: :concurrently end + + private + + def ensure_iterative_scans_supported! + installed_version = Gem::Version.new(select_value("SELECT extversion FROM pg_extension WHERE extname = 'vector'")) + return if installed_version >= MINIMUM_PGVECTOR_VERSION + + raise StandardError, "pgvector #{MINIMUM_PGVECTOR_VERSION} or newer is required for filtered FAQ search" + end end