Command Palette

Search for a command to run...

Hectal
Phase 6: Hybrid Search and Re-ranking
RAG and Vector Search · Exercise 1 of 5Next
Intermediate

Fuse ranked lists with reciprocal rank fusion

Write rrf(rankings, k=60). rankings is a list of ranked lists of ids (best first). Every list adds 1 / (k + rank) to each id it contains, where the best id has rank 1.

Return a list of (id, score) pairs, best score first. Ids with exactly equal scores are ordered by id (alphabetical). An id missing from a list gets nothing from that list.

What Check tests

  1. One list keeps its order and scores 1 / (60 + rank)
  2. Two lists add their points
  3. An id missing from a list still counts
  4. Equal scores are ordered by id
  5. The constant k can change

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.