diff --git a/enterprise/app/services/captain/llm/conversation_faq_service.rb b/enterprise/app/services/captain/llm/conversation_faq_service.rb index b84ab45d6..6c046b178 100644 --- a/enterprise/app/services/captain/llm/conversation_faq_service.rb +++ b/enterprise/app/services/captain/llm/conversation_faq_service.rb @@ -51,6 +51,8 @@ class Captain::Llm::ConversationFaqService < Llm::BaseAiService return [] unless relation.exists? ApplicationRecord.transaction do + # Force an exact search because IVFFlat can miss matches after relation filters. + # SET LOCAL keeps the planner change scoped to this transaction. ApplicationRecord.connection.execute('SET LOCAL enable_indexscan = off') relation .nearest_neighbors(:embedding, embedding, distance: 'cosine')