Overview
Hybrid RAG with Reciprocal Rank Fusion (RRF) is an advanced retrieval architecture that:- Retrieves candidates from both BM25 (lexical) and semantic retrievers
- Fuses the ranked lists using the RRF algorithm for optimal combination
- Applies Maximal Marginal Relevance (MMR) for result diversification
How It Works
Pipeline Steps
- Parallel Retrieval: Query both BM25 and semantic retrievers for candidates (15 each by default)
- Reciprocal Rank Fusion: Combine ranked lists using RRF formula:
where
k=60is a constant andrank_i(d)is the rank of documentdin listi - Initial Pool Selection: Select top 10 documents from RRF-fused results
- MMR Diversification: Apply MMR to select final 5 diverse, relevant documents
- Answer Generation: Generate answer from the diversified context
RRF is more principled than weighted averaging because it’s based on rank positions rather than raw scores, making it more robust to score scale differences between retrievers.
Key Features
- Reciprocal Rank Fusion: Theoretically-grounded method for combining ranked lists
- Scale-invariant: RRF works regardless of score ranges from different retrievers
- Result diversification: MMR reduces redundancy in retrieved documents
- Tunable parameters: Control candidate pool size, RRF constant, and diversity factor
- Higher candidate retrieval: Retrieves more candidates (15 vs 5) to improve fusion quality
Implementation Details
Configuration Parameters
Reciprocal Rank Fusion Algorithm
MMR Diversification
Complete Retrieval Pipeline
Usage with query_for_evaluation()
Return Structure
When to Use This Approach
Best For
- Complex queries: Questions that need diverse perspectives from the corpus
- Maximum recall: When you want the best possible candidate pool before selection
- Reducing redundancy: MMR ensures context provides complementary information
- Production systems: When retrieval quality is critical and worth extra computation
- Benchmark optimization: When competing for the highest possible RAG scores
Advantages Over Simple Hybrid
- Better fusion quality: RRF is more principled than weighted averaging
- Larger candidate pool: 15+15=30 candidates vs 5+5=10 in simple hybrid
- Diversified results: MMR prevents redundant, similar documents
- Rank-based combination: Not affected by score scale differences
- Configurable trade-offs: Tune diversity vs relevance with MMR lambda
Trade-offs
- Higher latency: ~3-5 seconds due to larger retrieval + MMR computation
- More embedding calls: MMR requires re-embedding documents for diversity calculation
- Increased complexity: More parameters to tune and more moving parts
- Higher memory: Maintains larger candidate sets during processing
Performance Characteristics
Speed
- Retrieval: ~1-2 seconds (parallel BM25 + semantic for 15 docs each)
- RRF fusion: ~0.01 seconds (very fast)
- MMR diversification: ~0.5-1 second (embedding + similarity computation)
- Total: ~3-5 seconds end-to-end
Cost
- Retrieval embeddings: ~$0.00001 (query embedding only)
- MMR embeddings: ~$0.00002 (re-embedding 10 candidates for diversity)
- LLM cost: ~$0.002-0.005 (same as other methods)
- Total: ~$0.003-0.006 per query (slightly higher than simple approaches)
Quality
- Highest recall: Large candidate pool captures more relevant documents
- Best precision: RRF + MMR select the most relevant, diverse subset
- Optimal diversity: MMR ensures complementary information in context
- Robust ranking: RRF handles score scale differences gracefully
Parameter Tuning Guide
RRF Constant (k)
- Lower values (30-50): More aggressive fusion, top-ranked items dominate
- Default (60): Balanced, standard choice in literature
- Higher values (70-90): Gentler fusion, considers more items equally
MMR Lambda (λ)
- High lambda (0.8-0.9): Prioritize relevance over diversity
- Balanced (0.7): Good trade-off (default)
- Low lambda (0.5-0.6): Prioritize diversity, more varied results
Candidate Pool Sizes
Comparison with Other Architectures
Source Files
- Implementation:
~/workspace/source/src/rag/hybrid_rrf.py:186-195 - RRF algorithm:
~/workspace/source/src/rag/hybrid_rrf.py:114-127 - MMR selection:
~/workspace/source/src/rag/hybrid_rrf.py:140-183 - Evaluation interface:
~/workspace/source/src/rag/hybrid_rrf.py:242-299
