Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 6.3 — Reciprocal Rank Fusion by Hand
RAG and Vector Search · Example 1 of 2

Recompute the lab's Fused column

The ranks are copied from the real embedding model in the search lab below, so this table is what the lab shows (the lab rounds the Fused column to 4 decimals).

Reciprocal rank fusion merges ranked lists using only each passage's place in each list: it adds 1 / (60 + rank) per list. No scales to align, one constant, and you can recompute the search lab's Fused column by hand.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write rrf_score(ranks, k=60) that takes a passage's list of ranks (one per list that contains it) and returns its fused score. Print it for [1, 3] and [10, 10] with 6 decimals.

02

Using rrf_score, print the fused score of a passage first in one list only, then of a passage tenth in both lists. Which is higher?

Explain it without notes

01

State the RRF formula and compute the fused score of a passage ranked 2nd in one list and 7th in another, with k = 60.

02

Why does RRF not need normalised scores?

03

Explain what the constant k does, using two values.

04

What can you not do with a fused score?

Recompute the lab's Fused column
Sign in to run this example in your browser.

Expected output

passage  vector  keyword  fused
D3            1        3  0.032266
D10           2        2  0.032258
D1            5        1  0.031778
D12           3        5  0.031258
D5            6        4  0.030777
D6            4        -  0.015625
D8            7        -  0.014925
D9            8        -  0.014706
D4            9        -  0.014493
D7           10        -  0.014286
D11          11        -  0.014085
D2           12        -  0.013889
D3 beats D10 by 0.000008