Reciprocal rank fusion formula
The reciprocal rank fusion formula: for each ranked list a document appears in, add 1 / (k + rank), where rank starts at 1, then sort by the total. A list that does not contain the document adds nothing. The usual k is 60, the value Cormack, Clarke and Buettcher found near-optimal in 2009, and the XERJ default.
TL;DR The reciprocal rank fusion formula adds 1 / (k + rank) for every ranked list a document appears in, then sorts by the total. Ranks start at 1, a missing list adds nothing, and k = 60 is the usual constant. It merges BM25 and vector results without a shared score scale.
Act as a coding agent. Read https://xerj.org/llms.txt, install XERJ, start a local node with --embed-mode neural, index one folder I point you to with xerj autoindex, then run one question as a BM25 match query, as a knn query, and as a hybrid query with fusion type rrf and k 60. Show me the top 5 of each side by side with file paths, and tell me which passages only the fused list found.
curl -fsSL https://xerj.org/get | sh
Install the single XERJ binary.
xerj --embed-mode neural
Start a local node with a vector arm. The all-MiniLM-L6-v2 model downloads once, about 90 MB.
xerj autoindex ./docs --url http://127.0.0.1:9200 --progress plain
Index a folder. Full-text and vector fields go into the same index.
curl -s -XPOST 'http://127.0.0.1:9200/docs/_search' -H 'content-type: application/json' -d '{"query":{"hybrid":{"queries":[{"query":{"match":{"body":"server unreachable"}},"weight":1.0},{"query":{"knn":{"field":"body_vector","k":10,"num_candidates":50,"query_vector":[]}},"weight":1.0}],"fusion":{"type":"rrf","k":60}}},"size":5}'
One hybrid request fused with RRF and k = 60. Fill query_vector with your embedding; the empty array marks where the floats go.
RRF calculator
Change a rank or the constant k and the fused order updates. Set a rank to 0 to take the document out of that list.
Type the rank of each document in two lists and pick k
| Document | BM25 rank | Vector rank | RRF score | Fused |
|---|---|---|---|---|
| Document A | 1/61 + 1/64 = 0.0320 | 2 | ||
| Document B | 1/62 + 1/61 = 0.0325 | 1 | ||
| Document C | 1/62 = 0.0161 | 3 |
Document B ranks first: it is near the top of both lists.
The formula
The score for a document is the sum, over every ranked list it appears in, of:
score(d) = 1 / (k + rank_i(d))
rank_i(d) is the 1-based rank of d in list i. If the document is missing from a list, that list adds nothing. k is a constant. A larger k flattens the gap between rank 1 and later ranks. With k = 60, a document high in both lists beats one that is first in a single list. In their 2009 pilots, Cormack, Clarke and Buettcher found k = 60 near-optimal. That value is also the XERJ default.
Here is the same formula in Python, ready to copy:
# Reciprocal rank fusion. k = 60 comes from Cormack, Clarke and Buettcher, SIGIR 2009.
def rrf(rankings, k=60):
"""rankings: a list of ranked lists of document ids, best first."""
scores = {}
for ranking in rankings:
for rank, doc_id in enumerate(ranking, start=1):
scores[doc_id] = scores.get(doc_id, 0.0) + 1.0 / (k + rank)
return sorted(scores.items(), key=lambda item: item[1], reverse=True)
bm25 = ["A", "B", "D"]
vector = ["B", "C", "E", "A"]
print(rrf([bm25, vector])) # B first: 1/62 + 1/61 = 0.0325
A worked example
Fusing two short ranked lists
Example only, not a measurement. Two lists of three documents, with k = 60, the constant Cormack, Clarke and Buettcher found near-optimal in their 2009 pilots. Score = 1 / (k + rank), then add.
| Document | Rank in list A | Rank in list B | RRF score |
|---|---|---|---|
| Document X | 1 | 2 | 1/61 + 1/62 = 0.0325 |
| Document Y | 2 | 1 | 1/62 + 1/61 = 0.0325 |
| Document Z | 3 | (missing) | 1/63 = 0.0159 |
X and Y tie at the top. Z appears in only one list, so it ranks lower. A real corpus will not look like this three-row example.
The table is a labeled teaching example with three documents and k = 60, not a measurement on a XERJ corpus. A document that ranks first in one list and second in the other ties with a document that does the reverse. A document that appears in only one list ranks lower, because only one list adds to its score.
Why RRF works well for hybrid search
A BM25 score has no fixed upper bound and changes from query to query, while a cosine similarity stays between -1 and 1. Adding those numbers directly lets one arm drown the other. RRF looks only at positions, so each arm gets a fair vote and no score normalization is needed.
RRF also helps recall. A passage that only the vector arm found still reaches the fused list, and so does a passage that only BM25 found. For a RAG pipeline or an AI agent, that means more questions where the right passage reaches the model.
Measured: hybrid RRF on BEIR
XERJ ran BM25, vectors only and hybrid RRF on two public BEIR datasets. Hybrid RRF scored the highest nDCG@10 on both.
BM25, vectors and hybrid on two public BEIR datasets
SciFact: 300 test queries over 5,183 documents
| Arm | nDCG@10 | Queries with no hits |
|---|---|---|
| BM25 | 0.6572 | 0 |
| Vectors only (MiniLM) | 0.6764 | 0 |
| BM25 top 30 reordered by MiniLM | 0.6855 | 0 |
| Hybrid RRF | 0.6993 | 0 |
NFCorpus: 323 test queries over 3,633 documents
| Arm | nDCG@10 | Queries with no hits |
|---|---|---|
| BM25 | 0.3016 | 25 |
| Vectors only (MiniLM) | 0.3291 | 0 |
| BM25 top 30 reordered by MiniLM | 0.3323 | 25 |
| Hybrid RRF | 0.3448 | 0 |
On SciFact, hybrid RRF scored 0.6993, against 0.6764 for vectors only and 0.6572 for BM25. On NFCorpus, it scored 0.3448, against 0.3291 and 0.3016. BM25 found no hits for 25 of the 323 NFCorpus queries, and the fused list still returned results for every one of them. The method is on hybrid search quality, measured with nDCG.
Run RRF in XERJ
- Install:
curl -fsSL https://xerj.org/get | sh - Start a node with a vector arm:
xerj --embed-mode neural - Index a folder:
xerj autoindex ./docs --url http://127.0.0.1:9200 --progress plain - Send one
hybridrequest with amatchquery, aknnquery and"fusion":{"type":"rrf","k":60}. The full request is in the command list on this page.
To hand it to an agent, use Copy the prompt and paste it into Claude Code, Cursor or Codex. The agent runs the same question three ways and shows what the fused list adds. When to change k, and when a weighted sum fits better, is in when to use reciprocal rank fusion.
History and research
The method was introduced by Cormack, Clarke and Buettcher, Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods, SIGIR 2009, pages 758 to 759. An ACM page also lists the paper at doi 10.1145/1571941.1572114. The k = 60 figure on this page is theirs, from those pilots. The BEIR numbers above are XERJ measurements.
Related terms
Hybrid search, hybrid vs vector vs semantic search, BM25, semantic search and how XERJ combines search.
FAQ
What is the reciprocal rank fusion formula?
score(d) = sum over every list that holds d of 1 / (k + rank), with 1-based ranks. Sort by the total. A common k is 60, from the 2009 paper.
Why use ranks instead of raw scores?
BM25 scores and vector similarities sit on different scales. Ranks do not, so you can fuse the lists without a shared unit and without normalization.
What does the constant k do?
A larger k flattens the gap between rank 1 and later ranks, so agreement between lists counts for more than one first place. In their 2009 pilots, Cormack, Clarke and Buettcher found k = 60 near-optimal. XERJ uses k = 60 by default and accepts another value.
What happens when a document is missing from one list?
That list adds nothing for it. The document keeps the score from the lists that do hold it, so a passage that only one arm finds can still reach the fused results.
Does RRF improve hybrid search results?
On the two BEIR datasets XERJ measured, hybrid RRF scored the highest nDCG@10: 0.6993 on SciFact and 0.3448 on NFCorpus, above BM25 and vectors alone. Test it on your own queries too.
When should I use a weighted sum instead of RRF?
When the raw scores carry meaning you want to keep and you can normalize them. Start with RRF, which needs no tuning beyond k. The trade-offs are in the when-to-use RRF answer.
Evidence
- Reciprocal rank fusion adds 1 / (k + rank) for each list a document appears in; the 2009 paper reports k = 60 as near-optimal in its pilots. Source: https://cormack.uwaterloo.ca/cormacksigir09-rrf.pdf
- On BEIR SciFact (300 test queries) nDCG@10 was 0.6572 for BM25, 0.6764 for MiniLM vectors only and 0.6993 for hybrid RRF. Source:
benchmarks/beir-hybrid/results/scifact.txt - On BEIR NFCorpus (323 test queries) nDCG@10 was 0.3016 for BM25, 0.3291 for MiniLM vectors only and 0.3448 for hybrid RRF. BM25 returned zero hits for 25 queries; hybrid RRF for none. Source:
benchmarks/beir-hybrid/results/nfcorpus.txt
Related
- What is hybrid search?
- Hybrid search vs vector search vs semantic search
- What is Reciprocal Rank Fusion?
- How to run hybrid search in XERJ
- How does XERJ combine BM25 and kNN?
- How much better is hybrid search than BM25? Measured nDCG numbers
- BM25 vs vector search
- Neurosymbolic AI frameworks in 2026: open source tools for LLM reasoning and agent memory · same intent: Science
- What are grounded answers? · same intent: Science
- What is semantic search? · same intent: Science