RRF関数は、他の関数によって提供される 2 つ以上のスコアを組み合わせることによって、融合されたスコアを返します。
構文
RRF(<function1>, <function2>, ..., <weights>)
論争
| 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]))
[
{
"id": "doc-042",
"text": "The keyword appears frequently in this document about distributed systems.",
"vector": [0.12, 0.87, 0.34]
},
{
"id": "doc-119",
"text": "Another relevant document mentioning the keyword in context.",
"vector": [0.45, 0.22, 0.91]
}
]
重み付けハイブリッド検索
この例では、ハイブリッド検索ではスコアリング関数の重みを使用します。
SELECT TOP 10 *
FROM c
ORDER BY RANK RRF(FullTextScore(c.text, "keyword"), VectorDistance(c.vector, [1,2,3]), [2,1])
[
{
"id": "doc-007",
"text": "This document contains the keyword and is semantically close to the query vector.",
"vector": [0.98, 0.11, 0.23]
},
{
"id": "doc-355",
"text": "A document with strong keyword relevance boosted by the higher weight.",
"vector": [0.67, 0.44, 0.18]
}
]
2 つの FullTextScore 関数を使用した Fusion
この例では、2 つの FullTextScore 関数が融合されています。
SELECT TOP 10 *
FROM c
ORDER BY RANK RRF(FullTextScore(c.text, "keyword1"), FullTextScore(c.text, "keyword2"))
[
{
"id": "doc-201",
"text": "This article discusses both keyword1 and keyword2 in the context of data engineering."
},
{
"id": "doc-088",
"text": "A comprehensive overview that mentions keyword1 and covers keyword2 in detail."
}
]
2 つの VectorDistance 関数を使用した Fusion
この例では、2 つの VectorDistance 関数が融合されています。
SELECT TOP 5 *
FROM c
ORDER BY RANK RRF(VectorDistance(c.vector1, [1,2,3]), VectorDistance(c.vector2, [2,2,4]))
[
{
"id": "doc-014",
"vector1": [0.12, 0.87, 0.34],
"vector2": [0.56, 0.78, 0.90]
},
{
"id": "doc-092",
"vector1": [0.45, 0.22, 0.91],
"vector2": [0.33, 0.67, 0.45]
}
]
注釈
- この関数には、Azure Cosmos DB NoSQL フルテキスト検索機能への登録が必要です。
- ハイブリッド検索では、Azure Cosmos DB NoSQL ベクター検索への登録も必要です。
- この関数にはフルテキスト インデックスが必要です。
- この関数は、
ORDER BY RANK句でのみ使用でき、他のプロパティ パスのORDER BYと組み合わせることはできません。 - この関数をプロジェクションの一部にすることはできません (たとえば、
SELECT FullTextScore(c.text, "keyword") AS Score FROM cは無効です)。