fix(kb): Chat can keyword-search any saved document, not just the semantic index#29
Merged
Merged
Conversation
…index kb_search ran semantic-only whenever an embed model was reachable, ranking solely over the embeddings index — so a document not yet embedded (reindex is a 5-docs/tick trickle, or the doc predates configuring an embed model) was invisible to Chat, even when its content plainly matched. The lexical keyword scan of full content only ran as a fallback when embedding failed. Now kb_search ALWAYS runs the keyword scan (reaches any stored document) and, when an embed model is reachable, merges in the semantic (meaning) hits for extra recall — keyword matches first so an un-embedded doc stays visible. Degrades to keyword-only (flagged) when no embed model is reachable, as before. Adds a regression test: with semantic available, an un-embedded doc is still found. Full suite green (626).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Chat couldn't find a document stored in Knowledge unless it was in the semantic index.
kb_searchran semantic-only whenever an embed model was reachable — ranking purely over the embeddings table. A document that wasn't embedded yet was invisible to Chat, even when its content plainly matched:KnowledgeBase.search) already exists but only ran as a fallback when embedding failed.That's the "Chat can only search the index" you hit.
The fix
kb_searchnow always runs the keyword scan over every document's content — so a quick search reaches any stored document — and, when an embed model is reachable, merges in the semantic (meaning) hits for extra recall. Keyword matches come first, so an un-embedded doc stays visible; semantic augments rather than replaces. Still degrades to keyword-only (flaggeddegraded) when no embed model is reachable, exactly as before.Also tightened the tool description so the model reaches for it to look things up.
Test
New regression test: with semantic available, an un-embedded doc is still found by keyword (fails on the old code, passes now). Full backend suite green (626), ruff clean.
Backend-only; independent of the schedules PRs.