RRF - Bahasa kueri di Cosmos DB (di Azure dan Fabric)

Fungsi mengembalikan RRF skor menyatu dengan menggabungkan dua skor atau lebih yang disediakan oleh fungsi lain.

Syntax

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

Arguments

Description
function1 Fungsi penilaian seperti VectorDistance atau FullTextScore.
function2 Fungsi penilaian seperti VectorDistance atau FullTextScore.
weights Array angka yang menentukan bobot penting untuk setiap fungsi penilaian.

Tipe pengembalian

Mengembalikan nilai numerik yang mewakili skor yang menyatu.

Examples

Bagian ini berisi contoh cara menggunakan konstruksi bahasa kueri ini.

Pencarian Hibrid (kesamaan vektor + BM25)

Dalam contoh ini, Hybrid Search menggabungkan FullTextScore dan 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]
  }
]

Dalam contoh ini, Pencarian Hibrid menggunakan bobot untuk fungsi penilaian.

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

Fusion dengan dua fungsi FullTextScore

Dalam contoh ini, dua fungsi FullTextScore menyatu.

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

Fusion dengan dua fungsi VectorDistance

Dalam contoh ini, dua fungsi VectorDistance menyatu.

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

Komentar

  • Fungsi ini memerlukan pendaftaran di fitur Pencarian Teks Lengkap Azure Cosmos DB NoSQL.
  • Pencarian Hibrid juga memerlukan pendaftaran di Azure Cosmos DB NoSQL Vector Search.
  • Fungsi ini memerlukan Indeks Teks Lengkap.
  • Fungsi ini hanya dapat digunakan dalam klausa ORDER BY RANK , dan tidak dapat dikombinasikan dengan ORDER BY pada jalur properti lainnya.
  • Fungsi ini tidak dapat menjadi bagian dari proyeksi (misalnya, SELECT FullTextScore(c.text, "keyword") AS Score FROM c tidak valid).