The $rrf retriever runs several retrievers and merges their results with Reciprocal Rank Fusion
(RRF). Each retriever ranks its own results. A document gets points from every retriever that returns
it, so documents that rank high in several retrievers come first.
Use $rrf for hybrid search, to merge a full-text query with an $ann semantic search. It
also merges full-text queries only, or $ann retrievers only.
Parameters#
| Parameter | Description | Default |
|---|---|---|
retrievers | Required. 2 to 10 retrievers to merge. Each entry is a query object, a $standard, or an $ann. | |
rankConstant | An integer between 1 and 2147483647. Higher values give lower-ranked results more influence. | 60 |
window | An integer between 1 and 11000. The number of results each retriever contributes, and the maximum number of merged results. See Paging. | LIMIT |
Scoring#
Each retriever that returns a document adds weight / (rankConstant + rank) to its score. rank is the
position of the document in that retriever’s results, starting at 1.
These scores are small numbers. Compare them only with other results of the same query.
Weights#
A weight scales how much a retriever adds to the score. All retrievers have a weight of 1 by default.
- To set the weight of a query object, wrap it in
$standard. - An
$annretriever takesweightdirectly. - A weight must be
0or greater. With a weight of0, the documents of that retriever stay in the results, but the retriever adds nothing to their score.
Paging#
window sets how deep $rrf looks:
- Each retriever contributes up to
windowresults, and the merged list is cut atwindow. - When
windowis not set, it is equal toLIMIT, which is10by default. LIMITcannot be larger thanwindow.- To use
OFFSET, setwindow. A page that starts at or afterwindowis empty.
Keep the same window on every page so that pages do not overlap.
Examples#
Hybrid Search#
Merge a full-text query and a semantic search on the same field:
Weighted Hybrid Search#
Give the full-text query twice the weight of the semantic search:
Full-Text Queries Only#
$rrf does not need HYBRID fields:
Paging Through Results#
Set window and keep it the same on every page:
See Query Options for the SEARCH.QUERY options that work with $rrf, and
Counting and Aggregations for SEARCH.COUNT and
SEARCH.AGGREGATE.