Skip to content

feat: HybridRetriever passes noisy, low-relevance documents to the LLM #132

@bhavyakeerthi3

Description

@bhavyakeerthi3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions