函數會 RRF 結合其他函數提供的兩個或多個分數,傳回融合分數。
語法
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]))
[
{
"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]
}
]
與兩個 FullTextScore 函數的融合
在此範例中,會融合兩個 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."
}
]
與兩個 VectorDistance 函數融合
在此範例中,兩個 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無效)。