Azure AI 検索のクエリにセマンティック ランク付けを追加する

メモ

Azure AI 検索は、Azure ポータルREST APIおよびAzure SDKから使用できます。 また、Foundry IQ は、エンタープライズ コンテンツを、Microsoft Foundry ポータルのエージェントの再利用可能なアクセス許可に対応したナレッジ ベースに変換するマネージド ナレッジ レイヤーです。

検索ドキュメントに文字列フィールドが含まれており、ベクター クエリに検索ドキュメントに テキスト表現がある場合は 、テキスト クエリ、ハイブリッド クエリ、ベクター クエリにセマンティック ランク付けを適用できます。

この記事では、クエリでセマンティック ランカーを呼び出す方法について説明します。 最新の安定した API またはプレビュー API を使用していることを前提としています。 以前のバージョンのヘルプについては、「 セマンティック ランク付けコードの移行」を参照してください。

前提 条件

メモ

キャプションと回答は、検索ドキュメント内のテキストから逐語的に抽出されます。 セマンティック サブシステムは、機械読解を使用してキャプションまたは回答の特性を持つコンテンツを認識しますが、 クエリの書き換えの場合を除き、新しい文やフレーズは作成しません。 このため、説明や定義を含むコンテンツはセマンティック ランク付けに最適です。 生成された応答とチャット スタイルの対話を行う場合は、「 エージェント検索 または 検索拡張生成 (RAG)」を参照してください。

クライアントを選択する

次のいずれかのツールと SDK を使用して、セマンティック ランク付けを使用するクエリを作成できます。

関連性スコアリングをバイパスする機能を回避する

いくつかのクエリ機能は関連性スコアリングをバイパスするため、セマンティック ランク付けと互換性がありません。 クエリ ロジックに次の機能が含まれている場合、結果を意味的にランク付けすることはできません。

  • search=*または純粋なフィルター専用クエリなどの空の検索文字列を含むクエリは、セマンティック関連性を測定するものがないため、検索スコアが 0 であるため、機能しません。 クエリでは、処理中に評価でき、関連性のスコアが付いた検索ドキュメントを生成する用語または語句を指定する必要があります。 スコア付けされた結果は、セマンティック ランカーへの入力です。

  • 特定のフィールドでの並べ替え (orderBy 句) は、検索スコアとセマンティック スコアを上書きします。 セマンティック スコアがランク付けを提供することになっているため、順序付けされた結果にセマンティック ランク付けを適用すると、orderby 句を追加すると HTTP 400 エラーが発生します。

クエリを設定する

既定では、クエリはセマンティック ランク付けを使用しません。 セマンティック ランク付けを使用するには、2 つの異なるパラメーターを使用できます。 各パラメーターは、異なるクエリ形式のセットをサポートしています。

すべてのセマンティック クエリは、 search plus queryType または semanticQuery を使用して指定する場合でも、プレーン テキストである必要があり、空にすることはできません。 次の表からわかるように、 queryType-semantic パラメーターはクエリ形式のサブセットをサポートしています。

パラメーター プレーンテキスト検索 単純なテキスト検索構文 フルテキスト検索の構文 ベクター検索 ハイブリッド検索 セマンティック回答 とキャプション
queryType-semantic 1
semanticQuery="<your plain text query>" 2

1queryType=semanticsimple パラメーターがfullに使用されているため、明示的なqueryTypeまたはsemantic値をサポートできません。 有効なクエリ動作は、単純なパーサーの既定値です。

2semanticQuery パラメーターは、すべてのクエリの種類に使用できます。 ただし、Azure ポータル Search Explorer ではサポートされていません。

選択したパラメーターに関係なく、インデックスには、豊富なセマンティック コンテンツと セマンティック構成を含むテキスト フィールドが含まれている必要があります。

