Raudaschl/rag-fusion

RAG-Fusion: multi-query generation + Reciprocal Rank Fusion for better retrieval-augmented generation. Includes evaluation harness with NFCorpus/BEIR.

What it solves

Traditional search often fails when a user's vocabulary doesn't match the indexed text (e.g., using lay terms instead of technical jargon). RAG-Fusion addresses this by expanding a single user query into multiple variations to capture different facets of the intent, ensuring that relevant documents aren't missed due to phrasing differences.

How it works

  1. Query Generation: An LLM (GPT) generates several variations of the original user query to cover different angles and synonyms.
  2. Vector Search: The system performs vector-based searches (using ChromaDB) for every generated query variation.
  3. Reciprocal Rank Fusion (RRF): The results from all these searches are combined. Documents that appear consistently across multiple query perspectives are boosted higher in the final ranking.
  4. Output Generation: The final re-ranked list of documents is produced, which can then be synthesized into a natural language answer by an LLM.

Who it’s for

This approach is ideal for users dealing with specialist corpora where terminology mismatch is common, such as:

  • Academic, scientific, or biomedical research.
  • Legal e-discovery and patent prior-art search.
  • Long-tail e-commerce search.
  • Exploratory workflows where recall (finding all relevant documents) is more important than precision.

Highlights

  • Hybrid Search Support: Combines BM25 (keyword) and vector search for better precision and semantic breadth.
  • Diverse Prompting: Uses specialized prompts to force the LLM to generate genuinely different query angles.
  • Quantitative Evaluation: Includes a full evaluation harness using the NFCorpus dataset to measure Precision, Recall, NDCG, and MRR.
  • Adaptive Routing Recommendation: Suggests running fusion only when a "weakness signal" is detected to balance compute costs and latency.