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 pencarian vektor untuk algoritma yang membuat ruang penyematan, dan pengaturan pada definisi bidang vektor yang dievaluasi pada waktu kueri. Buat Indeks REST API membuat penyimpanan vektor.
Jika Anda tidak memiliki langganan Azure, buat akun gratis sebelum Anda memulai.
Catatan
Mulai cepat ini menghilangkan langkah vektorisasi dan menyediakan penyematan dalam dokumen sampel. Jika Anda ingin menambahkan pemotongan dan vektorisasi data bawaan melalui konten Anda sendiri, coba wizard Impor dan vektorisasi data untuk panduan end-to-end.
Prasyarat
Visual Studio Code dengan klien REST.
Pencarian Azure AI, di wilayah mana pun dan di tingkat mana pun. Buat atau temukan sumber daya Azure AI Search yang sudah ada di bawah langganan Anda saat ini.
- Anda dapat menggunakan tingkat Gratis untuk sebagian besar mulai cepat ini, tetapi Dasar atau lebih tinggi direkomendasikan untuk file data yang lebih besar.
- Untuk menjalankan contoh kueri yang memanggil reranking semantik, layanan pencarian Anda harus tingkat Dasar atau lebih tinggi, dengan peringkat semantik diaktifkan.
Mengambil informasi sumber daya
Permintaan ke titik akhir pencarian harus diautentikasi dan diotorisasi. Anda dapat menggunakan kunci atau peran API untuk tugas ini. Sebaiknya gunakan koneksi tanpa kunci melalui ID Microsoft Entra.
Pilih tab yang sesuai dengan metode autentikasi pilihan Anda. Gunakan metode yang sama untuk semua permintaan dalam mulai cepat ini.
Masuk ke portal Azure dan temukan layanan pencarian Anda.
Pada beranda Gambaran Umum , temukan URL. Contoh titik akhir mungkin terlihat seperti
https://mydemo.search.windows.net
.Ikuti langkah-langkah dalam mulai cepat tanpa kunci untuk mendapatkan token Microsoft Entra Anda.
Anda mendapatkan token saat menjalankan
az account get-access-token
perintah di langkah 3 dari mulai cepat sebelumnya.az account get-access-token --scope https://search.azure.com/.default --query accessToken --output tsv
Membuat atau mengunduh file kode
Anda menggunakan satu .rest
atau .http
file untuk menjalankan semua permintaan dalam mulai cepat ini. Anda dapat mengunduh file REST yang berisi kode untuk mulai cepat ini, atau Anda dapat membuat file baru di Visual Studio Code dan menyalin kode ke dalamnya.
Di Visual Studio Code, buat file baru dengan
.rest
ekstensi file atau.http
. Contohnya,az-search-vector-quickstart.rest
. Salin dan tempel konten mentah file Azure-Samples/azure-search-rest-samples/blob/main/Quickstart-vectors/az-search-vector-quickstart.rest ke dalam file baru ini.Di bagian atas file, ganti nilai tempat penampung dengan
@baseUrl
URL layanan pencarian Anda. Lihat bagian Ambil informasi sumber daya untuk petunjuk tentang cara menemukan URL layanan pencarian Anda.@baseUrl = PUT-YOUR-SEARCH-SERVICE-URL-HERE
Di bagian atas file, ganti nilai tempat penampung untuk autentikasi. Lihat bagian Ambil informasi sumber daya untuk instruksi tentang cara mendapatkan token Microsoft Entra atau kunci API Anda.
Untuk autentikasi tanpa kunci yang direkomendasikan melalui ID Microsoft Entra, Anda perlu mengganti
@apiKey
dengan@token
variabel .@token = PUT-YOUR-MICROSOFT-ENTRA-TOKEN-HERE
Jika Anda lebih suka menggunakan kunci API, ganti
@apiKey
dengan kunci yang Anda salin dari portal Azure.@apiKey = PUT-YOUR-ADMIN-KEY-HERE
Untuk autentikasi tanpa kunci yang direkomendasikan melalui ID Microsoft Entra, Anda perlu mengganti
api-key: {{apiKey}}
denganAuthorization: Bearer {{token}}
di header permintaan. Ganti semua instansapi-key: {{apiKey}}
yang Anda temukan dalam file.
Membuat indeks vektor
Anda menggunakan Buat Indeks REST API untuk membuat indeks vektor dan menyiapkan struktur data fisik pada layanan pencarian Anda.
Skema indeks dalam contoh ini diatur di sekitar konten hotel. Data sampel terdiri dari nama vektor dan nonvektor dan deskripsi hotel fiktif. Skema ini mencakup konfigurasi untuk pengindeksan dan kueri vektor, dan untuk peringkat semantik.
Di Visual Studio Code, buka file yang
az-search-vector-quickstart.rest
Anda buat sebelumnya.### Create a new index
Temukan blok kode dalam file. Blok ini berisi permintaan untuk membuathotels-vector-quickstart
indeks pada layanan pencarian Anda.### Create a new index POST {{baseUrl}}/indexes?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json Authorization: Bearer {{token}} { "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": "Description_fr", "type": "Edm.String", "searchable": true, "filterable": false, "retrievable": true, "sortable": false, "facetable": false, "analyzer": "en.microsoft" }, { "name": "Description_frvector", "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": "ParkingIncluded", "type": "Edm.Boolean", "searchable": false, "filterable": true, "retrievable": true, "sortable": true, "facetable": true }, { "name": "LastRenovationDate", "type": "Edm.DateTimeOffset", "searchable": false, "filterable": true, "retrievable": true, "sortable": true, "facetable": true }, { "name": "Rating", "type": "Edm.Double", "searchable": false, "filterable": true, "retrievable": true, "sortable": true, "facetable": true }, { "name": "Address", "type": "Edm.ComplexType", "fields": [ { "name": "StreetAddress", "type": "Edm.String", "searchable": true, "filterable": false, "retrievable": true, "sortable": false, "facetable": false }, { "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": "PostalCode", "type": "Edm.String", "searchable": true, "filterable": true, "retrievable": true, "sortable": true, "facetable": true }, { "name": "Country", "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": "Category" } ] } } ] } }
Pilih Kirim Permintaan. Anda harus memiliki
HTTP/1.1 201 Created
respons.
Isi respons harus menyertakan representasi JSON dari skema indeks.
{
"@odata.context": "https://my-demo-search.search.windows.net/$metadata#indexes/$entity",
"@odata.etag": "\"0x8DD2E70E6C36D8E\"",
"name": "hotels-vector-quickstart",
"defaultScoringProfile": null,
"fields": [
{
"name": "HotelId",
"type": "Edm.String",
"searchable": false,
"filterable": true,
"retrievable": true,
"sortable": false,
"facetable": false,
"key": true,
"indexAnalyzer": null,
"searchAnalyzer": null,
"analyzer": null,
"dimensions": null,
"vectorSearchProfile": null,
"synonymMaps": []
},
[MORE FIELD DEFINITIONS OMITTED FOR BREVITY]
],
"scoringProfiles": [],
"corsOptions": null,
"suggesters": [],
"analyzers": [],
"tokenizers": [],
"tokenFilters": [],
"charFilters": [],
"encryptionKey": null,
"similarity": {
"@odata.type": "#Microsoft.Azure.Search.BM25Similarity",
"k1": null,
"b": null
},
"vectorSearch": {
"algorithms": [
{
"name": "my-hnsw-vector-config-1",
"kind": "hnsw",
"hnswParameters": {
"metric": "cosine",
"m": 4,
"efConstruction": 400,
"efSearch": 500
},
"exhaustiveKnnParameters": null
},
{
"name": "my-hnsw-vector-config-2",
"kind": "hnsw",
"hnswParameters": {
"metric": "euclidean",
"m": 4,
"efConstruction": 400,
"efSearch": 500
},
"exhaustiveKnnParameters": null
},
{
"name": "my-eknn-vector-config",
"kind": "exhaustiveKnn",
"hnswParameters": null,
"exhaustiveKnnParameters": {
"metric": "cosine"
}
}
],
"profiles": [
{
"name": "my-vector-profile",
"algorithm": "my-hnsw-vector-config-1"
}
]
},
"semantic": {
"defaultConfiguration": null,
"configurations": [
{
"name": "my-semantic-config",
"prioritizedFields": {
"titleField": {
"fieldName": "HotelName"
},
"prioritizedContentFields": [
{
"fieldName": "Description"
}
],
"prioritizedKeywordsFields": [
{
"fieldName": "Category"
}
]
}
}
]
}
}
Kunci takeaways tentang Create Index REST API:
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.Konfigurasi (opsional)
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.
Unggah dokumen
Membuat dan memuat indeks adalah langkah-langkah terpisah. Anda membuat skema indeks di langkah sebelumnya. Sekarang Anda perlu memuat dokumen ke dalam indeks.
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.
Di Visual Studio Code, buka file yang
az-search-vector-quickstart.rest
Anda buat sebelumnya.### Upload documents
Temukan blok kode dalam file. Blok ini berisi permintaan untuk mengunggah dokumen kehotels-vector-quickstart
indeks pada layanan pencarian Anda.### Upload documents POST {{baseUrl}}/indexes/hotels-quickstart-vectors/docs/index?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json Authorization: Bearer {{token}} { "value": [ { "@search.action": "mergeOrUpload", "HotelId": "1", "HotelName": "Stay-Kay City Hotel", "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": "Old Century 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": "Gastronomic 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 Palace Hotel", "HotelNameVector": [VECTOR ARRAY OMITTED], "Description": "Sublime Palace 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 Palace 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": "Luxury 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": "Nordick's Valley Motel", "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": "Swirling Currents 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" ] } ] }
Penting
Kode dalam contoh ini tidak dapat dijalankan. Beberapa karakter atau garis dihapus untuk keringkasan. Gunakan kode dalam file Anda
az-search-vector-quickstart.rest
untuk menjalankan permintaan.Pilih Kirim Permintaan. Anda harus memiliki
HTTP/1.1 200 OK
respons. Isi respons harus menyertakan representasi JSON dari dokumen pencarian.
Kunci takeaways tentang permintaan Dokumen - Indeks REST API :
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 penyematan teks-ada-002 Azure OpenAI.
Jalankan Kueri
Setelah dokumen dimuat, Anda dapat mengeluarkan kueri vektor terhadapnya dengan menggunakan Dokumen - Pos Pencarian (REST).
Di bagian berikutnya, kita menjalankan kueri terhadap hotels-vector-quickstart
indeks. Kueri meliputi:
- Pencarian vektor tunggal
- Pencarian vektor tunggal dengan filter
- Pencarian hibrid
- Pencarian hibrid semantik dengan filter
Contoh kueri vektor 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.
Pencarian vektor tunggal
Di Visual Studio Code, buka file yang
az-search-vector-quickstart.rest
Anda buat sebelumnya.### Run a single vector query
Temukan blok kode dalam file. Blok ini berisi permintaan untuk mengkueri indeks pencarian.### Run a single vector query POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json Authorization: Bearer {{token}} { "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.Penting
Kode dalam contoh ini tidak dapat dijalankan. Beberapa karakter atau garis dihapus untuk keringkasan. Gunakan kode dalam file Anda
az-search-vector-quickstart.rest
untuk menjalankan permintaan.Pilih Kirim Permintaan. Anda harus memiliki
HTTP/1.1 200 OK
respons. Isi respons harus menyertakan representasi JSON dari hasil pencarian.
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 dalam select
. Dalam pencarian kesamaan, respons selalu menyertakan k
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.85773647,
"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.8399132,
"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.83839583,
"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.82543474,
"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.82380104,
"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.8151413,
"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.8133767,
"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\u2019s restaurant services.",
"Category": "Resort and Spa"
}
]
}
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.
Di Visual Studio Code, buka file yang
az-search-vector-quickstart.rest
Anda buat sebelumnya.### Run a vector query with a filter
Temukan blok kode dalam file. Blok ini berisi permintaan 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 Authorization: Bearer {{token}} { "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 }, ] }
Penting
Kode dalam contoh ini tidak dapat dijalankan. Beberapa karakter atau garis dihapus untuk keringkasan. Gunakan kode dalam file Anda
az-search-vector-quickstart.rest
untuk menjalankan permintaan.Pilih Kirim Permintaan. Anda harus memiliki
HTTP/1.1 200 OK
respons. Isi respons harus menyertakan representasi JSON dari hasil pencarian.
Kueri sama dengan contoh pencarian vektor tunggal sebelumnya, tetapi mencakup filter pengecualian pasca-pemrosesan dan hanya mengembalikan tiga hotel yang memiliki Wi-Fi gratis.
{
"@odata.context": "https://my-demo-search.search.windows.net/indexes('hotels-vector-quickstart')/$metadata#docs(*)",
"@odata.count": 3,
"value": [
{
"@search.score": 0.85773647,
"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",
"Tags": [
"continental breakfast",
"air conditioning",
"free wifi"
]
},
{
"@search.score": 0.83839583,
"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",
"Tags": [
"view",
"free wifi",
"pool"
]
},
{
"@search.score": 0.8151413,
"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",
"Tags": [
"pool",
"free wifi",
"air conditioning",
"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
Di Visual Studio Code, buka file yang
az-search-vector-quickstart.rest
Anda buat sebelumnya.### Run a hybrid query
Temukan blok kode dalam file. Blok ini berisi permintaan untuk mengkueri indeks pencarian.### Run a hybrid query POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json Authorization: Bearer {{token}} { "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 } ] }
Penting
Kode dalam contoh ini tidak dapat dijalankan. Beberapa karakter atau garis dihapus untuk keringkasan. Gunakan kode dalam file Anda
az-search-vector-quickstart.rest
untuk menjalankan permintaan.Pilih Kirim Permintaan. Anda harus memiliki
HTTP/1.1 200 OK
respons. Isi respons harus menyertakan representasi JSON dari hasil pencarian.
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 respons:
{
"@odata.count": 7,
"value": [
{
"@search.score": 0.03279569745063782,
"HotelName": "Luxury 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 Palace Hotel",
"Description": "Sublime Palace 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 Palace is part of a lovingly restored 1800 palace."
},
{
"@search.score": 0.03226646035909653,
"HotelName": "Swirling Currents 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 Valley 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": "Gastronomic 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": "Old Century 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": "Stay-Kay City 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 Palace Hotel dan History Lion Resort. Hotel Sublime Palace memiliki skor relevansi BM25 yang lebih kuat.
{
"@search.score": 2.2626662,
"HotelName": "Sublime Palace Hotel",
"Description": "Sublime Palace 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 Palace is part of a lovingly restored 1800 palace."
},
{
"@search.score": 0.86421645,
"HotelName": "Luxury 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, Hotel Sublime Palace 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 Valley 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": "Swirling Currents 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": "Luxury 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 Palace Hotel",
"Description": "Sublime Palace 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 Palace is part of a lovingly restored 1800 palace.",
"Category": "Boutique"
},
{
"@search.score": 0.82380056,
"HotelId": "1",
"HotelName": "Stay-Kay City 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": "Old Century 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": "Gastronomic 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).
Di Visual Studio Code, buka file yang
az-search-vector-quickstart.rest
Anda buat sebelumnya.### Run a hybrid query with semantic reranking
Temukan blok kode dalam file. Blok ini berisi permintaan untuk mengkueri indeks pencarian.### Run a hybrid query with semantic reranking POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1 Content-Type: application/json Authorization: Bearer {{token}} { "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 } ] }
Penting
Kode dalam contoh ini tidak dapat dijalankan. Beberapa karakter atau garis dihapus untuk keringkasan. Gunakan kode dalam file Anda
az-search-vector-quickstart.rest
untuk menjalankan permintaan.Pilih Kirim Permintaan. Anda harus memiliki
HTTP/1.1 200 OK
respons. Isi respons harus menyertakan representasi JSON dari hasil pencarian.
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 Swirling Currents sekarang bergerak ke tempat teratas. Tanpa peringkat semantik, Nordick's Valley Motel 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.context": "https://my-demo-search.search.windows.net/indexes('hotels-vector-quickstart')/$metadata#docs(*)",
"@odata.count": 2,
"@search.facets": {
"Address/StateProvince": [
{
"count": 1,
"value": "VA"
}
]
},
"@search.answers": [],
"value": [
{
"@search.score": 0.03306011110544205,
"@search.rerankerScore": 2.8773112297058105,
"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.1703834533691406,
"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
}
}
]
}
Kunci takeaways tentang Dokumen - Search Post REST API:
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.
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 Azure dengan menggunakan tautan Semua sumber daya atau Grup sumber daya di panel paling kiri.
Jika Anda ingin menyimpan layanan pencarian, tetapi menghapus indeks dan dokumen, Anda dapat menggunakan DELETE
perintah di klien REST. Perintah ini (di akhir file Anda az-search-vector-quickstart.rest
) menghapus hotels-vector-quickstart
indeks:
### Delete an index
DELETE {{baseUrl}}/indexes/hotels-vector-quickstart?api-version=2023-11-01 HTTP/1.1
Content-Type: application/json
Authorization: Bearer {{token}}
Langkah berikutnya
Sebagai langkah selanjutnya, sebaiknya pelajari cara memanggil panggilan REST API tanpa kunci API.
Anda mungkin juga ingin meninjau kode demo untuk Python, C#, atau JavaScript.