SCIENCE · RETRIEVAL

Reciprocal rank fusion formula

AUTHOR · XERJ documentation team · REVIEWED BY · XERJ engineering team · PUBLISHED · 2026-11-13 · UPDATED · 2026-11-19
SHORT ANSWER · UPDATED 2026-11-19

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.

PASTE THIS TO YOUR AI AGENT. IT DOES THE REST 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.
RUN THIS XERJ COMMAND curl -fsSL https://xerj.org/get | sh Install the single XERJ binary.
RUN THIS XERJ COMMAND xerj --embed-mode neural Start a local node with a vector arm. The all-MiniLM-L6-v2 model downloads once, about 90 MB.
RUN THIS XERJ COMMAND 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.
RUN THIS XERJ COMMAND 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.

Try it: RRF calculator

Type the rank of each document in two lists and pick k

DocumentBM25 rankVector rankRRF scoreFused
Document A1/61 + 1/64 = 0.03202
Document B1/62 + 1/61 = 0.03251
Document C1/62 = 0.01613

Document B ranks first: it is near the top of both lists.

Runs in your browser and sends nothing. A rank of 0 means the document is missing from that list, so that list adds nothing. Score = sum of 1 / (k + rank). The starting values are a teaching example, not a XERJ run; k = 60 is the value Cormack, Clarke and Buettcher found near-optimal in 2009.

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

Try it: a labeled 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.

DocumentRank in list ARank in list BRRF score
Document X121/61 + 1/62 = 0.0325
Document Y211/62 + 1/61 = 0.0325
Document Z3(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 formula and the choice k = 60 come from Cormack, Clarke and Buettcher, Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods, SIGIR 2009. The three documents are a teaching example, not a XERJ run.

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.

Try it: switch datasets

BM25, vectors and hybrid on two public BEIR datasets

SciFact: 300 test queries over 5,183 documents

ArmnDCG@10Queries with no hits
BM250.65720
Vectors only (MiniLM)0.67640
BM25 top 30 reordered by MiniLM0.68550
Hybrid RRF0.69930
Runs in your browser and sends nothing. Measured by XERJ with --embed-mode neural and the built-in all-MiniLM-L6-v2 model; the default lexical embedder is not covered. Raw output is in benchmarks/beir-hybrid/results in the XERJ repository.

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

  1. Install: curl -fsSL https://xerj.org/get | sh
  2. Start a node with a vector arm: xerj --embed-mode neural
  3. Index a folder: xerj autoindex ./docs --url http://127.0.0.1:9200 --progress plain
  4. Send one hybrid request with a match query, a knn query 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

Related