DEV.co
Vector Databases · Raudaschl

rag-fusion

RAG-Fusion is a Python library that improves retrieval-augmented generation (RAG) by generating multiple query variations and combining their search results using a ranking algorithm called Reciprocal Rank Fusion. It's designed to surface relevant documents that a single query phrasing might miss, particularly when user vocabulary differs from indexed text.

Source: GitHub — github.com/Raudaschl/rag-fusion
946
GitHub stars
113
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
RepositoryRaudaschl/rag-fusion
OwnerRaudaschl
Primary languagePython
LicenseMIT — OSI-approved
Stars946
Forks113
Open issues0
Latest releaseUnknown
Last updated2026-04-26
Sourcehttps://github.com/Raudaschl/rag-fusion

What rag-fusion is

RAG-Fusion implements multi-query generation via LLM (OpenAI), parallel vector search (ChromaDB), and Reciprocal Rank Fusion re-ranking, with optional hybrid BM25+vector fusion and cross-encoder reranking. The repository includes an evaluation harness with NFCorpus/BEIR benchmarks, paired-bootstrap confidence intervals, and empirical comparison across six retrieval variants.

Quickstart

Get the rag-fusion source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/Raudaschl/rag-fusion.gitcd rag-fusion# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Academic and Scientific Literature Search

Handles terminology mismatch between lay queries and technical indexed text; benefits from recall-focused retrieval where missing a relevant paper is costly. Works well with diverse paraphrasings of research intent.

Patent Prior-Art and Legal E-Discovery

Excels when documents must be discovered across varied vocabularies and phrasing conventions. Multi-query generation captures different legal perspectives on the same underlying claim or statute.

Long-Tail E-Commerce and Specialist Corpora

Recovers results for non-standard user queries ('phone holder thing for car') by generating canonical alternatives. Effective on embedded models unfamiliar with niche product catalogs or domain-specific language.

Implementation considerations

  • Requires active OpenAI API key and account; multi-query generation and LLM-judged evaluation incur token costs that scale with corpus and query volume.
  • Hybrid+Diverse variant (BM25 + vector + LLM rewrites + cross-encoder) produces measurable improvements but requires BM25 index setup and optional reranker model integration.
  • Vector search relies on ChromaDB and `all-MiniLM-L6-v2` embedding by default; consider embedding model choice and ChromaDB configuration for production scale.
  • Evaluation harness uses NFCorpus (3.6k docs); validate empirical lifts on your own domain and corpus size before production deployment.
  • README explicitly cautions that vector-only fusion is 'roughly a wash' and 'net-negative on rich queries'; deploy hybrid variant if deploying fusion at all.

When to avoid it — and what to weigh

  • Sub-Second Latency Requirements — Multi-query generation and fusion add sequential LLM calls and multiple vector searches. Not suitable for voice interfaces, autocomplete, or sub-second p95 response targets.
  • FAQ Chatbots and Curated Knowledge Bases — Pre-curated, small, high-precision knowledge bases benefit little from fusion; baseline retrieval often suffices. The added recall can introduce off-topic results that complicate synthesis.
  • High-Margin, High-Volume Consumer Search — Increased API calls (LLM query generation, multiple searches) raise per-query cost. Not cost-effective for margin-thin, latency-sensitive consumer applications.
  • Code Search and Identifier Lookup — Precision-dominated task where exact matches matter. Multi-query fusion can dilute relevance and introduce false positives on structured identifiers.

License & commercial use

MIT License. Permissive OSI-approved license allowing commercial use, modification, and distribution with minimal restrictions (attribution and license inclusion required).

MIT license permits commercial use without royalty or proprietary restriction. However, production deployment requires OpenAI API keys (paid service) and optional cross-encoder models (open-source or commercial). License does not cover third-party service terms or data governance; review OpenAI ToS and data privacy regulations separately.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityModerate
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Requires OpenAI API key storage (use environment variables, never hardcode). ChromaDB persistence and query caching write to disk; ensure directory permissions and filesystem security. No security audit or vulnerability disclosure process mentioned. Inputs to LLM (user queries) and outputs (generated rewrites) should be validated if exposed to untrusted users. Third-party dependencies (chromadb, openai, rank_bm25) should be kept updated.

Alternatives to consider

Langchain + LangGraph multi-query retrieval

Framework-based abstraction over multi-query fusion; larger ecosystem but less empirical validation on retrieval metrics; requires additional dependency management.

LlamaIndex query transformation and re-ranking

Higher-level RAG orchestration with built-in multi-query strategies; less control over fusion algorithm; different cost/latency profile depending on model choice.

Elasticsearch + BM25 semantic-rerank hybrid

Production-scale hybrid retrieval without LLM query generation; lower latency and API costs; requires Elasticsearch infrastructure; misses multi-perspective query coverage.

Software development agency

Build on rag-fusion with DEV.co software developers

Start with the evaluation harness to validate retrieval improvements on your domain. Use the Hybrid+Diverse variant with cross-encoder reranking for production. Review cost and latency analysis in the experiments folder before scaling.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

rag-fusion FAQ

Does RAG-Fusion always improve results?
No. README explicitly states vector-only fusion is 'roughly a wash' on average and 'net-negative on rich queries.' Only the Hybrid+Diverse variant (BM25 + vector + LLM rewrites + cross-encoder) shows consistent improvement. Use adaptive routing (run fusion selectively) for mixed workloads.
What's the cost and latency impact?
Multi-query generation calls OpenAI LLM (typically 3–5 rewrites per query), then runs multiple vector searches and optional reranking. README's experiments folder includes cost/latency analysis by corpus size. Not suitable for sub-second latency; expect 2–5x query cost increase vs. single vector search.
Can I use this without OpenAI?
The core fusion and retrieval logic is model-agnostic, but the repository's implementation hardcodes OpenAI. Query generation could be replaced with open-source LLMs (Ollama, Hugging Face Inference), but no alternative integration is provided out-of-box.
How do I validate this works on my data?
Use the included evaluation harness (evaluate.py) on a sample of your domain data with graded relevance judgments. Bootstrap CIs and per-difficulty-bucket analysis are included. README cautions empirical lifts from NFCorpus may not transfer; validate before production rollout.

Software developers & web developers for hire

From first prototype to production, DEV.co delivers software development services around tools like rag-fusion. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across vector databases and beyond.

Ready to Deploy RAG-Fusion?

Start with the evaluation harness to validate retrieval improvements on your domain. Use the Hybrid+Diverse variant with cross-encoder reranking for production. Review cost and latency analysis in the experiments folder before scaling.