Overview
RrfReRanker combines results from multiple vector queries using Reciprocal Rank Fusion (RRF). This algorithm assigns higher weight to documents that appear early in multiple result lists, without requiring relevance scores.
The RRF score for a document at rank r is calculated as:
k is the rank constant.
This reranker is specifically designed for multi-vector scenarios where query results from multiple vector fields need to be combined.
Constructor
Parameters
Number of top documents to return after reranking.
Ignored by RRF. This parameter exists for API consistency but has no effect.
Smoothing constant
k in the RRF formula. Larger values reduce the impact of early ranks, making the fusion more balanced across different result lists.Properties
The rank constant used in the RRF score calculation.
Number of top documents to return.
Methods
rerank()
Results from one or more vector queries. Keys are vector field names, values are lists of retrieved documents.
Re-ranked documents with RRF scores in the
score field.Usage Example
Multi-Vector Search with RRF
Adjusting Rank Constant
Therank_constant parameter controls how aggressively early ranks are weighted:
How It Works
- Collect Results: Gather documents from all vector field queries
- Calculate RRF Scores: For each document, sum RRF scores across all queries where it appears
- Deduplicate: Documents appearing in multiple result lists are processed once
- Rank: Return top
ndocuments by RRF score
Example
Given two query results:rank_constant=60:
- doc_A:
1/(60+2+1) + 1/(60+0+1)=0.0159 + 0.0164=0.0323 - doc_B:
1/(60+1+1) + 1/(60+0+1)=0.0161 + 0.0164=0.0325← highest - doc_C:
1/(60+2+1)=0.0159 - doc_D:
1/(60+1+1)=0.0161
When to Use RRF
Use RRF when:
- Combining results from multiple vector fields
- You don’t have access to raw similarity scores
- You want a simple, parameter-free fusion method
- Query fields have similar importance