# What Is Reciprocal Rank Fusion?

> How reciprocal rank fusion merges keyword and vector search results into one ranking, with a worked example and its limits, for your AI interview.

**In short:** Reciprocal rank fusion (RRF) merges several ranked result lists into one. It gives each item 1 divided by (its rank plus a constant, often 60), and adds those amounts across the lists. Because it works from ranks, the lists' raw scores never need to match.

AI and LLM interview question Q125, Retrieval-augmented generation (RAG). Advanced, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-reciprocal-rank-fusion

## Say it in 30 seconds

Reciprocal rank fusion, or RRF, combines two or more ranked lists into one. Say a keyword search and a vector search each return their own top results. RRF scores each item by one divided by (its position plus a constant, often 60), then adds the scores. An item near the top of both lists rises to the top. Because it works from places alone, I never have to scale the two engines' scores to match.

## Say it in 2 minutes

Many RAG systems search in more than one way. A keyword search finds exact words, such as a clause number. A vector search finds meaning, so it catches the same idea written differently. Each returns a ranked list, and the two lists can disagree. Reciprocal rank fusion, or RRF, is the simple step that turns two lists into one.

The method is short. For each item, add 1 divided by (its rank plus a constant, often 60), once for every list it appears in. First place in one list scores about 0.016. An item near the top of both lists scores more, because two shares add up. Then sort by the total. The constant flattens the gap between the top places.

Two things make it useful. It works from places, so I never have to scale a keyword score against a similarity score. And items that several searches agree on rise. It is not the last word, though. A 2022 paper found RRF sensitive to its parameters. In its tests, a weighted mix of the two scores beat RRF, and it needed only a few labelled examples to tune.

In an interview, I would say what it is, show the formula, and name the trade-off. It rewards agreement, so a clause that only one search finds can be buried. Then I would test it on real questions from our own documents before trusting it.

## What is reciprocal rank fusion, in plain words?

A search usually returns a ranked list: the best match first, then the next, and so on. Reciprocal rank fusion, or RRF, merges two or more of these lists into one. It is used in retrieval-augmented generation (RAG), where an app first fetches passages from your documents and the model then answers from them.

Picture a hiring panel of three interviewers. Each ranks the same candidates from first to last, but their marks come from different scales, so adding up the marks would be unfair. Adding up the places each person gave is fairer. A candidate that most of the panel ranked near the top rises to the top.

Azure's search documentation describes the same idea. Items that appear near the top of several lists are likely to be more relevant, so they should rank higher in the combined result. In a RAG app, the two lists usually come from a keyword search and a vector search.

- **Keyword search:** Finds passages that contain the words you typed, such as a clause number.
- **Vector search:** Finds passages whose meaning is close to your question, even when the words differ.
- **Rank:** A place in a list. 1 is first, 2 is second, and so on.
- **Fusion constant (k):** A fixed number added to each rank, so the gap between the top places is smaller. Often 60.

## How does the formula work?

For each item, RRF looks at every list it appears in. It takes the item's rank in that list, adds the constant k, and takes 1 divided by the total. It then adds those amounts across the lists. An item missing from a list adds nothing from that list.

$$
\operatorname{RRF}(d)=\sum_{r}\frac{1}{k+\operatorname{rank}_r(d)}
$$

In words: an item's RRF score is the sum, over each list it appears in, of 1 divided by (k plus its rank in that list). Microsoft's documentation says the score is calculated this way, and that experiments point to a small k, such as 60.

1. **Collect the lists:** Run the keyword search and the vector search. Each returns its own ranked list.
2. **Score by place:** For each item, add 1 divided by (k plus its rank) from every list it appears in.
3. **Sort the totals:** Sort all items by their total. The highest total goes first.

*Diagram, How two ranked lists become one: Two ranked lists go in. Each item's place in each list becomes a share, and the shares are added. One merged ranking comes out. Only the places count, so the two engines' raw scores never need to match.*
1. The keyword list goes in, first place to last.
2. The vector list goes in too, in its own order.
3. The summed totals are sorted, highest first, into one list.

## What does a real search look like with RRF?

Imagine a legal team with 40,000 supplier contracts. They want every clause that sets a liability cap, which is the most a party pays if things go wrong. The keyword search returns clauses that use the exact words. The vector search returns clauses that say the same thing differently, such as the maximum either side pays.

The demo uses five results per list to keep it short. A real system fetches many more, then fuses them.

```python
# Fuse two ranked lists with reciprocal rank fusion. K = 60 is a common starting value.
K = 60
keyword = ["MSA-2041 cl. 9.2", "MSA-1187 cl. 4.1", "NDA-0330 cl. 2", "SOW-77 cl. 3", "MSA-2041 cl. 11"]
meaning = ["MSA-1187 cl. 4.1", "MSA-2041 cl. 11", "SOW-77 cl. 3", "MSA-0912 cl. 7", "NDA-0330 cl. 2"]

def fuse(*ranked_lists):
    scores = {}
    for ranked in ranked_lists:
        for rank, clause in enumerate(ranked, start=1):
            scores[clause] = scores.get(clause, 0) + 1 / (K + rank)
    return sorted(scores.items(), key=lambda item: item[1], reverse=True)

for clause, score in fuse(keyword, meaning):
    print(f"{score:.5f}  {clause}")
```

Output:

```text
0.03252  MSA-1187 cl. 4.1
0.03151  MSA-2041 cl. 11
0.03150  SOW-77 cl. 3
0.03126  NDA-0330 cl. 2
0.01639  MSA-2041 cl. 9.2
0.01562  MSA-0912 cl. 7
```

