RRF - Cosmos DB'de sorgu dili (Azure ve Doku'da)

İşlev, RRF diğer işlevler tarafından sağlanan iki veya daha fazla puanı birleştirerek birleştirilmiş puan döndürür.

Sözdizimi

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

Arguments

Description
function1 VectorDistance veya FullTextScore gibi bir puanlama işlevi.
function2 VectorDistance veya FullTextScore gibi bir puanlama işlevi.
weights Her puanlama işlevi için bir önem ağırlığı tanımlayan bir sayı dizisi.

Dönüş türleri

Birleştirilmiş puanı temsil eden sayısal bir değer döndürür.

Örnekler

Bu bölüm, bu sorgu dili yapısının nasıl kullanılacağına örnekler içerir.

Karma Arama (vektör benzerliği + BM25)

Bu örnekte Karma Arama, FullTextScore ve VectorDistance'ı birleştirir.

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]
  }
]

Bu örnekte Karma Arama, puanlama işlevleri için ağırlıkları kullanır.

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]
  }
]

İki FullTextScore işleviyle fusion

Bu örnekte iki FullTextScore işlevi birleştirilmiştir.

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."
  }
]

İki VectorDistance işleviyle fusion

Bu örnekte iki VectorDistance işlevi birleştirilmiştir.

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]
  }
]

Açıklamalar

  • Bu işlev, Azure Cosmos DB NoSQL Tam Metin Arama özelliğine kaydolmayı gerektirir.
  • Karma Arama ayrıca Azure Cosmos DB NoSQL Vektör Araması'nda da kayıt gerektirir.
  • Bu işlev tam metin dizini gerektirir.
  • Bu işlev yalnızca bir ORDER BY RANK yan tümcesinde kullanılabilir ve diğer özellik yollarında ile ORDER BY birleştirılamaz.
  • Bu işlev bir projeksiyonun parçası olamaz (örneğin, SELECT FullTextScore(c.text, "keyword") AS Score FROM c geçersizdir).