共用方式為


快速入門:使用 REST 進行向量搜尋

瞭解如何使用 搜尋 REST API 在 Azure AI 搜尋服務中建立、載入和查詢向量。

在 Azure AI 搜尋服務中,「向量存放區」具有定義向量和非向量欄位的索引結構描述、建立內嵌空間的演算法向量設定,以及向量欄位定義上用於查詢要求的設定。 建立索引 API 會建立向量存放區。

如尚未擁有 Azure 訂用帳戶,請在開始之前先建立免費帳戶

注意

穩定的 2023-11-01 REST API 版本取決於數據區塊化和內嵌的外部解決方案。 如果您想要評估內建的數據區塊化和向量化功能 (公開預覽) 功能,請嘗試匯入和向量化數據精靈,以取得端對端逐步解說。

必要條件

  • 具有 REST 用戶端Visual Studio Code。 如果您需要開始使用的協助,請參閱 快速入門:使用 REST 進行文字搜尋。

  • Azure AI 搜尋,在任何區域和任何層級。 您可以針對本快速入門使用免費層,但建議針對較大的數據檔使用基本或更高層級。 在您的 目前訂用帳戶下建立或 尋找現有的 Azure AI 搜尋資源

    大部分現有的服務都支援向量搜尋。 對於在 2019 年 1 月之前建立的一小部分服務,包含向量欄位的索引在建立時會失敗。 在此情況下,必須建立新的服務。

  • 或者,若要執行叫 用語意重新叫用的查詢範例,您的搜尋服務必須是基本層或更高層級,並 啟用語意排名。

  • 選擇性地,具有 部署的 text-embedding-ada-002Azure OpenAI 資源。 來源 .rest 檔案包含產生新文字內嵌的選擇性步驟,但我們提供預先產生的內嵌,以便省略此相依性。

下載檔案

從 GitHub 下載 REST 範例 ,以在此快速入門中傳送要求。 如需詳細資訊,請參閱 從 GitHub 下載檔案。

您也可以在本機系統上啟動新的檔案,並使用本文中的指示手動建立要求。

複製搜尋服務金鑰和 URL

REST 呼叫需要每個要求的搜尋服務端點和 API 金鑰。 您可以從 Azure 入口網站 取得這些值。

  1. 登入 Azure 入口網站。 移至 [ 概觀] 頁面並複製 URL。 範例端點看起來會像是 https://mydemo.search.windows.net

  2. 選取 [設定> Keys],然後複製管理密鑰。 管理員 索引鍵可用來新增、修改和刪除物件。 有兩個可交換的系統管理密鑰。 複製任一個。

    顯示 Azure 入口網站 中 URL 和 API 金鑰的螢幕快照。

建立向量索引

建立索引 (REST) 會建立向量索引,並在您的搜尋服務上設定實體數據結構。

索引架構是圍繞酒店內容進行組織。 範例數據是由向量和非向量名稱和七家虛構旅館的描述所組成。 此架構包含向量索引編製和查詢的組態,以及語意排名的組態。

  1. 在 Visual Studio Code 中開啟新的文字檔。

  2. 將變數設定為您稍早收集的搜尋端點和 API 金鑰。

    @baseUrl = PUT-YOUR-SEARCH-SERVICE-URL-HERE
    @apiKey = PUT-YOUR-ADMIN-API-KEY-HERE
    
  3. 以擴展名儲存 .rest 盤案。

  4. 貼上下列範例,以在搜尋服務上建立 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"
                    }
                },
                {
                    "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" }
                        ]
                    }
                }
            ]
        }
    }
    
  5. 選取 [傳送要求]。 回想一下,您需要 REST 用戶端傳送要求。 您應該會有 HTTP/1.1 201 Created 回應。 回應主體應該包含索引架構的 JSON 表示法。

    重點︰

    • 集合 fields 包含文字和向量搜尋所需的索引鍵欄位和文字和向量字段(例如 DescriptionDescriptionVector)。 在同一個索引中共置向量和非向量字段可啟用混合式查詢。 例如,您可以將篩選、文字搜尋與語意排名和向量結合成單一查詢作業。
    • 向量欄位必須是 type: Collection(Edm.Single)dimensionsvectorSearchProfile 屬性。
    • vectorSearch 段是近似鄰近演算法組態和配置檔的陣列。 支持的演算法包括階層式導覽小型世界和詳盡的 K 近鄰。 如需詳細資訊,請參閱 向量搜尋中的相關性評分。
    • [選擇性]:組 semantic 態可重新建立搜尋結果。 您可以針對組態中所指定的字串字段,重新進行類型 semantic 查詢的結果。 若要深入瞭解,請參閱 語意排名概觀