Read the output. Clause 4.1 comes first because both searches ranked it near the top: 1 divided by 62, plus 1 divided by 61, gives 0.03252. Clause 9.2 is the best keyword match, but only the keyword search found it. One share of 1 divided by 61 gives 0.01639, which puts it fifth of six.

That is the trade-off in one line. RRF rewards agreement, so a clause that only one search finds can sink, however good its match. One fix is to fetch deeper lists from each search, so the other engine can place the clause in its own list. With k = 60, though, a rank near 50 adds only about 0.009, so the clause needs roughly a seventh-place or better finish there to reach the top four.

## Why use ranks instead of scores, and why k = 60?

Keyword and vector engines score items in their own ways, so their numbers can't be compared directly. Microsoft's documentation says each algorithm has its own range and magnitude. A keyword score of 14 and a similarity of 0.83 (made-up numbers) can't be added without normalising. Their places can.

> "Each algorithm has its own range and magnitude." (Microsoft, Foundry IQ (Azure AI Search) documentation)
>
> "Experiments show the algorithm performs best when you set k to a small value, such as 60." (Microsoft, Foundry IQ (Azure AI Search) documentation)

The 60 is a starting point, not a law. The fusion constant is a different number from the k that vector search uses to decide how many of the closest matches (its nearest neighbours) to fetch. Keep the two apart in your answer.

> **Tip:** Asked why 60? Say it is a common starting value that worked well in experiments, and that you would check it on your own data.

## What are the limits of RRF?

RRF is simple, which is its strength, but it only uses places. A result that leads its list by a wide margin gets the same share as one that leads by a whisker.

- **Blind to the gaps:** Score differences inside a list are ignored. Only the order counts.
- **Sensitive to its settings:** A 2022 study found RRF sensitive to its parameters, so results can move when the constant changes.
- **Favours agreement:** An item found by only one search gets one share of credit, so it can drop out of the top results.

A 2022 paper on arXiv, An Analysis of Fusion Functions for Hybrid Retrieval, compared RRF with a convex combination (CC) of the two scores, which is a weighted mix of them. Its authors found RRF sensitive to its parameters. CC beat RRF both on the same kind of data and on different data, and it needed only a small set of training examples to tune.

Microsoft's documentation adds a practical point: you can weight a vector query so it counts for more or less in the fused result. That lets you tune the balance instead of giving both lists an equal say.

### How would you decide if RRF is good enough?

1. **Build a test set:** Take a sample of real questions from your users, and mark which passages answer each one.
2. **Run each option:** Score keyword only, vector only, RRF and a weighted mix on the same questions.
3. **Look at the misses:** Check which answers were missed, not just the average. A missed clause costs more than a slow reply.
4. **Keep the simplest winner:** Pick the simplest option that meets your bar, and test again when the documents change.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: merge ranked lists by adding 1 divided by (k plus rank).
- [ ] Why ranks: each engine's scores sit on their own scale.
- [ ] The formula, with k as a fusion constant and 60 as a start.
- [ ] The trade-off: it rewards items several searches agree on.
- [ ] Honest limits: sensitive to settings, and a weighted mix can win.
- [ ] How you would check it on your own questions.

**Common traps**

- Trap: "Just add the two scores together." Better: The scores sit on different scales, so RRF adds a share for each place instead.
- Trap: "Take the best score from either list." Better: That keeps one search's view only. RRF gives credit to items both searches agree on.
- Trap: "RRF is always the best fusion method." Better: It is a strong, simple default. A 2022 study found a tuned weighted mix could beat it.

## Can you spot the fix in this fusion code?

**Spot the fix:** A team's fusion code adds the raw keyword score to the raw vector similarity. Which line is the RRF fix?

A. score = bm25 * 1000 + cosine
B. score = 1 / (60 + bm25_rank) + 1 / (60 + vector_rank)
C. score = bm25 + cosine, then cut at 0.5
D. score = len(text) / bm25

**Answer:** B. RRF works from places, so the two engines' scores never meet. Scaling one score to match the other needs careful normalising first, and RRF skips that step.

**Quick check:** A clause is first in the keyword list only. A clause that is fourth in both lists is in the fused results too, with k = 60. Which one ranks higher?

A. The first-place clause, because rank 1 always wins
B. The fourth-in-both clause, which lands higher
C. The first-place clause, because its raw keyword score is high
D. Neither, because one list alone drops the clause

**Answer:** B. One list gives the first-place clause 1 divided by 61, about 0.0164. Fourth place in both lists adds up to about 0.0313, so agreement beats one search's top pick.

## Can you answer these from memory?

**Flash cards**

- **What is reciprocal rank fusion?** A way to merge ranked lists into one, scoring each item by its place in each list.
- **What is the formula?** Sum of 1 divided by (k plus rank), over each list the item appears in. k is often 60.
- **Why not add raw scores?** Each engine has its own score range, so the raw numbers can't be added without normalising.
- **What does k do?** Flattens the gap between the top places. Vector search uses a different k.
- **What is the main trade-off?** It rewards items several searches agree on, and can bury one-search finds.
- **Is RRF always the best?** No. A 2022 study found a tuned weighted mix could beat it.

## Likely follow-up questions

- Q123 What is hybrid search (BM25 + vectors)? https://designervenkat.online/interview/ai/what-is-hybrid-search
- Q124 What is BM25? https://designervenkat.online/interview/ai/what-is-bm25
- Q126 Rerankers: cross-encoder vs bi-encoder? https://designervenkat.online/interview/ai/cross-encoder-vs-bi-encoder-rerankers
- Q131 Retrieval metrics: recall@k, MRR, nDCG? https://designervenkat.online/interview/ai/retrieval-metrics-recall-at-k-mrr-ndcg
- Q133 What are common RAG failure modes? https://designervenkat.online/interview/ai/common-rag-failure-modes
