/Learn
Modules · RAG and retrieval · Coding pattern

Reciprocal Rank Fusion (RRF) Hybrid Search

PracticeCoding patternTier 1 · Whole pictureApply10 minRAG and retrieval

You will be able to: implement weighted RRF, and explain when to prefer it over score-based fusion.

Source: Cormack, Clarke & Büttcher, 2009 (SIGIR)

AI engineeringModules

Study with AI

Part 1 of 5

Basics

The whole idea first, then the terms the rest of this page uses.

1.1Whole idea

Keyword and vector search each produce a ranking, on incompatible scales. RRF ignores scores and uses ranks: each list adds 1 / (k + rank) to a document. Documents high on several lists rise to the top.

Why it matters

Merges BM25 and vector rankings without normalising scores that live on different scales.

1.2Key concepts

One idea per card, in plain words.

01Hybrid search

Runs keyword and vector retrieval together: exact terms from one, paraphrases from the other.

02Rank, not score

A BM25 score of 12.4 and a cosine of 0.83 cannot be compared. Positions can.

03k

Dampens the gap between top ranks. The paper's value of 60 works widely.

Part 2 of 5

Question

What exactly you must answer, and what to settle before you start.

2.1Question

Interviewer

Keyword search finds exact product codes; vector search finds paraphrases. Merge both into one list, given that BM25 scores 12.4 where cosine scores 0.83.

Part 3 of 5

Detailed answer

How it works, and how to build or explain it.

3.1Step by step

The mechanism, in the order you would explain it.

  1. Fetch both lists

    Take 50–100 from each retriever. Shallow lists leave RRF nothing to fuse.

  2. Add reciprocal ranks

    For each list and document, add weight / (k + rank).

  3. Sort and cut

    Sort by the sum and send the top results on to the reranker.

  4. Tune weights last

    Keep weights at 1 until an eval set shows a reason to change them.

3.2Code

Working code for the core of it.

Merging rankings with RRF

Keyword and vector scores aren't comparable. Ranks are.

rrf.tsTypeScript
1export interface RrfOptions {2  k?: number;3  weights?: number[];4  top?: number;5}6 7/** Reciprocal rank fusion: each list adds weight / (k + rank). Raw scores never enter the sum. */8export function rrf(lists: string[][], { k = 60, weights, top }: RrfOptions = {}): { id: string; score: number }[] {9  const scores = new Map<string, number>();10  lists.forEach((list, l) =>11    list.forEach((id, i) => scores.set(id, (scores.get(id) ?? 0) + (weights?.[l] ?? 1) / (k + i + 1)))12  );13  const ranked = [...scores].map(([id, score]) => ({ id, score })).sort((a, b) => b.score - a.score);14  return top === undefined ? ranked : ranked.slice(0, top);15}
15 linesUTF-8TypeScript
/ (k + i + 1)
Only position counts. An item near the top of both lists beats one at the top of just one.
k = 60
Softens the gap between top ranks. 60 is the value from the original paper.

Tested by npm run test:modules.

Part 4 of 5

Q&A

What interviewers ask next. Answer out loud, then open.

4.1Interview questions

Why k = 60?
The original paper found it robust. Results barely change across a wide range, so most teams never tune it.
Why not normalise and add scores?
Score distributions shift per query, so min-max scaling turns unstable. A tuned weighted sum can still beat RRF if you have labelled data.
What about a document in one list only?
It still scores from that list. A very strong single-list hit can beat weak hits on both.
Part 5 of 5

Extra depth

Edge cases, counterpoints and what to read next.

5.1Edge cases and counterpoints

Includes the strongest argument against this approach.

Show detailsHide details
Queries and fusion
Some queries suit one retriever. Query classification can adjust weights per query.
Counterpoint
With labelled data, learned fusion often beats RRF. RRF wins as the zero-configuration default.
AI Engineer · Reciprocal Rank Fusion (RRF) Hybrid Search