Mulai cepat: Pencarian vektor dengan menggunakan REST
Pelajari cara menggunakan REST API Pencarian untuk membuat, memuat, dan mengkueri vektor di Azure AI Search.
Di Azure AI Search, penyimpanan vektor memiliki skema indeks yang menentukan bidang vektor dan nonvektor, konfigurasi vektor untuk algoritma yang membuat ruang penyematan, dan pengaturan pada definisi bidang vektor yang digunakan dalam permintaan kueri. API Buat Indeks membuat penyimpanan vektor.
Jika Anda tidak memiliki langganan Azure, buat akun gratis sebelum Anda memulai.
Catatan
Versi REST API 2023-11-01 yang stabil tergantung pada solusi eksternal untuk pemotongan dan penyematan data. Jika Anda ingin mengevaluasi fitur pemotongan dan vektorisasi data bawaan (pratinjau publik), coba wizard Impor dan vektorisasi data untuk panduan end-to-end.
Prasyarat
Visual Studio Code dengan klien REST. Jika Anda memerlukan bantuan untuk memulai, lihat Mulai Cepat: Pencarian teks menggunakan REST.
Pencarian Azure AI, di wilayah mana pun dan di tingkat mana pun. Anda dapat menggunakan tingkat Gratis untuk mulai cepat ini, tetapi Dasar atau lebih tinggi direkomendasikan untuk file data yang lebih besar. Buat atau temukan sumber daya Azure AI Search yang sudah ada di bawah langganan Anda saat ini.
Sebagian besar layanan yang ada mendukung pencarian vektor. Untuk subset kecil layanan yang dibuat sebelum Januari 2019, indeks yang berisi bidang vektor gagal pada pembuatan. Dalam situasi ini, layanan baru harus dibuat.
Secara opsional, untuk menjalankan contoh kueri yang memanggil reranking semantik, layanan pencarian Anda harus tingkat Dasar atau lebih tinggi, dengan peringkat semantik diaktifkan.
Secara opsional, sumber daya Azure OpenAI dengan penyebaran
text-embedding-ada-002
. File sumber.rest
mencakup langkah opsional untuk menghasilkan penyematan teks baru, tetapi kami menyediakan penyematan yang telah dibuat sebelumnya sehingga Anda dapat menghilangkan dependensi ini.
Mengunduh file
Unduh sampel REST dari GitHub untuk mengirim permintaan dalam mulai cepat ini. Untuk informasi selengkapnya, lihat Mengunduh file dari GitHub.
Anda juga dapat memulai file baru di sistem lokal Anda dan membuat permintaan secara manual dengan menggunakan instruksi dalam artikel ini.
Menyalin kunci layanan pencarian dan URL
Panggilan REST memerlukan titik akhir layanan pencarian dan kunci API pada setiap permintaan. Anda bisa mendapatkan nilai-nilai ini dari portal Azure.
Masuk ke portal Azure. Buka halaman Gambaran Umum dan salin URL. Contoh titik akhir mungkin terlihat seperti
https://mydemo.search.windows.net
.Pilih Pengaturan> Keys dan salin kunci admin. Kunci admin digunakan untuk menambahkan, memodifikasi, dan menghapus objek. Ada dua kunci admin yang dapat dipertukarkan. Salin salah satu.
Membuat indeks vektor
Buat Indeks (REST) membuat indeks vektor dan menyiapkan struktur data fisik pada layanan pencarian Anda.
Skema indeks diatur di sekitar konten hotel. Data sampel terdiri dari nama vektor dan nonvektor dan deskripsi tujuh hotel fiktif. Skema ini mencakup konfigurasi untuk pengindeksan dan kueri vektor, dan untuk peringkat semantik.
Buka file teks baru di Visual Studio Code.
Atur variabel ke titik akhir pencarian dan kunci API yang Anda kumpulkan sebelumnya.
@baseUrl = PUT-YOUR-SEARCH-SERVICE-URL-HERE @apiKey = PUT-YOUR-ADMIN-API-KEY-HERE
Simpan file dengan
.rest
ekstensi file.Tempelkan dalam contoh berikut untuk membuat
hotels-vector-quickstart
indeks di layanan pencarian Anda.### Create a new index POST {{baseUrl}}/indexes?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json api-key: {{apiKey}} { "name": "hotels-vector-quickstart", "fields": [ { "name": "HotelId", "type": "Edm.String", "searchable": false, "filterable": true, "retrievable": true, "sortable": false, "facetable": false, "key": true }, { "name": "HotelName", "type": "Edm.String", "searchable": true, "filterable": false, "retrievable": true, "sortable": true, "facetable": false }, { "name": "HotelNameVector", "type": "Collection(Edm.Single)", "searchable": true, "retrievable": true, "dimensions": 1536, "vectorSearchProfile": "my-vector-profile" }, { "name": "Description", "type": "Edm.String", "searchable": true, "filterable": false, "retrievable": true, "sortable": false, "facetable": false }, { "name": "DescriptionVector", "type": "Collection(Edm.Single)", "searchable": true, "retrievable": true, "dimensions": 1536, "vectorSearchProfile": "my-vector-profile" }, { "name": "Category", "type": "Edm.String", "searchable": true, "filterable": true, "retrievable": true, "sortable": true, "facetable": true }, { "name": "Tags", "type": "Collection(Edm.String)", "searchable": true, "filterable": true, "retrievable": true, "sortable": false, "facetable": true }, { "name": "Address", "type": "Edm.ComplexType", "fields": [ { "name": "City", "type": "Edm.String", "searchable": true, "filterable": true, "retrievable": true, "sortable": true, "facetable": true }, { "name": "StateProvince", "type": "Edm.String", "searchable": true, "filterable": true, "retrievable": true, "sortable": true, "facetable": true } ] }, { "name": "Location", "type": "Edm.GeographyPoint", "searchable": false, "filterable": true, "retrievable": true, "sortable": true, "facetable": false } ], "vectorSearch": { "algorithms": [ { "name": "my-hnsw-vector-config-1", "kind": "hnsw", "hnswParameters": { "m": 4, "efConstruction": 400, "efSearch": 500, "metric": "cosine" } }, { "name": "my-hnsw-vector-config-2", "kind": "hnsw", "hnswParameters": { "m": 4, "metric": "euclidean" } }, { "name": "my-eknn-vector-config", "kind": "exhaustiveKnn", "exhaustiveKnnParameters": { "metric": "cosine" } } ], "profiles": [ { "name": "my-vector-profile", "algorithm": "my-hnsw-vector-config-1" } ] }, "semantic": { "configurations": [ { "name": "my-semantic-config", "prioritizedFields": { "titleField": { "fieldName": "HotelName" }, "prioritizedContentFields": [ { "fieldName": "Description" } ], "prioritizedKeywordsFields": [ { "fieldName": "Tags" } ] } } ] } }
Pilih Kirim Permintaan. Ingat bahwa Anda memerlukan klien REST untuk mengirim permintaan. Anda harus memiliki
HTTP/1.1 201 Created
respons. Isi respons harus menyertakan representasi JSON dari skema indeks.Poin utama:
- Koleksi
fields
mencakup bidang kunci dan bidang teks dan vektor yang diperlukan (sepertiDescription
danDescriptionVector
) untuk pencarian teks dan vektor. Mengkolokasi bidang vektor dan nonvektor dalam indeks yang sama memungkinkan kueri hibrid. Misalnya, Anda dapat menggabungkan filter, pencarian teks dengan peringkat semantik, dan vektor ke dalam satu operasi kueri. - Bidang vektor harus
type: Collection(Edm.Single)
dengandimensions
properti danvectorSearchProfile
. - Bagian
vectorSearch
ini adalah array dari perkiraan konfigurasi dan profil algoritma tetangga terdekat. Algoritma yang didukung termasuk dunia kecil hierarkis yang dapat dinavigasi dan tetangga k terdekat yang lengkap. Untuk informasi selengkapnya, lihat Penilaian relevansi dalam pencarian vektor. - [Opsional]: Konfigurasi
semantic
memungkinkan reranking hasil pencarian. Anda dapat melakukan rerank menghasilkan kueri jenissemantic
untuk bidang string yang ditentukan dalam konfigurasi. Untuk mempelajari selengkapnya, lihat Gambaran umum peringkat semantik.
- Koleksi
Unggah dokumen
Membuat dan memuat indeks adalah langkah-langkah terpisah. Di Pencarian Azure AI, indeks berisi semua data dan kueri yang dapat dicari yang dijalankan pada layanan pencarian. Untuk panggilan REST, data disediakan sebagai dokumen JSON. Gunakan Dokumen- Indeks REST API untuk tugas ini.
URI diperluas untuk menyertakan docs
koleksi dan index
operasi.
Penting
Contoh berikut bukan kode yang dapat dijalankan. Untuk keterbacaan, kami mengecualikan nilai vektor karena masing-masing berisi 1.536 penyematan, yang terlalu panjang untuk artikel ini. Jika Anda ingin mencoba langkah ini, salin kode yang dapat dijalankan dari sampel di GitHub.
### Upload documents
POST {{baseUrl}}/indexes/hotels-quickstart-vectors/docs/index?api-version=2023-11-01 HTTP/1.1
Content-Type: application/json
api-key: {{apiKey}}
{
"value": [
{
"@search.action": "mergeOrUpload",
"HotelId": "1",
"HotelName": "Secret Point Motel",
"HotelNameVector": [VECTOR ARRAY OMITTED],
"Description":
"The hotel is ideally located on the main commercial artery of the city
in the heart of New York.",
"DescriptionVector": [VECTOR ARRAY OMITTED],
"Category": "Boutique",
"Tags": [
"pool",
"air conditioning",
"concierge"
],
},
{
"@search.action": "mergeOrUpload",
"HotelId": "2",
"HotelName": "Twin Dome Hotel",
"HotelNameVector": [VECTOR ARRAY OMITTED],
"Description":
"The hotel is situated in a nineteenth century plaza, which has been
expanded and renovated to the highest architectural standards to create a modern,
functional and first-class hotel in which art and unique historical elements
coexist with the most modern comforts.",
"DescriptionVector": [VECTOR ARRAY OMITTED],
"Category": "Boutique",
"Tags": [
"pool",
"air conditioning",
"free wifi",
"concierge"
]
},
{
"@search.action": "mergeOrUpload",
"HotelId": "3",
"HotelName": "Triple Landscape Hotel",
"HotelNameVector": [VECTOR ARRAY OMITTED],
"Description":
"The Hotel stands out for its gastronomic excellence under the management of
William Dough, who advises on and oversees all of the Hotel’s restaurant services.",
"DescriptionVector": [VECTOR ARRAY OMITTED],
"Category": "Resort and Spa",
"Tags": [
"air conditioning",
"bar",
"continental breakfast"
]
}
{
"@search.action": "mergeOrUpload",
"HotelId": "4",
"HotelName": "Sublime Cliff Hotel",
"HotelNameVector": [VECTOR ARRAY OMITTED],
"Description":
"Sublime Cliff Hotel is located in the heart of the historic center of
Sublime in an extremely vibrant and lively area within short walking distance to
the sites and landmarks of the city and is surrounded by the extraordinary beauty
of churches, buildings, shops and monuments.
Sublime Cliff is part of a lovingly restored 1800 palace.",
"DescriptionVector": [VECTOR ARRAY OMITTED],
"Category": "Boutique",
"Tags": [
"concierge",
"view",
"24-hour front desk service"
]
},
{
"@search.action": "mergeOrUpload",
"HotelId": "13",
"HotelName": "Historic Lion Resort",
"HotelNameVector": [VECTOR ARRAY OMITTED],
"Description":
"Unmatched Luxury. Visit our downtown hotel to indulge in luxury
accommodations. Moments from the stadium, we feature the best in comfort",
"DescriptionVector": [VECTOR ARRAY OMITTED],
"Category": "Resort and Spa",
"Tags": [
"view",
"free wifi",
"pool"
]
},
{
"@search.action": "mergeOrUpload",
"HotelId": "48",
"HotelName": "Nordicks Hotel",
"HotelNameVector": [VECTOR ARRAY OMITTED],
"Description":
"Only 90 miles (about 2 hours) from the nation's capital and nearby
most everything the historic valley has to offer. Hiking? Wine Tasting? Exploring
the caverns? It's all nearby and we have specially priced packages to help make
our B&B your home base for fun while visiting the valley.",
"DescriptionVector": [VECTOR ARRAY OMITTED],
"Category": "Boutique",
"Tags": [
"continental breakfast",
"air conditioning",
"free wifi"
],
},
{
"@search.action": "mergeOrUpload",
"HotelId": "49",
"HotelName": "Old Carrabelle Hotel",
"HotelNameVector": [VECTOR ARRAY OMITTED],
"Description":
"Spacious rooms, glamorous suites and residences, rooftop pool, walking
access to shopping, dining, entertainment and the city center.",
"DescriptionVector": [VECTOR ARRAY OMITTED],
"Category": "Luxury",
"Tags": [
"air conditioning",
"laundry service",
"24-hour front desk service"
]
}
]
}
Poin utama:
- Dokumen dalam payload terdiri dari bidang yang ditentukan dalam skema indeks.
- Bidang vektor berisi nilai titik mengambang. Atribut dimensi memiliki minimal 2 dan maksimum 3.072 nilai titik mengambang masing-masing. Mulai cepat ini mengatur atribut dimensi ke 1.536 karena itu adalah ukuran penyematan yang dihasilkan oleh model open AI text-embedding-ada-002 .
Jalankan Kueri
Setelah dokumen dimuat, Anda dapat mengeluarkan kueri vektor terhadapnya dengan menggunakan Dokumen - Pos Pencarian (REST).
Ada beberapa kueri untuk menunjukkan berbagai pola:
- Pencarian vektor tunggal
- Pencarian vektor tunggal dengan filter
- Pencarian hibrid
- Pencarian hibrid semantik dengan filter
Kueri vektor di bagian ini didasarkan pada dua string:
- String pencarian:
historic hotel walk to restaurants and shopping
- String kueri vektor (di-vektorisasi ke dalam representasi matematika):
classic lodging near running trails, eateries, retail
String kueri vektor secara semantik mirip dengan string pencarian, tetapi menyertakan istilah yang tidak ada dalam indeks pencarian. Jika Anda melakukan pencarian kata kunci untuk classic lodging near running trails, eateries, retail
, hasilnya adalah nol. Kami menggunakan contoh ini untuk menunjukkan bagaimana Anda bisa mendapatkan hasil yang relevan meskipun tidak ada istilah yang cocok.
Penting
Contoh berikut bukan kode yang dapat dijalankan. Untuk keterbacaan, kami mengecualikan nilai vektor karena setiap array berisi 1.536 penyematan, yang terlalu panjang untuk artikel ini. Jika Anda ingin mencoba kueri ini, salin kode yang dapat dijalankan dari sampel di GitHub.
Pencarian vektor tunggal
Tempelkan permintaan POST untuk mengkueri indeks pencarian. Lalu pilih Kirim permintaan. URI diperluas untuk menyertakan
/docs/search
operator.### Run a query POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json api-key: {{apiKey}} { "count": true, "select": "HotelId, HotelName, Description, Category", "vectorQueries": [ { "vector"": [0.01944167, 0.0040178085 . . . TRIMMED FOR BREVITY 010858015, -0.017496133], "k": 7, "fields": "DescriptionVector", "kind": "vector", "exhaustive": true } ] }
Kueri vektor ini dipersingkat untuk brevity.
vectorQueries.vector
berisi teks vektor input kueri,fields
menentukan bidang vektor mana yang dicari, dank
menentukan jumlah tetangga terdekat yang akan dikembalikan.String kueri vektor adalah
classic lodging near running trails, eateries, retail
, yang di vektorisasi menjadi 1.536 penyematan untuk kueri ini.Tinjau responsnya. Respons untuk vektor yang setara
classic lodging near running trails, eateries, retail
dengan mencakup tujuh hasil. Setiap hasil menyediakan skor pencarian dan bidang yang tercantum dalamselect
. Dalam pencarian kesamaan, respons selalu menyertakank
hasil yang diurutkan berdasarkan skor kesamaan nilai.{ "@odata.context": "https://my-demo-search.search.windows.net/indexes('hotels-vector-quickstart')/$metadata#docs(*)", "@odata.count": 7, "value": [ { "@search.score": 0.857736, "HotelName": "Nordick's Motel", "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer. Hiking? Wine Tasting? Exploring the caverns? It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley." }, { "@search.score": 0.8399129, "HotelName": "Old Carrabelle Hotel", "Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center." }, { "@search.score": 0.8383954, "HotelName": "Historic Lion Resort", "Description": "Unmatched Luxury. Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort" }, { "@search.score": 0.8254346, "HotelName": "Sublime Cliff Hotel", "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace." }, { "@search.score": 0.82380056, "HotelName": "Secret Point Hotel", "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York." }, { "@search.score": 0.81514084, "HotelName": "Twin Dome Hotel", "Description": "The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts." }, { "@search.score": 0.8133763, "HotelName": "Triple Landscape Hotel", "Description": "The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services." } ] }
Pencarian vektor tunggal dengan filter
Anda dapat menambahkan filter, tetapi filter diterapkan ke konten nonvektor dalam indeks Anda. Dalam contoh ini, filter berlaku untuk Tags
bidang untuk memfilter hotel apa pun yang tidak menyediakan Wi-Fi gratis.
Tempelkan permintaan POST untuk mengkueri indeks pencarian.
### Run a vector query with a filter POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json api-key: {{apiKey}} { "count": true, "select": "HotelId, HotelName, Category, Tags, Description", "filter": "Tags/any(tag: tag eq 'free wifi')", "vectorFilterMode": "postFilter", "vectorQueries": [ { "vector": [ VECTOR OMITTED ], "k": 7, "fields": "DescriptionVector", "kind": "vector", "exhaustive": true }, ] }
Tinjau responsnya. Kueri sama dengan contoh sebelumnya, tetapi mencakup filter pengecualian pasca-pemrosesan dan hanya mengembalikan tiga hotel yang memiliki Wi-Fi gratis.
{ "@odata.count": 3, "value": [ { "@search.score": 0.857736, "HotelName": "Nordick's Motel", "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer. Hiking? Wine Tasting? Exploring the caverns? It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley.", "Tags": [ "continental breakfast", "air conditioning", "free wifi" ] }, { "@search.score": 0.8383954, "HotelName": "Historic Lion Resort", "Description": "Unmatched Luxury. Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort", "Tags": [ "view", "free wifi", "pool" ] }, { "@search.score": 0.81514084, "HotelName": "Twin Dome Hotel", "Description": "The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts.", "Tags": [ "pool", "free wifi", "concierge" ] } ] }
Pencarian hibrid
Pencarian hibrid terdiri dari kueri kata kunci dan kueri vektor dalam satu permintaan pencarian. Contoh ini menjalankan kueri vektor dan pencarian teks lengkap secara bersamaan:
- String pencarian:
historic hotel walk to restaurants and shopping
- String kueri vektor (di-vektorisasi ke dalam representasi matematika):
classic lodging near running trails, eateries, retail
Tempelkan permintaan POST untuk mengkueri indeks pencarian. Lalu pilih Kirim permintaan.
### Run a hybrid query POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json api-key: {{apiKey}} { "count": true, "search": "historic hotel walk to restaurants and shopping", "select": "HotelName, Description", "top": 7, "vectorQueries": [ { "vector": [ VECTOR OMITTED], "k": 7, "fields": "DescriptionVector", "kind": "vector", "exhaustive": true } ] }
Karena ini adalah kueri hibrid, hasil diberi peringkat oleh Reciprocal Rank Fusion (RRF). RRF mengevaluasi skor pencarian dari beberapa hasil pencarian, mengambil kebalikannya, lalu menggabungkan dan mengurutkan hasil gabungan.
top
Jumlah hasil dikembalikan.Tinjau responsnya.
{ "@odata.count": 7, "value": [ { "@search.score": 0.03279569745063782, "HotelName": "Historic Lion Resort", "Description": "Unmatched Luxury. Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort" }, { "@search.score": 0.03226646035909653, "HotelName": "Sublime Cliff Hotel", "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace." }, { "@search.score": 0.03226646035909653, "HotelName": "Old Carrabelle Hotel", "Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center." }, { "@search.score": 0.03205128386616707, "HotelName": "Nordick's Motel", "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer. Hiking? Wine Tasting? Exploring the caverns? It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley." }, { "@search.score": 0.03128054738044739, "HotelName": "Triple Landscape Hotel", "Description": "The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services." }, { "@search.score": 0.03100961446762085, "HotelName": "Twin Dome Hotel", "Description": "The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts." }, { "@search.score": 0.03077651560306549, "HotelName": "Secret Point Hotel", "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York." } ] }
Karena RRF menggabungkan hasil, RRF membantu meninjau input. Hasil berikut hanya berasal dari kueri teks lengkap. Dua hasil teratas adalah Sublime Cliff Hotel dan History Lion Resort. Sublime Cliff Hotel memiliki skor relevansi BM25 yang lebih kuat.
{ "@search.score": 2.2626662, "HotelName": "Sublime Cliff Hotel", "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace." }, { "@search.score": 0.86421645, "HotelName": "Historic Lion Resort", "Description": "Unmatched Luxury. Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort" },
Dalam kueri khusus vektor, yang menggunakan HNSW untuk menemukan kecocokan, Sublime Cliff Hotel turun ke posisi keempat. Historic Lion, yang berada di urutan kedua dalam pencarian teks lengkap dan ketiga dalam pencarian vektor, tidak mengalami rentang fluktuasi yang sama, sehingga muncul sebagai kecocokan teratas dalam tataan hasil yang homogen.
"value": [ { "@search.score": 0.857736, "HotelId": "48", "HotelName": "Nordick's Motel", "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer. Hiking? Wine Tasting? Exploring the caverns? It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley.", "Category": "Boutique" }, { "@search.score": 0.8399129, "HotelId": "49", "HotelName": "Old Carrabelle Hotel", "Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center.", "Category": "Luxury" }, { "@search.score": 0.8383954, "HotelId": "13", "HotelName": "Historic Lion Resort", "Description": "Unmatched Luxury. Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium, we feature the best in comfort", "Category": "Resort and Spa" }, { "@search.score": 0.8254346, "HotelId": "4", "HotelName": "Sublime Cliff Hotel", "Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace.", "Category": "Boutique" }, { "@search.score": 0.82380056, "HotelId": "1", "HotelName": "Secret Point Hotel", "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York.", "Category": "Boutique" }, { "@search.score": 0.81514084, "HotelId": "2", "HotelName": "Twin Dome Hotel", "Description": "The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts.", "Category": "Boutique" }, { "@search.score": 0.8133763, "HotelId": "3", "HotelName": "Triple Landscape Hotel", "Description": "The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services.", "Category": "Resort and Spa" } ]
Pencarian hibrid semantik dengan filter
Berikut adalah kueri terakhir dalam koleksi. Kueri hibrid dengan peringkat semantik ini difilter untuk menunjukkan hanya hotel dalam radius 500 kilometer dari Washington D.C. Anda dapat mengatur vectorFilterMode
ke null, yang setara dengan default (preFilter
untuk indeks yang lebih baru dan postFilter
untuk yang lebih lama).
Tempelkan permintaan POST untuk mengkueri indeks pencarian. Lalu pilih Kirim permintaan.
### Run a hybrid query POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json api-key: {{apiKey}} { "count": true, "search": "historic hotel walk to restaurants and shopping", "select": "HotelId, HotelName, Category, Description,Address/City, Address/StateProvince", "filter": "geo.distance(Location, geography'POINT(-77.03241 38.90166)') le 500", "vectorFilterMode": null, "facets": [ "Address/StateProvince"], "top": 7, "queryType": "semantic", "answers": "extractive|count-3", "captions": "extractive|highlight-true", "semanticConfiguration": "my-semantic-config", "vectorQueries": [ { "vector": [ VECTOR OMITTED ], "k": 7, "fields": "DescriptionVector", "kind": "vector", "exhaustive": true } ] }
Tinjau responsnya. Responsnya adalah tiga hotel, yang difilter berdasarkan lokasi dan disaring oleh
StateProvince
dan direrankasi secara semantik untuk mempromosikan hasil yang paling dekat dengan kueri string pencarian (historic hotel walk to restaurants and shopping
).Hotel Old Carabelle kini bergerak ke posisi teratas. Tanpa peringkat semantik, Nordick's Hotel adalah nomor satu. Dengan peringkat semantik, model pemahaman mesin mengenali yang
historic
berlaku untuk "hotel, dalam jarak berjalan kaki ke makan (restoran) dan berbelanja."{ "@odata.count": 3, "@search.facets": { "Address/StateProvince": [ { "count": 1, "value": "NY" }, { "count": 1, "value": "VA" } ] }, "@search.answers": [], "value": [ { "@search.score": 0.03306011110544205, "@search.rerankerScore": 2.5094974040985107, "HotelId": "49", "HotelName": "Old Carrabelle Hotel", "Description": "Spacious rooms, glamorous suites and residences, rooftop pool, walking access to shopping, dining, entertainment and the city center.", "Category": "Luxury", "Address": { "City": "Arlington", "StateProvince": "VA" } }, { "@search.score": 0.03306011110544205, "@search.rerankerScore": 2.0370211601257324, "HotelId": "48", "HotelName": "Nordick's Motel", "Description": "Only 90 miles (about 2 hours) from the nation's capital and nearby most everything the historic valley has to offer. Hiking? Wine Tasting? Exploring the caverns? It's all nearby and we have specially priced packages to help make our B&B your home base for fun while visiting the valley.", "Category": "Boutique", "Address": { "City": "Washington D.C.", "StateProvince": null } }, { "@search.score": 0.032258063554763794, "@search.rerankerScore": 1.6706111431121826, "HotelId": "1", "HotelName": "Secret Point Hotel", "Description": "The hotel is ideally located on the main commercial artery of the city in the heart of New York.", "Category": "Boutique", "Address": { "City": "New York", "StateProvince": "NY" } } ] }
Poin utama:
- Pencarian vektor ditentukan melalui
vectors.value
properti . Pencarian kata kunci ditentukan melaluisearch
properti . - Dalam pencarian hibrid, Anda dapat mengintegrasikan pencarian vektor dengan pencarian teks lengkap melalui kata kunci. Filter, pemeriksaan ejaan, dan peringkat semantik hanya berlaku untuk konten tekstual, dan bukan vektor. Dalam kueri akhir ini, tidak ada semantik
answer
karena sistem tidak menghasilkan yang cukup kuat. - Hasil aktual mencakup detail lebih lanjut, termasuk keterangan semantik dan sorotan. Hasil dimodifikasi untuk keterbacaan. Untuk mendapatkan struktur respons lengkap, jalankan permintaan di klien REST.
- Pencarian vektor ditentukan melalui
Penghapusan
Saat bekerja dengan langganan Anda sendiri, sebaiknya identifikasi apakah Anda masih membutuhkan sumber daya yang Anda buat di akhir proyek. Sumber daya yang dibiarkan berjalan dapat menghabiskan uang Anda. Anda dapat menghapus sumber daya satu per satu atau menghapus grup sumber daya untuk menghapus seluruh rangkaian sumber daya.
Anda dapat menemukan dan mengelola sumber daya di portal dengan menggunakan tautan Semua sumber daya atau Grup sumber daya di panel paling kiri.
Anda juga dapat mencoba perintah ini DELETE
:
### Delete an index
DELETE {{baseUrl}}/indexes/hotels-vector-quickstart?api-version=2023-11-01 HTTP/1.1
Content-Type: application/json
api-key: {{apiKey}}
Langkah berikutnya
Sebagai langkah selanjutnya, kami sarankan Anda meninjau kode demo untuk Python, C#, atau JavaScript.