Module 6: Designing Search Systems
5. Advanced Ranking Strategies
Overview
This capsule covers advanced ranking techniques: score fusion (keyword + semantic), RRF (Reciprocal Rank Fusion), MMR (Maximal Marginal Relevance), and personalization with metadata.
Strategy 1: Score fusion (keyword + semantic)
The problem:
You want to combine keyword search (BM25) with semantic search (cosine).
The solution: A weighted sum
final_score = α × semantic_score + (1-α) × bm25_score
Where:
- α = 0.7 (70% semantic, 30% keyword)
- semantic_score ∈ [0, 1] (normalized)
- bm25_score ∈ [0, 1] (normalized)
Example:
Doc A:
semantic_score = 0.85
bm25_score = 0.60
final_score = 0.7 × 0.85 + 0.3 × 0.60 = 0.595 + 0.18 = 0.775
Doc B:
semantic_score = 0.70
bm25_score = 0.90
final_score = 0.7 × 0.70 + 0.3 × 0.90 = 0.49 + 0.27 = 0.76
Ranking: Doc A > Doc B (0.775 > 0.76)
Tuning α:
- α = 0.5 → An even balance
- α = 0.7 → Favoring semantic (conceptual queries)
- α = 0.3 → Favoring keyword (exact queries)
Strategy 2: RRF (Reciprocal Rank Fusion)
What is RRF?
Fusing rankings without depending on absolute scores (which may not be comparable).
Formula:
RRF(doc) = Σ 1 / (k + rank_i)
Where:
- rank_i: The document's position in ranking i
- k: A constant (typically k=60)
Example:
Keyword ranking:
1. Doc A
2. Doc B
3. Doc C
Semantic ranking:
1. Doc C
2. Doc A
3. Doc D
RRF scores:
Doc A: 1/(60+1) + 1/(60+2) ≈ 0.0164 + 0.0161 = 0.0325
Doc B: 1/(60+2) + 0 ≈ 0.0161
Doc C: 1/(60+3) + 1/(60+1) ≈ 0.0159 + 0.0164 = 0.0323
Doc D: 0 + 1/(60+3) ≈ 0.0159
Final ranking:
1. Doc A (0.0325) ✅
2. Doc C (0.0323)
3. Doc B (0.0161)
4. Doc D (0.0159)
The advantage: It requires no score normalization (it works with rankings).
Strategy 3: MMR (Maximal Marginal Relevance)
The problem:
The top-10 results are very similar to each other (redundancy).
The goal:
Diversify the results (relevance + diversity).
The algorithm:
1. Initialize: Selected = []
2. For each iteration (up to K results):
a. For each doc in Candidates:
mmr_score = λ × relevance(doc, query)
- (1-λ) × max_similarity(doc, Selected)
b. Add the doc with the highest mmr_score to Selected
3. Return Selected
Parameters:
- λ = 1.0 → Relevance only (no diversity)
- λ = 0.5 → Balanced (50% relevance, 50% diversity)
- λ = 0.0 → Diversity only (not recommended)
Example:
Query: "Python"
kNN top-5:
1. Doc A: "Python tutorial" (cosine: 0.95)
2. Doc B: "Python guide" (cosine: 0.94) [very similar to A]
3. Doc C: "Python vs JavaScript" (cosine: 0.88)
4. Doc D: "Data types in Python" (cosine: 0.85)
5. Doc E: "Python libraries" (cosine: 0.83)
Without MMR (relevance only):
1. Doc A
2. Doc B [redundant with A]
3. Doc C
With MMR (λ=0.7):
1. Doc A (the most relevant)
2. Doc C (diverse: a comparison)
3. Doc D (diverse: data types)
Use: E-commerce (diversifying products), academic search (multiple perspectives).
Strategy 4: Personalization with metadata
The scenario:
Weighting the results based on metadata (e.g. recent documents > old ones).
Example: A boost by date
final_score = semantic_score × time_boost
time_boost:
- Documents < 1 month old: 1.5x
- Documents 1-6 months old: 1.2x
- Documents 6-12 months old: 1.0x
- Documents > 1 year old: 0.8x
A numerical example:
Doc A:
semantic_score = 0.80
timestamp = 2024-11-01 (1 month)
boost = 1.5
final_score = 0.80 × 1.5 = 1.20
Doc B:
semantic_score = 0.85
timestamp = 2022-06-01 (2 years)
boost = 0.8
final_score = 0.85 × 0.8 = 0.68
Ranking: Doc A > Doc B (even though B had the higher semantic score)
Strategy 5: Ensemble (multiple embeddings)
The scenario:
Using multiple embedding models and fusing them.
Example:
Query: "machine learning"
Embedding 1 (OpenAI ada-002): top-100
Embedding 2 (Cohere embed-v3): top-100
Fuse with RRF → the final top-10
The advantage: More robust (multiple perspectives).
The disadvantage: Higher cost (2x the embeddings).
When to use each strategy
| Strategy | Use case |
|---|---|
| Score fusion | Combining keyword + semantic |
| RRF | Fusing multiple rankings (without scores) |
| MMR | Diversifying results (avoiding redundancy) |
| Metadata boost | Prioritizing recent/popular docs |
| Ensemble | Combining multiple embedding models |
Summary
Key points:
- Score fusion: A weighted sum (α)
- RRF: Fusion by rankings (without scores)
- MMR: Relevance + diversity
- Metadata boost: Weighting by date/popularity
- Ensemble: Multiple embeddings
Next capsule: 06-quality-evaluation.md — Precision, recall, MRR, NDCG.