feat(retrieval): add LLM query expansion with multi-query fusion#159
Open
Salomondiei08 wants to merge 1 commit intoEverMind-AI:mainfrom
Open
feat(retrieval): add LLM query expansion with multi-query fusion#159Salomondiei08 wants to merge 1 commit intoEverMind-AI:mainfrom
Salomondiei08 wants to merge 1 commit intoEverMind-AI:mainfrom
Conversation
Addresses vocabulary mismatch failure mode in hybrid retrieval where stored memories use different terms than the query (e.g. 'rescue inhaler protocol' stored vs 'gym bag' queried). Changes: - src/memory_layer/query_expansion.py: new module implementing expand_query() which generates 2-3 LLM paraphrase variants of a query using a structured prompt. Falls back silently (returns []) on any LLM failure. Also provides merge_hits_by_id() for union-dedup of per-query result sets. - src/agentic_layer/memory_manager.py: retrieve_mem_hybrid() now routes through _search_hybrid_with_query_expansion() instead of _search_hybrid(). This runs keyword+vector search in parallel for the original query and each variant, merges results by memory id (original-query scores preserved), then reranks the union against the original query for consistent scoring. Falls back to plain hybrid search when expansion produces no variants. Inspired by RAG-Fusion / HyDE. Recall improvement is measurable via Recall@K with single-query vs expanded-query baselines.
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.
Checklist
Additional Notes
_search_hybridis unchanged and still used by the AGENTIC and RRF retrieval paths — only the HYBRID path is affectedBreaking Changes
None.
_search_hybridis preserved as-is. The new routing inretrieve_mem_hybridis fully backward compatible and falls back to the original behavior on any failure.