検索エクスプローラー には、セマンティック ランク付けのオプションが含まれています。 Azure ポータルで semanticQuery パラメーターを設定できないことを思い出してください。

  1. Azure ポータルで検索サービスに移動します。

  2. 検索インデックスを開き、[ 検索エクスプローラー] を選択します。

  3. [クエリ オプション] を選択します。 セマンティック構成を既に定義している場合は、既定で選択されています。 ない場合は、インデックス のセマンティック構成を作成 します。

    検索エクスプローラーのクエリ オプションを示すスクリーンショット。

  4. "良い食べ物を持つ歴史的なホテル" などのクエリを入力し、[ 検索] を選択します。

  5. または、 JSON ビュー を選択し、クエリ エディターに定義を貼り付けます。 Azure ポータルでは semanticQuery の使用がサポートされていないため、queryType"semantic" に設定する必要があります。

    Azure ポータルで JSON クエリ構文を示すスクリーンショット。

    ビューに貼り付けることができるセマンティックにクエリの種類を設定する JSON の例:

    {
      "search": "funky or interesting hotel with good food on site",
      "count": true,
      "queryType": "semantic",
      "semanticConfiguration": "my-semantic-config",
      "captions": "extractive|highlight-true",
      "answers": "extractive|count-3",
      "highlightPreTag": "<strong>",
      "highlightPostTag": "</strong>",
      "select": "HotelId,HotelName,Description,Category"
    }
    

応答を評価する

初期結果からの上位50件のマッチのみが意味的にランク付けされます。 すべてのクエリと同様に、応答は、取得可能としてマークされているすべてのフィールド、または select パラメーターにリストされているフィールドだけで構成されます。 応答には元の関連性スコアが含まれます。また、要求の作成方法によっては、カウントやバッチ処理された結果も含まれる場合があります。

セマンティックランク付けでは、応答には、新しい セマンティックにランク付けされた関連性スコア、プレーンテキストと強調表示を含むオプションのキャプション、オプションの 回答など、より多くの要素があります。 結果にこれらの追加の要素が含まれていない場合は、クエリが正しく構成されていない可能性があります。 問題のトラブルシューティングの最初の手順として、セマンティック構成を確認して、インデックス定義とクエリの両方で指定されていることを確認します。

クライアント アプリでは、検索ページを構造化して、特定のフィールドの内容全体ではなく、キャプションを一致の説明として含めることができます。 この方法は、個々のフィールドが検索結果ページに対して密度が高すぎる場合に便利です。

上記のクエリ例の応答 ("サイトにレストランがあり、居心地の良いロビーまたは共有エリアがある興味深いホテル") は、3 つの回答 ("answers": "extractive|count-e") を返します。 "captions" プロパティが設定され、プレーン テキストと強調表示されたバージョンが設定されているため、キャプションが返されます。 回答が特定できない場合は、応答から省略されます。 簡潔にするために、この例では、3 つの回答とクエリの 3 つの最も高いスコア付け結果のみを示しています。

