How to beginner · 3 min read

Reciprocal Rank Fusion explained

Quick answer
Reciprocal Rank Fusion (RRF) is a simple yet effective method to combine multiple ranked lists by summing the reciprocal ranks of items, improving search result quality. It assigns higher scores to items ranked near the top across different lists, making it robust for AI search aggregation.

PREREQUISITES

  • Python 3.8+
  • Basic understanding of ranking algorithms
  • pip install numpy

Setup

Install numpy for efficient numerical operations. No API keys or external services are required for basic RRF implementation.

bash
pip install numpy
output
Requirement already satisfied: numpy in /usr/local/lib/python3.10/site-packages (1.25.0)

Step by step

This example shows how to implement Reciprocal Rank Fusion in Python to combine multiple ranked lists of search results. The function reciprocal_rank_fusion takes a list of ranked lists and returns a fused ranking based on the RRF formula.

python
import numpy as np

def reciprocal_rank_fusion(rank_lists, k=60):
    """
    Combine multiple ranked lists using Reciprocal Rank Fusion.

    Args:
        rank_lists (list of lists): Each inner list is a ranked list of item IDs.
        k (int): Constant to dampen the effect of rank positions.

    Returns:
        list: Items ranked by fused score descending.
    """
    scores = {}
    for ranked_list in rank_lists:
        for rank, item in enumerate(ranked_list, start=1):
            scores[item] = scores.get(item, 0) + 1 / (k + rank)
    # Sort items by descending score
    fused_ranking = sorted(scores.items(), key=lambda x: x[1], reverse=True)
    return [item for item, score in fused_ranking]

# Example usage
ranked_lists = [
    ['doc1', 'doc2', 'doc3', 'doc4'],
    ['doc3', 'doc2', 'doc5', 'doc6'],
    ['doc2', 'doc7', 'doc3', 'doc8']
]
fused = reciprocal_rank_fusion(ranked_lists)
print("Fused ranking:", fused)
output
Fused ranking: ['doc2', 'doc3', 'doc1', 'doc7', 'doc4', 'doc5', 'doc6', 'doc8']

Common variations

You can adjust the k parameter to control how much influence lower-ranked items have in the fusion. Smaller k values give more weight to top ranks. RRF can be combined with other scoring methods or used in asynchronous pipelines for real-time search aggregation.

For large-scale AI search, integrate RRF with vector search libraries like FAISS or Chroma by applying RRF on top of multiple retrieval results.

Troubleshooting

  • If some items never appear in the fused ranking, ensure they are present in at least one input ranked list.
  • If the fused ranking seems dominated by one list, try increasing k to reduce the impact of top ranks.
  • For very large datasets, consider using efficient data structures like defaultdict or sparse matrices to optimize performance.

Key Takeaways

  • Reciprocal Rank Fusion sums reciprocal ranks across multiple lists to improve search result quality.
  • Adjust the damping parameter k to balance influence between top and lower-ranked items.
  • RRF is simple to implement and effective for aggregating AI search results from diverse sources.
Verified 2026-04
Verify ↗