RANK_FUSION
RANK_FUSION (field [DESC|ASC] [weight], field [DESC|ASC] [weight]) [OPTION(k=60)]
is a function for Reciprocal Rank Fusion (RRF) that generates a combined ranking from two different search modalities like vector search and text search. RRF addresses score normalization across different search modalities by making use of the ranks of each document rather than the scores themselves, according to the following formula:
Here, D
represents the set of documents to be ranked and R
corresponds to the set of corresponding rankings. k
is set to 60 by default, however this parameter can be tuned as needed.
The collection data used in the following SQL query contains four documents:
+------+-------------------+
| id | score_a | score_b |
|------+-------------------|
| doc1 | 0.33 | 0.50 |
| doc2 | 0.50 | 1.00 |
| doc3 | 1.00 | 0.25 |
| doc4 | 0.25 | 0.33 |
+------+---------+---------+
Below is an example of using RANK_FUSION
to calculate the combined rankings for the above documents:
SELECT
_id,
RANK_FUSION(score_a, score_b) AS rrf
FROM
rankings
ORDER BY rrf DESC