### Upload documents
POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/index?api-version=2023-11-01 HTTP/1.1
Content-Type: application/json
api-key: {{apiKey}}
Request
{
"value": [
{
"@search.action": "mergeOrUpload",
"HotelId": "1",
"HotelName": "Secret Point Hotel",
"HotelNameVector": [0.0040753875,0.004081966,0.007854742],
"Description": "The hotel is ideally located on the...",
"DescriptionVector": [-0.020142354,0.017661706],
"Category": "Boutique",
"Tags": [
"pool",
"air conditioning",
"concierge"
],
"ParkingIncluded": false,
"LastRenovationDate": "1970-01-18T00:00:00Z",
"Rating": 3.60,
"Address": {
"StreetAddress": "677 5th Ave",
"City": "New York",
"StateProvince": "NY",
"PostalCode": "10022",
"Country": "USA"
},
"Location": {
"type": "Point",
"coordinates": [
-73.975403,
40.760586
]
}
}
]
}
這邊資料很長,所以只貼一筆資料,並且縮減向量,方便瀏覽,實際請到 Github 範例程式碼中查看
9. 執行單一向量查詢
類似查詢資料表
count: 是否回傳筆數
select: 回傳的欄位
vectorQueries: 向量查詢
vector: 向量
k: 回傳筆數
fields: 欄位
kind: 向量
exhaustive: 是否完整搜尋
### 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
api-key: {{apiKey}}
{
"@odata.context": "https://ai-jakeuj.search.windows.net/indexes('hotels-vector-quickstart')/$metadata#docs(*)",
"@odata.count": 7,
"value": [
{
"@search.score": 0.8577363,
"HotelId": "48",
"HotelName": "Nordick's Motel",
"Description": "Only 90 miles (about 2 hours) from the nati...",
"Category": "Boutique"
},
{
"@search.score": 0.8399121,
"HotelId": "49",
"HotelName": "Old Carrabelle Hotel",
"Description": "Spacious rooms, glamorous suites and reside...",
"Category": "Luxury"
},
{
"@search.score": 0.8383955,
"HotelId": "13",
"HotelName": "Historic Lion Resort",
"Description": "Unmatched Luxury. Visit our downtown hotel...",
"Category": "Resort and Spa"
},
{
"@search.score": 0.82543427,
"HotelId": "4",
"HotelName": "Sublime Cliff Hotel",
"Description": "Sublime Cliff Hotel is located in the heart...",
"Category": "Boutique"
},
{
"@search.score": 0.82380015,
"HotelId": "1",
"HotelName": "Secret Point Hotel",
"Description": "The hotel is ideally located on the main co...",
"Category": "Boutique"
},
{
"@search.score": 0.81514114,
"HotelId": "2",
"HotelName": "Twin Dome Hotel",
"Description": "The hotel is situated in a nineteenth cent...",
"Category": "Boutique"
},
{
"@search.score": 0.813376,
"HotelId": "3",
"HotelName": "Triple Landscape Hotel",
"Description": "The Hotel stands out for its gastronomic ...",
"Category": "Resort and Spa"
}
]
}
10. 執行向量查詢並加上過濾器
類似帶過濾條件查詢資料表
filter: 篩選條件
vectorFilterMode: 向量篩選模式
### 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}}
{
"@odata.context": "https://ai-jakeuj.search.windows.net/indexes('hotels-vector-quickstart')/$metadata#docs(*)",
"@odata.count": 3,
"value": [
{
"@search.score": 0.8577363,
"HotelId": "48",
"HotelName": "Nordick's Motel",
"Description": "Only 90 miles (about 2 hours) from the nati...",
"Category": "Boutique",
"Tags": [
"continental breakfast",
"air conditioning",
"free wifi"
]
},
{
"@search.score": 0.8383955,
"HotelId": "13",
"HotelName": "Historic Lion Resort",
"Description": "Unmatched Luxury. Visit our downtown hotel...",
"Category": "Resort and Spa",
"Tags": [
"view",
"free wifi",
"pool"
]
},
{
"@search.score": 0.81514114,
"HotelId": "2",
"HotelName": "Twin Dome Hotel",
"Description": "The hotel is situated in a nineteenth cent...",
"Category": "Boutique",
"Tags": [
"pool",
"free wifi",
"air conditioning",
"concierge"
]
}
]
}
11. 執行混合查詢
同時運行全文和向量查詢
### 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}}
Request
{
"count": true,
"search": "historic hotel walk to restaurants and shopping",
"select": "HotelId, HotelName, Category, Tags, Description",
"top": 7,
"vectorQueries": [
{
"vector": [0.01944167, 0.0040178085, -0.007816401, 0.009330357],
"k": 7,
"fields": "DescriptionVector",
"kind": "vector",
"exhaustive": true
}
]
}
Response
{
"@odata.context": "https://ai-jakeuj.search.windows.net/indexes('hotels-vector-quickstart')/$metadata#docs(*)",
"@odata.count": 7,
"value": [
{
"@search.score": 0.03306011110544205,
"HotelId": "49",
"HotelName": "Old Carrabelle Hotel",
"Description": "Spacious rooms, glamorous suites and reside...",
"Category": "Luxury",
"Tags": [
"air conditioning",
"laundry service",
"24-hour front desk service"
]
},
{
"@search.score": 0.032522473484277725,
"HotelId": "13",
"HotelName": "Historic Lion Resort",
"Description": "Unmatched Luxury. Visit our downtown hotel...",
"Category": "Resort and Spa",
"Tags": [
"view",
"free wifi",
"pool"
]
},
{
"@search.score": 0.03205128386616707,
"HotelId": "48",
"HotelName": "Nordick's Motel",
"Description": "Only 90 miles (about 2 hours) from the nati...",
"Category": "Boutique",
"Tags": [
"continental breakfast",
"air conditioning",
"free wifi"
]
},
{
"@search.score": 0.0320020467042923,
"HotelId": "4",
"HotelName": "Sublime Cliff Hotel",
"Description": "Sublime Cliff Hotel is located in the heart...",
"Category": "Boutique",
"Tags": [
"concierge",
"view",
"24-hour front desk service"
]
},
{
"@search.score": 0.03125763311982155,
"HotelId": "2",
"HotelName": "Twin Dome Hotel",
"Description": "The hotel is situated in a nineteenth cent...",
"Category": "Boutique",
"Tags": [
"pool",
"free wifi",
"air conditioning",
"concierge"
]
},
{
"@search.score": 0.03077651560306549,
"HotelId": "1",
"HotelName": "Secret Point Hotel",
"Description": "The hotel is ideally located on the main ...",
"Category": "Boutique",
"Tags": [
"pool",
"air conditioning",
"concierge"
]
},
{
"@search.score": 0.03077651560306549,
"HotelId": "3",
"HotelName": "Triple Landscape Hotel",
"Description": "The Hotel stands out for its gastronomic ...",
"Category": "Resort and Spa",
"Tags": [
"air conditioning",
"bar",
"continental breakfast"
]
}
]
}
12. 執行混合查詢並進行語意重新排序
混合查詢(全文和向量查詢)與語義重新排序功能,以提升搜索結果的相關性和質量
queryType: 查詢類型
semanticConfiguration: 語義配置
facets: 分類
### Run a hybrid query with semantic reranking (requires Basic tier or above)
POST {{baseUrl}}/indexes/hotels-vector-quickstart/docs/search?api-version=2023-11-01 HTTP/1.1
Content-Type: application/json
api-key: {{apiKey}}
{
"error": {
"code": "FeatureNotSupportedInService",
"message": "Semantic search is not enabled for this service.\r\nParameter name: queryType",
"details": [
{
"code": "SemanticQueriesNotAvailable",
"message": "Semantic search is not enabled for this service."
}
]
}
}
這邊我用免費層,所以無法使用該功能
requires Basic tier or above
13. 執行範例程式碼刪除索引
類似刪除資料表
### Delete an index
DELETE {{baseUrl}}/indexes/hotels-vector-quickstart?api-version=2023-11-01 HTTP/1.1
Content-Type: application/json
api-key: {{apiKey}}