共用方式為


傳回 Azure AI 搜尋服務中的語意答案

叫用語意排名和標題時,您可以選擇從直接「回答」查詢的最相符文件中擷取內容。 回應中可以包含一或多個答案,然後您可以在搜尋頁面上轉譯答案,進而改善應用程式的使用者體驗。

語意答案是搜尋索引中的逐字內容,閱讀理解模型已將其辨識為要求中提出的查詢答案。 這並非產生的答案。 如需使用生成式 AI 從內容撰寫答案的聊天樣式使用者互動模型指引,請參閱擷取擴增生成 (RAG)

在本文中,您會了解如何要求語意答案、解除封裝回應,以及找出哪些內容特性最有利於產生高品質答案。

必要條件

所有適用於語意查詢的必要條件也適用於答案,包括服務層級和區域

  • 查詢邏輯必須包含語意查詢參數 "queryType=semantic" 以及 "answers" 參數。 本文將討論必要參數。

  • 使用者輸入的查詢字串必須是可辨識的問題 (什麼 (what)、哪裡 (where)、何時 (when)、如何 (how))。

  • 索引中的搜尋文件必須包含具有答案特性的文字,而且該文字必須存在於語意設定所列出的其中一個欄位。 例如,假設有個查詢為「什麼是雜湊表」,如果語意設定中沒有任何欄位包含「雜湊表為...」的段落,則不太可能傳回答案。

注意

從 2021-04-30-Preview 開始,在建立或更新索引 (預覽) 要求中,需要 "semanticConfiguration" 才能指定語意排名的輸入欄位。

什麼是語意答案?

語意答案是語意查詢回應的子結構。 語意答案由搜尋文件中的一或多個逐字段落所組成,針對看起來像問題的查詢編寫答案。 若要傳回答案,片語或句子必須存在於具有答案語言特性的搜尋文件中,而且查詢本身必須以問題形式提出。

Azure AI 搜尋服務使用機器閱讀理解模型來辨識及挑選最佳答案。 此模型會從可用內容產生一組可能答案,在達到足夠的信賴等級時,便會從中提出一個建議答案。

答案會作為查詢回應承載中獨立的最上層物件傳回,您可以選擇將其與搜尋結果一同呈現在搜尋頁面上。 在結構方面,其屬於回應中的陣列元素,由文字、文件金鑰和信賴分數所組成。

制訂 "answers" 的 REST 查詢

若要傳回語意答案,查詢必須具有語意 "queryType""queryLanguage""semanticConfiguration""answers" 參數。 指定這些參數並不保證能得到答案,但要求必須包含這些參數,才能處理答案。

{
    "search": "how do clouds form",
    "queryType": "semantic",
    "queryLanguage": "en-us",
    "semanticConfiguration": "my-semantic-config",
    "answers": "extractive|count-3",
    "captions": "extractive|highlight-true",
    "count": "true"
}
  • 查詢字串不得為 null,且應該以問題形式編寫。

  • "queryType" 必須設定為 "semantic。

  • "queryLanguage" 必須是支援語言清單 (REST API) 的其中一個值。

  • "semanticConfiguration" 決定哪些字串欄位會為擷取模型提供權杖。 產生標題列的相同欄位也會產生答案。 如需詳細資訊,請參閱建立語意設定

  • 針對 "answers",參數建構為 "answers": "extractive",其中預設傳回答案數目為一。 如上述範例所示,您可以新增 count,最多增加 10 個答案數目。 您是否需要多個答案,取決於應用程式的使用者體驗,以及轉譯結果的方式。

從回應解除封裝 "answer"

系統會在 "@search.answers" 陣列中提供答案,而陣列會先出現在查詢回應中。 陣列中的每個答案包括:

  • 文件索引鍵
  • 答案的文字或內容,以純文字或格式化呈現
  • 信賴分數

如果答案未確定,則回應會顯示為 "@search.answers": []。 答案陣列後面會接著值陣列,此為語意查詢中的標準回應。

假設查詢「雲端如何形成」,下列範例將說明答案:

