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
- One list keeps its order and scores 1 / (60 + rank)
- Two lists add their points
- An id missing from a list still counts
- Equal scores are ordered by id
- 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.