Day 3:Week 11, Day 3: Hybrid Search Fusion — Convex Score Combination vs Reciprocal Rank Fusion
Battle-tested daily lesson note • 100% runnable code, interview Q&A, test suite & interactive quiz
Week 11, Day 3: Hybrid Search Fusion — Convex Score Combination vs Reciprocal Rank Fusion (RRF)
1. Why Combining BM25 and Cosine Similarity Scores Directly is Tricky
In Hybrid Search, we run two retrievers in parallel:
- Lexical Retriever (
Okapi BM25): Scores live in (e.g.,18.4,7.2,1.1) and vary wildly depending on how many words the user typed! - Dense Vector Retriever (
Cosine Similarity): Scores live in (typically clustered tightly in[0.65, 0.88]).
If you naively compute 0.5 * bm25_score + 0.5 * cosine_score, a BM25 score of 18.4 completely swamps a Cosine score of 0.85! And if you use Min-Max normalization per query, a single outlier BM25 score distorts the entire scale.
2. The Production Standard: Reciprocal Rank Fusion (RRF — Cormack et al., 2009)
Instead of relying on uncalibrated raw scores, Reciprocal Rank Fusion (RRF) fuses multiple ranked lists based purely on each document's 1-based rank position in each retriever :
where is the universal smoothing constant (and is an optional retriever weight, default 1.0).
Why Works So Well:
- It requires zero score calibration across heterogeneous retrievers (
BM25,Dense,SPLADE). - A document ranked #2 in BM25 AND #3 in Dense Search gets:
- Whereas a document ranked #1 in BM25 only (and missing from Dense) gets: Consensus winners that appear near the top of BOTH lexical and semantic search automatically float to #1!
In Simple English: Why RRF Beats Naive Score Averaging
Suppose BM25 returns scores like 18.4, 12.1, 4.0 while Cosine Vector Search returns 0.88, 0.85, 0.79. If you simply add 18.4 + 0.88, BM25 always bullies Cosine into irrelevance!
Reciprocal Rank Fusion (RRF) ignores raw scores and looks ONLY at position (1st, 2nd, 3rd...) using $1 / (60 + \text{rank})$:
- Document ranking #2 in BM25 ($1/62 = 0.01613) AND **#3 in Vector** (\1/63 = 0.01587) earns **\0.03200$** total!
- It easily beats a fluke document that ranked #1 in BM25 ($1/61 = 0.01639$) while missing completely from semantic search (
0.01639)!