上傳文件

建立和載入索引是個別的步驟。 在 Azure AI 搜尋中,索引包含搜尋服務上執行的所有可搜尋數據和查詢。 針對 REST 呼叫,數據會以 JSON 檔的形式提供。 針對這項工作使用 Documents- Index REST API

URI 會擴充以包含 docs 集合和 index 作業。

重要

下列範例無法執行程序代碼。 為了可讀性,我們排除了向量值,因為每個值都包含 1,536 個內嵌,這對於本文而言太長。 如果您想要嘗試此步驟,請從 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"
            ]
        }
    ]
}

重點︰

  • 承載中的檔是由索引架構中定義的欄位所組成。
  • 向量欄位包含浮點值。 維度屬性的最小值為 2,且每個浮點數上限為 3,072。 本快速入門會將 dimensions 屬性設定為 1,536,因為這是 Open AI 文字 內嵌-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 上的範例複製可執行的程式代碼。

  1. 貼上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個內嵌。

  2. 檢閱回應。 向量對等 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 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."
            }
        ]
    }
    

使用篩選的單一向量搜尋

您可以新增篩選,但篩選條件會套用至索引中的非函式內容。 在此範例中,篩選會套用至 Tags 字段,以篩選出任何不提供免費Wi-Fi的酒店。

  1. 貼上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
            },
        ]
    }
    
  2. 檢閱回應。 此查詢與前一個範例相同,但它包含後置處理排除篩選條件,並只傳回具有免費Wi-Fi的三家酒店。

    {
    
        "@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"
                ]
            }
        ]
    }
    

混合式搜尋是由單一搜尋要求中的關鍵詞查詢和向量查詢所組成。 此範例會同時執行向量查詢和全文搜索:

  • 搜尋字串historic hotel walk to restaurants and shopping
  • 向量查詢字串 (向量化為數學表示法): classic lodging near running trails, eateries, retail
  1. 貼上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 回的結果數目。

  2. 檢閱回應。

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

    因為 RRF 會合併結果,所以有助於檢閱輸入。 下列結果僅來自全文檢索查詢。 前兩名的結果是崇高懸崖酒店和歷史獅子度假村。 崇高懸崖酒店有更強大的BM25相關性分數。

            {
                "@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"
                },
    

    在僅向量查詢中,使用 HNSW 尋找相符專案,Sublime Cliff Hotel 會下降到第四個位置。 歷史獅子,在全文搜索中名列第二,在向量搜尋中名列第三,它不會經歷相同的波動範圍,因此它似乎是同質化結果集中的最高相符專案。

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

使用篩選的語意混合式搜尋

以下是集合中的最後一個查詢。 此具有語意排名的混合式查詢會經過篩選,只顯示位於華盛頓特區 500 公里半徑內的旅館。您可以將 設定 vectorFilterMode 為 null,這相當於預設值 (preFilter 針對較新的索引和 postFilter 較舊的索引)。

  1. 貼上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
            }
        ]
    }
    
  2. 檢閱回應。 回應是三家酒店,依位置和多面向 StateProvince 篩選,並以語意方式重新調整,以提升最接近搜尋字串查詢的結果(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": "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"
                }
            }
        ]
    }
    

    重點︰

    • 向量搜尋是透過 vectors.value 屬性來指定。 關鍵詞搜尋是透過 search 屬性來指定。
    • 在混合式搜尋中,您可以透過關鍵詞整合向量搜尋與全文搜索。 篩選、拼字檢查和語意排名僅適用於文字內容,而非向量。 在此最終查詢中,沒有語意,因為系統不會產生足夠強的語意 answer
    • 實際結果包含更多詳細數據,包括語意 標題 和醒目提示。 結果已修改為可讀性。 若要取得回應的完整結構,請在 REST 用戶端中執行要求。

清理

如果您是在自己的訂用帳戶中進行,建議您在專案結束時判斷自己是否仍需要先前所建立的資源。 資源若繼續執行,將需付費。 您可以個別刪除資源,或刪除資源群組以刪除整組資源。

您可以使用最左邊窗格中的 [ 所有資源 ] 或 [資源群組 ] 連結,在入口網站中找到和管理資源。

您也可以嘗試此指令 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}}

下一步

在下一個步驟中,建議您檢閱 PythonC#JavaScript 的示範程序代碼。