Different retrievers are good at different things. Keyword search (BM25) finds exact terms and rare identifiers, vector search finds paraphrases. Hybrid search runs both and merges the lists, but their scores live on incompatible scales (BM25 scores are unbounded, cosine similarities are in [-1, 1]), so adding raw scores is meaningless. Reciprocal rank fusion (RRF) ignores scores and uses only ranks: a document earns 1 / (k + rank) from each list it appears in, and documents are sorted by their total. A document ranked well by several retrievers rises to the top, and the constant k (typically 60) softens the advantage of rank 1.
Implement reciprocal_rank_fusion.
rankings is a list of ranked lists of document ids, best first. Ranks start at 1.1 / (k + rank). Documents missing from a list get nothing from it.Accumulate scores in a dictionary while enumerating each list with start=1.
Documents appearing in several lists naturally accumulate more.
No results yet
Run your code to check it against the examples, or submit to run every test.