{
    "@search.answers": [
        {
            "key": "4123",
            "text": "Sunlight heats the land all day, warming that moist air and causing it to rise high into the   atmosphere until it cools and condenses into water droplets. Clouds generally form where air is ascending (over land in this case),   but not where it is descending (over the river).",
            "highlights": "Sunlight heats the land all day, warming that moist air and causing it to rise high into the   atmosphere until it cools and condenses into water droplets. Clouds generally form<em> where air is ascending</em> (over land in this case),   but not where it is<em> descending</em> (over the river).",
            "score": 0.94639826
        }
    ],
    "value": [
        {
            "@search.score": 0.5479723,
            "@search.rerankerScore": 1.0321671911515296,
            "@search.captions": [
                {
                    "text": "Like all clouds, it forms when the air reaches its dew point—the temperature at which an air mass is cool enough for its water vapor to condense into liquid droplets. This false-color image shows valley fog, which is common in the Pacific Northwest of North America.",
                    "highlights": "Like all<em> clouds</em>, it<em> forms</em> when the air reaches its dew point—the temperature at    which an air mass is cool enough for its water vapor to condense into liquid droplets. This false-color image shows valley<em> fog</em>, which is common in the Pacific Northwest of North America."
                }
            ],
            "title": "Earth Atmosphere",
            "content": "Fog is essentially a cloud lying on the ground. Like all clouds, it forms when the air reaches its dew point—the temperature at  \n\nwhich an air mass is cool enough for its water vapor to condense into liquid droplets.\n\nThis false-color image shows valley fog, which is common in the Pacific Northwest of North America. On clear winter nights, the \n\nground and overlying air cool off rapidly, especially at high elevations. Cold air is denser than warm air, and it sinks down into the \n\nvalleys. The moist air in the valleys gets chilled to its dew point, and fog forms. If undisturbed by winds, such fog may persist for \n\ndays. The Terra satellite captured this image of foggy valleys northeast of Vancouver in February 2010.\n\n\n",
            "locations": [
                "Pacific Northwest",
                "North America",
                "Vancouver"
            ]
        }
    ]
}

設計包含答案的搜尋結果頁面時,請務必處理找不到答案的情況。

在 @search.answers 內:

  • "key" 是相符項目的文件金鑰或識別碼。 假設有文件金鑰,您可以使用查閱文件 API 來擷取搜尋文件的任何或所有部分,以便包含在搜尋頁面或詳細資料頁面中。

  • "text""highlights" 會用純文字和醒目提示提供相同內容。

    根據預設,醒目提示會設定為 <em>,您可以使用現有的 highlightPreTag 和 highlightPostTag 參數加以覆寫。 如其他地方所述,答案的本質是來自於搜尋文件的逐字內容。 擷取模型會尋找答案的特性來尋找適當內容,但不會在回應中撰寫新語言。

  • "score" 是反映答案強度的信賴分數。 如果回應中有多個答案,則會使用此分數決定順序。 最佳答案和最佳標題可以衍生自不同的搜尋文件,最佳答案來自於一份文件,而最佳標題則來自於另一份文件,但一般而言,相同文件會出現在每個陣列的頂端位置。

答案後面接著 "value" 陣列,依據預設一律包含分數、標題,以及可擷取的任何欄位。 若您指定特定參數,則 "value" 陣列僅限於您指定的欄位。 如需詳細資訊,請參閱設定語意排名

產生高品質答案的秘訣

為獲得最佳結果,請在具有下列特性的文件主體傳回語意答案:

  • "semanticConfiguration" 必須包含提供足夠文字的欄位,其中可能找到答案。 更有可能包含答案的欄位應該先列在 "prioritizedContentFields" 中。 只有文件中的逐字文字才能顯示為答案。

  • 查詢字串不得為 null (search= *),且字串應具有問題的特性,例如「什麼是」或「如何」,而不是由任意順序的字詞或片語組成的關鍵字搜尋。 若查詢字串看起來並非問題,則會略過答案處理,即使要求將 "answers" 指定為查詢參數也是如此。

  • 語意擷取和摘要對於每個文件可以及時分析的權杖數目有所限制。 實際上,如果您有多達數百頁的大型文件,請嘗試先將內容分成較小的文件。

下一步