Reciprocal rank fusion (RRF) combines ranked results from multiple retrieval systems by summing each document’s reciprocal-rank contributions, then sorting by the total. It is useful when lexical and vector search provide complementary results. section 15.5.1
The calculation proceeds as follows:
- For every ranked result list, add 1 / (k + rank) to the document’s score. section 15.5.1
- Aggregate contributions for documents appearing in multiple lists, then sort scores in descending order. section 15.5.1
- Increase k to reduce the influence of an isolated high rank; k=60 is a commonly used default in the implementation. section 15.5.1
Lexical and vector retrieval
For the query "singin' in the rain", run lexical and vector searches independently, then pass both ranked document lists to a hybrid search configured with RRF and k=60. section 15.5.1
Listing 15.17 RRF for combining multiple sets of search results
def reciprocal_rank_fusion(search_results, k=None):
if k is None: k = 60
scores = {}
for ranked_docs in search_results: #1
for rank, doc in enumerate(ranked_docs, 1): #2
scores[doc["id"]] = (scores.get(doc["id"], 0) + #3
(1.0 / (k + rank))) #3
sorted_scores = dict(sorted(scores.items(), #4
key=lambda item: item[1], reverse=True)) #4
return sorted_scores #4
Inspect the Python implementation that iterates through ranked lists, accumulates reciprocal-rank scores, and returns sorted results. section 15.5.1


