備註
這項功能目前處於公開預覽狀態。 此預覽版在沒有服務等級協議的情況下提供,不建議用於生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款。
Azure AI Search 的 知識庫 預設會執行 資料擷取,從你的知識來源回傳原始的基礎區塊。 資料擷取有助於擷取特定資訊,但缺乏複雜查詢所需的脈絡與推理。
您也可以啟用「答案合成」功能,該功能會使用您知識庫中指定的大型語言模型以自然語言回應查詢。 每個答案都包含對所擷取來源的引用,並遵循您提供的任何指示,例如使用分項清單。
你可以有兩種方式啟用答案合成:
- 在知識庫上(這會成為所有查詢的預設設定)
- 針對個別擷取要求 (覆寫預設值)
這很重要
minimal擷取推理工作會停用大型語言模型處理,因此在知識庫定義和擷取要求中均與「答案合成」不相容。 欲了解更多資訊,請參閱 設定檢索推理努力。答案合成會產生 Azure OpenAI 的隨用隨付費用,這是以輸入和輸出語彙基元的數目為基礎。 費用會顯示在指派給該知識庫的大型語言模型下。 如需詳細資訊,請參閱 代理程式擷取的可用性和定價。
先決條件
Azure AI 搜尋服務搭配指定 LLM 的知識庫。
若要對 LLM 進行傳出呼叫,搜尋服務必須有具備 Microsoft Foundry 資源上 Cognitive Services User 權限的受控識別。
The 2025-11-01-preview REST API 或等效的 Azure SDK 預覽套件:.NET | Java | JavaScript | Python
在知識庫中啟用答案生成
本節說明如何在現有知識庫中實現答案綜合。 雖然你可以用這種配置來建立新的知識庫,但知識庫的建立超出了本文的範圍。
要在知識庫中啟用答案彙整:
請使用 2025-11-01 預覽版的 知識庫 - 建立或更新(REST API) 來提出請求。
在請求書正文中,設
outputMode為answerSynthesis。(選用) 使用
answerInstructions來自訂答案輸出。 我們的範例指示知識庫為Use concise bulleted lists。
@search-url = <YOUR SEARCH SERVICE URL>
@api-key = <YOUR API KEY>
@knowledge-base-name = <YOUR KNOWLEDGE BASE NAME>
### Enable answer synthesis in a knowledge base
PUT {{search-url}}/knowledgebases/{{knowledge-base-name}}?api-version=2025-11-01-preview HTTP/1.1
Content-Type: application/json
api-key: {{api-key}}
{
"name": "{{knowledge-base-name}}",
"knowledgeSources": [ ... // OMITTED FOR BREVITY ],
"models": [ ... // OMITTED FOR BREVITY ],
"outputMode": "answerSynthesis",
"answerInstructions": "Use concise bulleted lists"
}
備註
此範例假設您使用金鑰型驗證進行本機概念證明測試。 我們建議對生產工作負載進行角色型存取控制。 如需詳細資訊,請參閱使用角色連線到 Azure AI 搜尋服務。
在擷取請求中啟用答案合成
為了在每個查詢時控制回應格式,你可以在查詢時啟用答案綜合。 此方法覆蓋知識庫中指定的預設輸出模式。
要在檢索請求中啟用答案合成:
請使用 2025-11-01 預覽版的 知識檢索 - 擷取(REST API) 來表達請求。
在請求書正文中,設
outputMode為answerSynthesis。
@search-url = <YOUR SEARCH SERVICE URL>
@api-key = <YOUR API KEY>
@knowledge-base-name = <YOUR KNOWLEDGE BASE NAME>
### Enable answer synthesis in a retrieve request
POST {{search-url}}/knowledgebases/{{knowledge-base-name}}/retrieve?api-version=2025-11-01-preview HTTP/1.1
Content-Type: application/json
api-key: {{api-key}}
{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is healthcare?"
}
]
}
],
"outputMode": "answerSynthesis"
}
備註
此範例假設您使用金鑰型驗證進行本機概念證明測試。 我們建議對生產工作負載進行角色型存取控制。 如需詳細資訊,請參閱使用角色連線到 Azure AI 搜尋服務。
取得綜合答案
當啟用答案綜合時, 知識檢索 - 擷取(REST API) 會根據你在知識庫中選擇性指定的指令,回傳一個自然語言的答案。 你的知識來源引用格式為 [ref_id:<number>]。
例如,如果您的指示是 Use concise bulleted lists 且查詢是 What is healthcare?,則回應可能如下所示:
{
"response": [
{
"content": [
{
"type": "text",
"text": "- Healthcare encompasses various services provided to patients and the general population ... // TRIMMED FOR BREVITY"
}
]
}
]
}
完整 text 輸出如下:
"- Healthcare encompasses various services provided to patients and the general population, including primary health services, hospital care, dental care, mental health services, and alternative health services [ref_id:1].\n- It involves the delivery of safe, effective, patient-centered care through different modalities, such as in-person encounters, shared medical appointments, and group education sessions [ref_id:0].\n- Behavioral health is a significant aspect of healthcare, focusing on the connection between behavior and overall health, including mental health and substance use [ref_id:2].\n- The healthcare system aims to ensure quality of care, access to providers, and accountability for positive outcomes while managing costs effectively [ref_id:2].\n- The global health system is evolving to address complex health needs, emphasizing the importance of cross-sectoral collaboration and addressing social determinants of health [ref_id:4]."
根據你的知識庫設定,回應可能包含其他資訊,例如活動日誌和參考陣列。 欲了解更多資訊,請參閱 建立知識庫。