クイックスタート: REST を使用したベクトル検索

Search REST API を使用して、Azure AI 検索でクエリ ベクトルの作成、読み込み、クエリを行う方法について説明します。

Azure AI 検索において、"ベクトル ストア" には、ベクトル フィールドと非ベクトル フィールドを定義するインデックス スキーマ、埋め込み空間を作成するアルゴリズムのベクトル構成、およびクエリ要求で使用されるベクトル フィールド定義の設定が含まれています。 Create Index API によってベクトル ストアが作成されます。

Azure サブスクリプションをお持ちでない場合は、開始する前に 無料アカウント を作成してください。

Note

安定した 2023-11-01 REST API バージョンは、データのチャンキングと埋め込みに関して外部モジュールに依存します。 組み込みのデータのチャンキングとベクトル化 (パブリック プレビュー) 機能を評価したい場合は、[データのインポートとベクトル化] ウィザードのエンド ツー エンドのチュートリアルを試してください。

前提条件

  • REST クライアントを使用する Visual Studio Code。 開始するための支援が必要な場合は、「クイック スタート: REST を使用したテキスト検索」を参照してください。

  • 任意のリージョンおよび任意のレベルの Azure AI Search。 このクイックスタートでは Free レベルを使用できますが、大規模なデータ ファイルには Basic 以上をお勧めします。 現在のサブスクリプションで、既存の Azure AI 検索サービスを見つけるか、または作成します。

    既存のサービスのほとんどではベクトル検索がサポートされています。 2019 年 1 月より前に作成されたサービスの小さなサブセットでは、ベクトル フィールドを含むインデックスの作成に失敗します。 このような場合は、新しいサービスを作成する必要があります。

  • オプションで、セマンティック ランク付けを呼び出すクエリ例を実行するには、検索サービスは Basic レベル以上であり、セマンティック ランク付けが有効である必要があります。

  • 必要に応じて、text-embedding-ada-002 のデプロイを含む Azure OpenAI リソース。 このソース .rest ファイルには、新しいテキスト埋め込みを生成するためのオプションの手順が含まれていますが、この依存関係を省略できるように事前に生成した埋め込みを用意しています。

ファイルのダウンロード

GitHub から REST サンプルをダウンロードして、このクイックスタートの要求を送信します。 詳細については、「GitHub からファイルをダウンロードする」を参照してください。

ローカル システムで新しいファイルを開始し、この記事の手順を使用して手動で要求を作成することもできます。

検索サービス キーと URL をコピーする

REST 呼び出しでは、すべての要求で検索サービス エンドポイントと API キーが必要です。 これらの値は Azure portal から取得できます。

  1. Azure portal にサインインします。 [概要] ページに移動して、URL をコピーします。 たとえば、エンドポイントは https://mydemo.search.windows.net のようになります。

  2. [設定]>[キー] を選択して、管理者キーをコピーします。 管理者キーは、オブジェクトの追加、変更、削除で使用します。 2 つの交換可能な管理者キーがあります。 どちらかをコピーします。

    Azure portal の URL および API キーを示すスクリーンショット。

ベクトル インデックスを作成する

[インデックスの作成 (REST)] ではベクトル インデックスを作成し、検索サービスに物理データ構造を設定します。

インデックス スキーマは、ホテルのコンテンツを中心に整理されています。 サンプル データは、7 つの架空のホテルのベクトルおよび非ベクトルの名前および説明で構成されています。 このスキーマには、ベクトル インデックス作成およびクエリとセマンティック ランク付けのための構成が含まれています。

  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 など) が含まれています。 ベクトル フィールドと非ベクトル フィールドを同じインデックスに配置すると、ハイブリッド クエリが有効になります。 たとえば、フィルター、セマンティック ランク付けを使用したテキスト検索、およびベクトルを 1 つのクエリ操作に結合できます。
    • ベクトル フィールドは、dimensions および vectorSearchProfile プロパティを含む type: Collection(Edm.Single) である必要があります。
    • vectorSearch セクションは、近似最近傍アルゴリズムの構成とプロファイルの配列です。 サポートされているアルゴリズムは、階層ナビゲーション可能な小さい世界 (hierarchical navigable small world) と網羅的 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 個の浮動小数点値があります。 このクイックスタートでは、ディメンション属性を 1,536 に設定します。これは、Open AI の text-embedding-ada-002 モデルによって生成される埋め込みのサイズであるためです。

クエリを実行する

これでドキュメントが読み込まれたので、Documents - Search Post (REST) を使用して、それらに対してベクトル クエリを発行できます。

さまざまなパターンを示すクエリがいくつかあります:

このセクションのベクトル クエリは、次の 2 つの文字列に基づいています。

  • 検索文字列: historic hotel walk to restaurants and shopping
  • ベクトル クエリ文字列 (数学的表現にベクトル化): classic lodging near running trails, eateries, retail

このベクトル クエリ文字列は、意味的には検索文字列に似ていますが、検索インデックスに存在しない用語を含んでいます。 classic lodging near running trails, eateries, retail のキーワード検索を実行すると、結果は 0 になります。 この例を使用して、一致する言葉がない場合でも関連する結果を取得する方法を示します。

重要

次の例は実行可能なコードではありません。 読みやすくするために、ベクトル値は除外しています。各配列には 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 に相当するベクトルの応答には、7 つの結果が含まれます。 各結果には、検索スコアと、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 を備えた 3 つのホテルのみが返されます。

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

    これはハイブリッド クエリであるため、結果は Reciprocal Rank Fusion (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 では結果をマージするので、入力の確認に役立ちます。 次の結果は、フル テキスト クエリのみからのものです。 上位 2 つの結果は、Sublime Cliff Hotel と History Lion Resort です。 Sublime Cliff Hotel の 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 は 4 位に下がります。 Historic Lion の場合、フル テキスト検索では 2 位、ベクトル検索では 3 位でしたが、変動範囲が同じでないため、均質化された結果セットでは最上位の一致として表示されます。

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

フィルターを使用したセマンティック ハイブリッド検索

ここでは、コレクションでの最後のクエリを示します。 セマンティック ランク付けを行うこのハイブリッド クエリは、ワシントン D.C. の半径 500 キロメートル以内のホテルのみを表示するようにフィルター処理されます。vectorFilterMode は、既定値 (新しいインデックスでは preFilter、古いものでは postFilter) に相当する null に設定できます。

  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. 応答を確認します。 応答は 3 つのホテルとなり、場所でフィルター処理され、StateProvince によってファセットが適用され、意味的に再ランク付けされて、結果が昇格し、検索文字列クエリ (historic hotel walk to restaurants and shopping) に最も近くなります。

    ここで、Old Carabelle Hotel が 1 位に移動します。 セマンティック ランク付けを行わない場合、Nordick's Hotel が 1 位です。 セマンティック ランク付けを行う場合、機械読解モデルでは、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 のデモ コードを確認することをお勧めします。