快速入門:使用 REST API 進行向量搜尋
了解如何使用搜尋服務 REST API 在 Azure AI 搜尋服務中建立、載入及查詢向量。
在 Azure AI 搜尋中, 向量存放區 具有定義向量和非向量欄位的索引架構、用於建立內嵌空間之演算法的向量搜尋組態,以及查詢時評估的向量字段定義設定。 建立 索引 REST API 會建立向量存放區。
如尚未擁有 Azure 訂用帳戶,請在開始之前先建立免費帳戶。
注意
本快速入門省略向量化步驟,並提供範例文件中的內嵌。 如果您想要將內建資料區塊化和向量化新增至您自己的內容,請嘗試匯入和向量化資料精靈,以取得完整的逐步解說。
必要條件
Azure AI 搜尋,在任何區域和任何層級。 您可以針對本快速入門使用免費層級,但建議針對較大的資料檔案使用基本或更高層級。 在您的目前訂用帳戶下建立或尋找現有的 Azure AI 搜尋服務資源。
大部分現有的服務都支援向量搜尋。 2019 年 1 月之前建立的一小部分服務,包含向量欄位的索引在建立時會失敗。 在此情況下,必須建立新的服務。
下載檔案
從 GitHub 下載 REST 範例,以在此快速入門中傳送要求。 如需相關資訊,請參閱從 GitHub 下載檔案。
您也可以在本機系統上啟動新的檔案,並使用本文中的指示手動建立要求。
取得搜尋端點和 API 金鑰
您可以在 Azure 入口網站 中找到搜尋服務端點和 API 金鑰。 您會在下一個步驟中將這些值貼到 .rest
或 .http
檔案中。
對搜尋端點發出的要求必須經過驗證和授權。 您可以針對這項工作使用 API 金鑰或角色。 金鑰較容易上手,但角色更安全。 雖然我們針對本快速入門使用 API 金鑰,但建議您 切換至無密鑰連線。
登入 Azure 入口網站,然後尋找您的搜尋服務。
在 [概觀] 首頁上,尋找 URL。 範例端點看起來會像是
https://mydemo.search.windows.net
。選取 [設定]>[金鑰]。 必須啟用 API 金鑰或兩者。 系統管理 API 金鑰 可用來新增、修改和刪除物件。 有兩個可交換的系統管理密鑰。 複製任一個。
建立向量索引
建立索引 (REST) 會建立向量索引,並在您的搜尋服務上設定實體資料結構。
索引架構會針對旅館內容進行組織。 範例資料是由七家虛構旅館的向量和非向量名稱和描述所組成。 此架構包含向量索引編製和查詢的設定,以及語意排名的設定。
在 Visual Studio Code 中建立新的文字檔。
在檔案頂端,新增您稍早收集值的變數。
@baseUrl = PUT-YOUR-SEARCH-SERVICE-URL-HERE @apiKey = PUT-YOUR-ADMIN-KEY-HERE
使用
.rest
或.http
副檔名來儲存檔案。貼上下列範例,在搜尋服務上建立
hotels-vector-quickstart
索引。### 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" } } ], "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" } ] } } ] } }
再次儲存盤案,然後選取 [ 傳送要求]。 您應該會有
HTTP/1.1 201 Created
回應。 回應主體應該包含索引架構的 JSON 表示法。關於此 REST API 的重要要點:
fields
集合包含文字和向量搜尋所需的索引鍵欄位、文字和向量欄位(例如Description
和DescriptionVector
)。 在同一個索引中共置向量和非向量欄位可啟用混合式查詢。 例如,您可以將篩選、文字搜尋與語意排名和向量合併成單一查詢作業。向量欄位必須是有
dimensions
和vectorSearchProfile
屬性的type: Collection(Edm.Single)
。vectorSearch
區段是近似最近鄰演算法設定和設定檔的陣列。 支援的演算法包括階層式可導覽小世界 (navigable small world) 和詳盡的 K 最近鄰 (k-nearest neighbor)。 如需詳細資訊,請參閱向量搜尋中的相關性評分。[選用]:
semantic
設定可重新排名搜尋結果。 針對設定中所指定的字串欄位,您可以進行類型semantic
查詢結果的重新排名。 若要深入了解,請參閱語意排名概觀。
上傳文件
建立和載入索引是單獨的步驟。 在 Azure AI 搜尋服務中,索引包含所有可搜尋資料以及對搜尋服務執行的查詢。 針對 REST 呼叫,數據會以 JSON 文件的形式提供。 針對這項工作使用 Documents- Index REST API。
URI 會擴充以包含 docs
集合和 index
作業。
重要
下列範例不是可執行的程式碼。 為了可讀性,我們排除了向量值,因為每個值都包含 1,536 個內嵌,這對於本文而言太長。 如果您想要嘗試此步驟,請從 GitHub 上的範例中複製可執行的程式碼。
貼上上傳檔的有效要求,如下所示。
儲存盤案,然後選取 [ 傳送要求]。 您應該會有
HTTP/1.1 201 Created
回應。 回應本文應包含搜尋檔的 JSON 表示法。
### 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": "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"
]
}
]
}
關於此 REST API 的重要要點:
承載中的文件是由索引架構中定義的欄位所組成。
向量欄位包含浮點值。 維度屬性至少有 2 個,而且每個值最多 3,072 個浮點數。 本快速入門會將維度屬性設定為 1,536,因為這是 Azure OpenAI text-embedding-ada-002 模型所產生的內嵌大小。
執行查詢
現在已載入文件,您可以使用文件 - 搜尋貼文 (REST) 來對其發出向量查詢。
有一些查詢可示範各種模式:
本節中的向量查詢是以兩個字串為基礎:
- 搜尋字串:
historic hotel walk to restaurants and shopping
- 向量查詢字串 (向量化為數學表示法):
classic lodging near running trails, eateries, retail
向量查詢字串在語意上類似於搜尋字串,但包含搜尋索引中不存在的字詞。 如果您對 classic lodging near running trails, eateries, retail
執行關鍵詞搜尋,則結果為零。 我們使用此範例示範如何取得相關結果,即使沒有相符的字詞也一樣。
重要
下列範例是無法執行的程式碼。 為了可讀性,我們排除了向量值,因為每個陣列都包含 1,536 個內嵌,這對於本文而言太長。 如果您想要嘗試這些步驟,請從 GitHub 上的範例中複製可執行的程式碼。
單一向量搜尋
貼上 POST 要求以查詢搜尋索引。 儲存檔案。 然後選取 [傳送要求]。 URI 會擴充以包含
/docs/search
運算子。### 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 } ] }
為了簡潔起見,此向量查詢會縮短。
vectorQueries.vector
包含查詢輸入的向量化文字,fields
決定要搜尋的向量欄位,而k
指定要傳回的最近鄰數目。向量查詢字串是
classic lodging near running trails, eateries, retail
,其會向量化為此查詢的 1,536 個內嵌。檢閱回應。
classic lodging near running trails, eateries, retail
對等向量的回應包含七個結果。 每個結果都會提供搜尋分數和列在select
中的欄位。 在相似性搜尋中,回應一律包含依值相似度分數排序的k
結果。{ "@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 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.8399129, "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.8383954, "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.8254346, "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.82380056, "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." }, { "@search.score": 0.81514084, "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.8133763, "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." } ] }
使用篩選的單一向量搜尋
您可以新增篩選,但篩選條件會套用於索引中的非向量內容。 在此範例中,篩選會套用於 Tags
欄位,篩選排除任何不提供免費 Wi-Fi 的旅館。
貼上 POST 要求以查詢搜尋索引。
### 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 }, ] }
檢閱回應。 此查詢與前一個範例相同,但包含後置處理的排除篩選,並只傳回具有免費 Wi-Fi 的三家旅館。
{ "@odata.count": 3, "value": [ { "@search.score": 0.857736, "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.", "Tags": [ "continental breakfast", "air conditioning", "free wifi" ] }, { "@search.score": 0.8383954, "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", "Tags": [ "view", "free wifi", "pool" ] }, { "@search.score": 0.81514084, "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.", "Tags": [ "pool", "free wifi", "concierge" ] } ] }
混合式搜尋
混合式搜尋是由單一搜尋要求中的關鍵字查詢和向量查詢所組成。 此範例會同時執行向量查詢和全文檢索搜尋:
- 搜尋字串:
historic hotel walk to restaurants and shopping
- 向量查詢字串 (向量化為數學表示法):
classic lodging near running trails, eateries, retail
貼上 POST 要求以查詢搜尋索引。 然後選取 [傳送要求]。
### 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 } ] }
因為這是混合式查詢,因此結果會依倒數排名融合 (RRF) 進行排名。 RRF 會評估多個搜尋結果的搜尋分數、採用反向排列,然後合併並排序合併的結果。 傳回的結果數目
top
。檢閱回應。
{ "@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." } ] }
因為 RRF 會合併結果,所以有助於檢閱輸入。 下列結果僅來自全文檢索搜尋查詢。 前兩名的結果是崇高宮酒店和歷史獅子度假村。 昇華宮酒店具有更強的BM25相關性分數。
{ "@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" },
在僅向量查詢中,使用 HNSW 尋找相符專案,Sublime 故宮酒店會降至第四個位置。 Historic Lion 在全文檢索搜尋中排名第二,在向量搜尋中排名第三,並未經歷相同的波動範圍,因此成為同質化結果集中的最高相符項目。
"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" } ]
使用篩選的語意混合式搜尋
以下是集合中的最後一個查詢。 此具有語意排名的混合式查詢會經過篩選,只顯示位於華盛頓特區 500 公里半徑內的旅館。您可以將 vectorFilterMode
設定為 null,這相當於預設值 (較新索引的 preFilter
和較舊索引的 postFilter
)。
貼上 POST 要求以查詢搜尋索引。 然後選取 [傳送要求]。
### 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 } ] }
檢閱回應。 回應中有三家旅館,依位置篩選,並根據
StateProvince
進行 Facet 篩選,然後經過語意排名以提升最接近搜尋字串查詢的結果 (historic hotel walk to restaurants and shopping
)。旋轉流酒店現在進入頂級位置。 沒有語意排名,北歐的山谷汽車旅館是頭號。 使用語意排名,機器理解模型認識到,
historic
適用於「旅館,餐飲 (餐廳) 和購物地點在步行距離內」。{ "@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": "Swirling Currents 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 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", "Address": { "City": "Washington D.C.", "StateProvince": null } }, { "@search.score": 0.032258063554763794, "@search.rerankerScore": 1.6706111431121826, "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", "Address": { "City": "New York", "StateProvince": "NY" } } ] }
關於此 REST API 的重要要點:
向量搜尋是透過
vectors.value
屬性來指定。 關鍵字搜尋是透過search
屬性來指定。在混合式搜尋中,您可以將向量搜尋與關鍵字的全文檢索搜尋整合。 篩選、拼字檢查和語意排名僅適用於文字內容,而非向量。 在此最終查詢中,沒有語意
answer
,因為系統不會產生足夠強的語意。實際結果包含更多詳細資料,包括語意標題和醒目提示。 結果已針對可讀性進行修改。 若要取得回應的完整結構,請在 REST 用戶端中執行要求。
清理
如果您是在自己的訂用帳戶中進行,建議您在專案結束時判斷自己是否仍需要先前所建立的資源。 資源若繼續執行,將需付費。 您可以個別刪除資源,或刪除資源群組以刪除整組資源。
您可以使用最左邊窗格中的 [所有資源] 或 [資源群組] 連結,在 Azure 入口網站 中找到和管理資源。
您也可以嘗試此 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}}
下一步
在下一個步驟中,建議您瞭解如何在沒有 API 金鑰的情況下叫用 REST API 呼叫。
您也可以檢閱 Python、C# 或 JavaScript 的示範程式碼。