在 Azure AI 搜尋中傳回語意答案

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

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

在本文中,瞭解如何要求語意答案、解壓縮回應,並找出最有利於產生高品質答案的內容特性。

必要條件

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

  • 查詢邏輯必須包含語意查詢參數 「queryType=semantic」,加上 「answers」 參數。 本文將討論必要的參數。

  • 使用者輸入的查詢字串必須可辨識為問題(何者、位置、時機、方式)。

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

注意

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

什麼是語意答案?

語意答案是語意查詢回應子結構。 它是由搜尋檔中的一或多個逐字段落所組成,這些段落是查詢的解答,看起來像是問題。 若要傳回答案,片語或句子必須存在於具有答案語言特性的搜尋檔中,而且查詢本身必須提出為問題。

Azure AI 搜尋會使用機器閱讀理解模型來辨識並挑選最佳答案。 模型會從可用的內容產生一組潛在的答案,當它達到足夠的信賴等級時,它會建議一個作為答案。

答案會在查詢響應承載中以獨立的最上層物件的形式傳回,您可以選擇在搜尋頁面上轉譯,並存搜尋結果。 在結構上,它是回應中的陣列元素,其中包含文字、檔索引鍵和信賴分數。

為「答案」制定 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 個。 您是否需要一個以上的答案取決於應用程式的用戶體驗,以及您想要轉譯結果的方式。

從回應解除包裝「答案」

陣列中 "@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 參數來覆寫。 如其他地方所述,答案的實質內容是搜尋檔中的逐字內容。 擷取模型會尋找答案的特性來尋找適當的內容,但不會在回應中撰寫新語言。

  • 「分數」 是反映答案強度的信心分數。 如果回應中有多個答案,則會使用此分數來判斷順序。 最上層的答案和最上層 標題 可以衍生自不同的搜尋檔,其中最上層的答案來自一份檔,而頂端的 標題 則來自另一份檔,但一般而言,相同的檔會出現在每個數位的頂端位置。

答案後面接著 「value」 陣列,此陣列一律包含分數、標題,以及預設可擷取的任何字段。 如果您指定 select 參數,“value” 陣列會限制為您指定的欄位。 如需詳細資訊,請參閱 設定語意排名

用於產生高品質答案的 提示

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

  • “semanticConfiguration” 必須包含提供可能找到答案之足夠文字的欄位。 較可能包含答案的欄位應該先列在 “prioritizedContentFields” 中。 只有檔中的逐字文字可以顯示為答案。

  • 查詢字串不得為 Null(search=*),字串應該具有問題的特性,例如「什麼是」或「如何」,而不是以任意順序包含字詞或片語的關鍵詞搜尋。 如果查詢字串似乎不是問題,即使要求將「答案」指定為查詢參數,也會略過答案處理。

  • 語意擷取和摘要限制可及時分析每個檔的令牌數量。 實際上,如果您有數百頁的大型檔,請先嘗試將內容分成較小的檔。

下一步