fix(memory/holographic): sanitize FTS5 queries for natural-language recall#11333
Open
cyb3rwr3n wants to merge 1 commit into
Open
fix(memory/holographic): sanitize FTS5 queries for natural-language recall#11333cyb3rwr3n wants to merge 1 commit into
cyb3rwr3n wants to merge 1 commit into
Conversation
…ecall The FactRetriever's _fts_candidates passed the raw query string directly to FTS5's MATCH operator. FTS5 defaults to AND-between-tokens, which means any multi-word prose query like 'what happened with the deployment rollback' required every single token to co-occur in a fact — dropping recall to zero on the kind of queries agents actually issue via prefetch(). Fix: add _sanitize_fts_query() that: - tokenizes the query and drops English stopwords - strips FTS5 operator characters per token - OR-joins the remaining content tokens as phrase literals For pathological inputs (all stopwords, empty), falls back to the raw query so the caller sees zero results instead of a SQL error. This is a pure-retrieval-quality fix — the HRR + Jaccard reranking stages still keep precision high. Ships with 10 tests covering the sanitizer and retrieval integration.
9a65f4c to
2c930a3
Compare
Collaborator
Open
5 tasks
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.
Summary
The holographic memory provider's
FactRetriever._fts_candidatespasses the raw user query directly to FTS5'sMATCHoperator. FTS5 defaults to AND-between-tokens, which means any multi-word prose query requires every token to co-occur in a fact. For theprefetch()path where the query comes straight from the user message, this reduces recall to near-zero on natural-language prompts.Example, before this fix:
The prefetch hook in
run_agent.pythat injects memory context on every turn was therefore silently missing relevant facts whenever the user phrased their message in prose.Fix
Add
_sanitize_fts_query()that:"tok1" OR "tok2" OR ...No changes to the HRR + Jaccard + trust reranking — those keep precision high once the candidate pool isn't empty.
Test plan
Ships with 10 new tests in
tests/plugins/memory/test_holographic_retrieval.py:MemoryStore:[]without crashingExisting memory/fact-store test suite (329 tests) still passes.
Notes
@classmethodso tests can call it directly without instantiating a retriever + store.