Prerequisites: To use hybrid search with sparse embeddings, you must first configure a sparse vector index in your collection schema. See Sparse Vector Search Setup for configuration instructions.
Understanding RRF
Reciprocal Rank Fusion combines multiple rankings by using rank positions rather than raw scores. This makes it effective for merging rankings with different score scales.RRF Formula
RRF combines rankings using the formula: Where:- = weight for ranking i (default: 1.0)
- = rank position from ranking i (0, 1, 2, …)
- = smoothing parameter (default: 60)
Important: The legacy
query API outputs distances, whereas RRF uses scoresRrf Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
ranks | List[Rank] | Required | List of ranking expressions (must have return_rank=True) |
k | int | 60 | Smoothing parameter - higher values reduce emphasis on top ranks |
weights | List[float] or None | None | Weights for each ranking (defaults to 1.0 for each) |
normalize | bool | False | If True, normalize weights to sum to 1.0 |
RRF vs Linear Combination
| Approach | Use Case | Pros | Cons |
|---|---|---|---|
| RRF | Different score scales (e.g., dense + sparse) | Scale-agnostic, robust to outliers | Requires return_rank=True |
| Linear Combination | Same score scales | Simple, preserves distances | Sensitive to scale differences |
The return_rank Requirement
RRF requires rank positions (0, 1, 2…) not distance scores. Always setreturn_rank=True on all Knn expressions used in RRF.
Weight Configuration
The k Parameter
Thek parameter controls how much emphasis is placed on top-ranked results:
- Small k (e.g., 10): Heavy emphasis on top ranks
- Default k (60): Balanced emphasis (standard in literature)
- Large k (e.g., 100+): More uniform weighting across ranks
Common Use Case: Dense + Sparse
The most common RRF use case is combining dense semantic embeddings with sparse keyword embeddings.Edge Cases and Important Behavior
Component Ranking Behavior
Each Knn component in RRF operates on the documents that pass the filter. The number of results from each component is the minimum of itslimit parameter and the number of filtered documents. RRF handles varying result counts gracefully - documents from any ranking are scored.
Minimum Requirements
- At least one ranking expression is required
- All rankings must have
return_rank=True - Weights (if provided) must match the number of rankings
Document Selection with RRF
Documents must appear in at least one component ranking to be scored. To include documents that don’t appear in a specific Knn’s results, set thedefault parameter on that Knn:
RRF as a Convenience Wrapper
Rrf is a convenience class that constructs the underlying ranking expression. You can manually build the same expression if needed:
Complete Example
Here’s a practical example showing RRF with filtering and result processing:Tips and Best Practices
- Always use
return_rank=Truefor all Knn expressions in RRF - Set appropriate limits on component Knn expressions (usually 100-500)
- Consider the k parameter - default of 60 works well for most cases
- Test different weights - start with equal weights, then tune based on results
- Use
defaultvalues in Knn if you want documents from partial matches
Next Steps
- Learn about batch operations for running multiple RRF searches
- See practical examples of hybrid search in production
- Explore ranking expressions for arithmetic combinations instead of RRF