Problem
The current HybridRetriever fetches up to 10 documents from both BM25
and Vector search across multiple queries. Many of these documents are
only tangentially related to the user's query.
Passing noisy, low-relevance context to the LLM leads to:
- Unfocused or verbose answers
- Increased risk of hallucinated pathway/protein associations
- Wasted LLM tokens on irrelevant content
Proposed Fix
Wrap the HybridRetriever with LangChain's ContextualCompressionRetriever
using an EmbeddingsFilter compressor.
This filters out any retrieved document whose cosine similarity to the
query embedding falls below a threshold (e.g. 0.76), ensuring only
high-quality, relevant context reaches the LLM.
This is complementary to reranking (PR #116) — compression removes noise,
reranking orders what remains.
I am working on a fix and will submit a PR shortly.
Problem
The current HybridRetriever fetches up to 10 documents from both BM25
and Vector search across multiple queries. Many of these documents are
only tangentially related to the user's query.
Passing noisy, low-relevance context to the LLM leads to:
Proposed Fix
Wrap the HybridRetriever with LangChain's
ContextualCompressionRetrieverusing an
EmbeddingsFiltercompressor.This filters out any retrieved document whose cosine similarity to the
query embedding falls below a threshold (e.g. 0.76), ensuring only
high-quality, relevant context reaches the LLM.
This is complementary to reranking (PR #116) — compression removes noise,
reranking orders what remains.
I am working on a fix and will submit a PR shortly.