Repolode
Raudaschl

Raudaschl/rag-fusion

Python reference implementation of RAG-Fusion, combining LLM query rewrites, BM25 and vector search, and Reciprocal Rank Fusion to improve retrieval, with an NFCorpus evaluation harness.

Stars
960
Forks
113
Open issues
0
Last commit
28 days ago

What is it?

RAG-Fusion is a retrieval method for retrieval-augmented generation. An LLM rewrites the user's query into several variants from different angles, each variant is searched with both BM25 keyword search and vector search, and the ranked lists are merged with Reciprocal Rank Fusion so that documents appearing across many lists rise to the top. It targets cases where a single phrasing of a query misses relevant material, such as when user vocabulary differs from how the corpus is indexed.

The repository contains a basic pipeline in main.py that uses vector search with ChromaDB and OpenAI, plus an evaluation harness in eval/ that compares baseline, hybrid, RAG-Fusion and hybrid-diverse variants on the NFCorpus dataset from BEIR. It also includes cross-encoder reranking stages and experiment write-ups measuring NDCG, precision, recall and MRR, along with cost and latency measurements per configuration.

The repo's measurements suggest that adding a reranker after hybrid fusion yields small but statistically significant gains, while vector-only fusion gives little benefit once a strong reranker is in place.

Key features

  • 01Generates multiple LLM rewrites of a user query to cover different phrasings.
  • 02Combines BM25 keyword search and vector search for each query variant.
  • 03Merges ranked results with Reciprocal Rank Fusion.
  • 04Supports cross-encoder and other reranker stages on the fused candidate pool.
  • 05Evaluates retrieval variants on the NFCorpus dataset with IR metrics and bootstrap confidence intervals.
  • 06Caches LLM query rewrites on disk and persists ChromaDB embeddings locally.

Use cases

  • Searching specialist literature such as medical or scientific papers where terminology varies.
  • Improving recall in retrieval pipelines where missing a relevant document is costly.
  • Experimenting with query rewriting and rank fusion before adopting them in a RAG system.

Quick start

  1. 1

    Install the core dependencies

    pip install openai chromadb python-dotenv tqdm tabulate rank_bm25
  2. 2

    Create the .env file from the template

    cp .env.example .env
  3. 3

    Add your OpenAI API key to .env, then run the demo

    python main.py

Things to know

  • Running the demo and rewrites requires a paid OpenAI API key.
  • The demo in main.py uses vector search only; the best-performing hybrid-plus-rerank setup lives in eval/ and needs extra packages.
  • Experiments rely on specific LLM and decision models, some of which may be retired or unavailable.

Topics

#rag#information-retrieval#vector-search#reciprocal-rank-fusion#query-expansion#reranking#chromadb#openai#python#rag-fusion

FAQ

What is rag-fusion?
Python reference implementation of RAG-Fusion, combining LLM query rewrites, BM25 and vector search, and Reciprocal Rank Fusion to improve retrieval, with an NFCorpus evaluation harness. RAG-Fusion is a retrieval method for retrieval-augmented generation. An LLM rewrites the user's query into several variants from different angles, each variant is searched with both BM25 keyword search and vector search, and the ranked lists are merged with Reciprocal Rank Fusion so that documents appearing across many lists rise to the top. It targets cases where a single phrasing of a query misses relevant material, such as when user vocabulary differs from how the corpus is indexed.
Is rag-fusion free to use? What license does it have?
rag-fusion is open source under the MIT license. Check the license terms before using it in commercial products.
Is rag-fusion still maintained?
Actively maintained. The last commit to rag-fusion was on Oct 10, 2026.
What can I use rag-fusion for?
Searching specialist literature such as medical or scientific papers where terminology varies. Improving recall in retrieval pipelines where missing a relevant document is costly. Experimenting with query rewriting and rank fusion before adopting them in a RAG system.
How do I install rag-fusion?
Install the core dependencies: pip install openai chromadb python-dotenv tqdm tabulate rank_bm25 Create the .env file from the template: cp .env.example .env Add your OpenAI API key to .env, then run the demo: python main.py
Where can I get rag-fusion?
The source code and installation instructions are on GitHub: https://github.com/Raudaschl/rag-fusion

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects