RRF - Cosmos DB 中的查询语言(在 Azure 和 Fabric 中)

RRF 函数通过组合其他函数提供的两个或多个分数来返回融合分数。

Syntax

RRF(<function1>, <function2>, ..., <weights>)

Arguments

Description
function1 评分函数,如 VectorDistance 或 FullTextScore。
function2 评分函数,如 VectorDistance 或 FullTextScore。
weights 定义每个评分函数的重要性权重的数字数组。

返回类型

返回表示融合分数的数值。

例子

本部分包含有关如何使用此查询语言构造的示例。

混合搜索(矢量相似性 + BM25)

在此示例中,混合搜索结合了 FullTextScore 和 VectorDistance。

SELECT TOP 10 *
FROM c
ORDER BY RANK RRF(FullTextScore(c.text, "keyword"), VectorDistance(c.vector, [1,2,3]))
-- Example result not available (see documentation)

在此示例中,混合搜索使用评分函数的权重。

SELECT TOP 10 *
FROM c
ORDER BY RANK RRF(FullTextScore(c.text, "keyword"), VectorDistance(c.vector, [1,2,3]), [2,1])
-- Example result not available (see documentation)

使用两个 FullTextScore 函数进行融合

在此示例中,将融合两个 FullTextScore 函数。

SELECT TOP 10 *
FROM c
ORDER BY RANK RRF(FullTextScore(c.text, "keyword1"), FullTextScore(c.text, "keyword2"))
-- Example result not available (see documentation)

使用两个 VectorDistance 函数进行融合

在此示例中,将融合两个 VectorDistance 函数。

SELECT TOP 5 *
FROM c
ORDER BY RANK RRF(VectorDistance(c.vector1, [1,2,3]), VectorDistance(c.vector2, [2,2,4]))
-- Example result not available (see documentation)

注解

  • 此函数需要在 Azure Cosmos DB NoSQL 全文搜索功能中注册。
  • 混合搜索还需要在 Azure Cosmos DB NoSQL 矢量搜索中注册。
  • 此函数需要全文索引。
  • 此函数只能在子 ORDER BY RANK 句中使用,不能与其他 ORDER BY 属性路径结合使用。
  • 此函数不能是投影的一部分(例如, SELECT FullTextScore(c.text, "keyword") AS Score FROM c 无效)。