Practice in Lab: Fuse retriever rankings without comparing incompatible scores →
Fuse retriever rankings without comparing incompatible scores
Lexical and vector retrievers often produce scores on unrelated scales. Reciprocal rank fusion combines their ranked lists using position rather than assuming their raw scores are comparable. Each retriever should contribute at most once to a document's score.
The smoothing constant controls how sharply top positions dominate. Deterministic identifier ordering resolves tied fused scores. This is a local ranking algorithm with transparent arithmetic; a production system still needs relevance evaluation, permission filtering and a policy for stale or duplicate document versions. Fusion cannot repair an unauthorized candidate set.
rankings=[["a","b"],["b","c"]]
scores={}
for ranking in rankings:
for rank,key in enumerate(ranking,1):
scores[key]=scores.get(key,0)+1/(60+rank)
print(sorted(scores,key=lambda k:(-scores[k],k)))Review the design
RRF uses ranking evidence instead of uncalibrated score scales. Tune and evaluate it on representative relevance judgments, keeping final evaluation queries separate from parameter selection.
Your task
Implement rrf(rankings,k=60) returning all ids sorted by descending sum 1/(k+rank), then id. Rank unique ids within each list starting at 1, ignoring repeated appearances without consuming another rank. Require k>0.
The explanation opens here once every check passes.