rachid chabane.
Search
← All articles
Explainers · RAG · agent-maintained

Hybrid RAG: reciprocal rank fusion in practice

Combine BM25 and vectors without tuning ten weights: rank is enough.

27-05-2026 1 min ███░░ FR / EN
RAGretrieval

Combine BM25 and vectors without tuning ten weights: rank is enough.

Reciprocal rank fusion merges two ranked lists by summing the reciprocals of each document’s rank, so a result that scores well in either retriever rises without any score normalization. The single k constant is far easier to reason about than a weighted blend of incomparable lexical and cosine scores.

Fusing two imperfect rankings beats over-optimizing a single one.

# reciprocal rank fusion: fuse N rankings by rank, not score
from collections import defaultdict

def rrf(rankings, k=60):
    scores = defaultdict(float)
    for ranking in rankings:
        for rank, doc_id in enumerate(ranking):
            scores[doc_id] += 1 / (k + rank + 1)
    return sorted(scores, key=scores.get, reverse=True)

In practice the lexical arm catches exact identifiers and rare terms the embedding glosses over, while the vector arm recovers paraphrase. Fused, they cover each other’s blind spots, a robust default before reaching for a trained reranker.

RetrieverCatchesMisses
Lexical (BM25)Exact identifiers and rare termsParaphrase
VectorParaphraseExact identifiers and rare terms the embedding glosses over

Glossary

BM25
A classic lexical ranking function that scores documents by term frequency and rarity. Strong on exact identifiers and jargon, blind to synonyms and paraphrase.
Embeddings
Learned vector representations of text (or code) in which geometric distance approximates semantic similarity. The substrate of vector search, deduplication and clustering.
Hybrid retrieval
Combining lexical search (such as BM25) and vector search in one retrieval pipeline, so exact-term matches and semantic matches compensate for each other's blind spots.
RAG
Retrieval-augmented generation: the system grounds a language model's answer by retrieving relevant documents at query time and injecting them into the prompt, instead of relying on the model's parametric memory alone.
Reciprocal rank fusion
A rank-only method for merging several ranked lists: each document scores the sum of 1/(k + rank) across lists. No score normalization or weight tuning, which is what makes it robust.
Vector search
Retrieval over embedding vectors: documents and queries are mapped to a shared vector space and matched by similarity (typically cosine), capturing meaning beyond exact words.

Sources

01
01-03-2024 pinecone.io

Want to go deeper?