{
  "@odata.count": 29,
  "@search.answers": [
    {
      "key": "24",
      "text": "Chic hotel near the city. High-rise hotel in downtown, within walking distance to theaters, art galleries, restaurants and shops. Visit Seattle Art Museum by day, and then head over to Benaroya Hall to catch the evening's concert performance.",
      "highlights": "Chic hotel near the city. <strong>High-rise hotel in downtown, </strong>within<strong> walking distance to </strong>theaters, art<strong> galleries, restaurants and shops.</strong> Visit Seattle Art Museum by day, and then head over to Benaroya Hall to catch the evening's concert performance.",
      "score": 0.9340000152587891
    },
    {
      "key": "40",
      "text": "Only 8 miles from Downtown. On-site bar/restaurant, Free hot breakfast buffet, Free wireless internet, All non-smoking hotel. Only 15 miles from airport.",
      "highlights": "Only 8 miles from Downtown. <strong>On-site bar/restaurant, Free hot breakfast buffet, Free wireless internet, </strong>All non-smoking<strong> hotel.</strong> Only 15 miles from airport.",
      "score": 0.9210000038146973
    },
    {
      "key": "38",
      "text": "Nature is Home on the beach. Explore the shore by day, and then come home to our shared living space to relax around a stone fireplace, sip something warm, and explore the library by night. Save up to 30 percent. Valid Now through the end of the year. Restrictions and blackouts may apply.",
      "highlights": "Nature is Home on the beach. Explore the shore by day, and then come home to our<strong> shared living space </strong>to relax around a stone fireplace, sip something warm, and explore the library by night. Save up to 30 percent. Valid Now through the end of the year. Restrictions and blackouts may apply.",
      "score": 0.9200000166893005
    }
  ],
  "value": [
    {
      "@search.score": 3.2328331,
      "@search.rerankerScore": 2.575303316116333,
      "@search.captions": [
        {
          "text": "The best of old town hospitality combined with views of the river and cool breezes off the prairie. Our penthouse suites offer views for miles and the rooftop plaza is open to all guests from sunset to 10 p.m. Enjoy a complimentary continental breakfast in the lobby, and free Wi-Fi throughout the hotel.",
          "highlights": "The best of old town hospitality combined with views of the river and cool breezes off the prairie. Our<strong> penthouse </strong>suites offer views for miles and the rooftop<strong> plaza </strong>is open to all guests from sunset to 10 p.m. Enjoy a<strong> complimentary continental breakfast in the lobby, </strong>and free Wi-Fi<strong> throughout </strong>the hotel."
        }
      ],
      "HotelId": "50",
      "HotelName": "Head Wind Resort",
      "Description": "The best of old town hospitality combined with views of the river and cool breezes off the prairie. Our penthouse suites offer views for miles and the rooftop plaza is open to all guests from sunset to 10 p.m. Enjoy a complimentary continental breakfast in the lobby, and free Wi-Fi throughout the hotel.",
      "Category": "Suite"
    },
    {
      "@search.score": 0.632956,
      "@search.rerankerScore": 2.5425150394439697,
      "@search.captions": [
        {
          "text": "Every stay starts with a warm cookie. Amenities like the Counting Sheep sleep experience, our Wake-up glorious breakfast buffet and spacious workout facilities await.",
          "highlights": "Every stay starts with a warm cookie. Amenities like the<strong> Counting Sheep sleep experience, </strong>our<strong> Wake-up glorious breakfast buffet and spacious workout facilities </strong>await."
        }
      ],
      "HotelId": "34",
      "HotelName": "Lakefront Captain Inn",
      "Description": "Every stay starts with a warm cookie. Amenities like the Counting Sheep sleep experience, our Wake-up glorious breakfast buffet and spacious workout facilities await.",
      "Category": "Budget"
    },
    {
      "@search.score": 3.7076726,
      "@search.rerankerScore": 2.4554927349090576,
      "@search.captions": [
        {
          "text": "Chic hotel near the city. High-rise hotel in downtown, within walking distance to theaters, art galleries, restaurants and shops. Visit Seattle Art Museum by day, and then head over to Benaroya Hall to catch the evening's concert performance.",
          "highlights": "Chic hotel near the city. <strong>High-rise hotel in downtown, </strong>within<strong> walking distance to </strong>theaters, art<strong> galleries, restaurants and shops.</strong> Visit Seattle Art Museum by day, and then head over to Benaroya Hall to catch the evening's concert performance."
        }
      ],
      "HotelId": "24",
      "HotelName": "Uptown Chic Hotel",
      "Description": "Chic hotel near the city. High-rise hotel in downtown, within walking distance to theaters, art galleries, restaurants and shops. Visit Seattle Art Museum by day, and then head over to Benaroya Hall to catch the evening's concert performance.",
      "Category": "Suite"
    },
   . . .
  ]
}

予想されるワークロード

セマンティック ランク付けでは、検索サービスでレプリカあたり最大 10 個の同時クエリがサポートされる必要があります。

ボリュームが大きすぎる場合、サービスはセマンティック ランク付け要求を調整します。 これらの語句を含むエラー メッセージは、サービスがセマンティック ランク付けの容量にあることを示します。

Error in search query: Operation returned an invalid status 'Partial Content'`
@search.semanticPartialResponseReason`
CapacityOverloaded

このレベルの近くまたはそれ以上で一貫したスループット要件が見込まれる場合は、作業負荷に備えてサポートチケットを提出してください。

次の手順

セマンティック ランク付けは、キーワード検索とベクター検索を 1 つの要求と統合された応答に結合するハイブリッド クエリで使用できます。