注释
某些代理检索功能已在 2026-04-01 REST API 版本中正式发布。 但是,此功能仍为预览版,需要预览版 REST API 版本。 预览版功能在没有服务级别协议的情况下提供,不建议用于生产工作负荷。
重要
这些特性和功能是 2026-05-01 预览版 REST API 的一部分。 2026-05-01-preview 作为Azure订阅的一部分获得许可,并受Microsoft产品条款、Microsoft产品和服务数据保护附录(“DPA”)和Azure预览版补充使用条款的约束。
2026-05-01-preview 支持连接到其他 Microsoft 服务和第三方服务。 使用这些服务受其各自的条款的约束,可能会导致数据处理或存储超出Azure符合性边界,以及流入Azure符合性边界的数据。
您有责任管理您的数据是否会流出您组织的合规和地理边界之外及其任何相关影响,并确保已配置适当的权限、边界和审批。
你负责仔细查看和测试在特定用例上下文中生成的应用程序,并做出所有适当的决策和自定义。 这包括实施自己的负责任的 AI 缓解措施,例如元系统、内容筛选器或其他安全系统,并确保应用程序满足适当的质量、可靠性、安全性和可信度标准。
默认情况下,Azure AI 搜索 中的知识库会执行数据提取操作,该操作会从知识源返回原始的 grounding 文本块。 数据提取可用于检索特定信息,但缺少复杂查询所需的上下文和推理。
可以改为启用 答案合成 (预览),该合成使用知识库中指定的 LLM 以自然语言回答查询。 每个答案包括检索到的源的引文,并遵循提供的任何说明,例如使用项目符号列表。
可以在知识库或检索请求中设置此属性。 知识库设置为所有查询建立默认值,而检索请求设置会基于查询替代默认值。
先决条件
具有指定 LLM 的知识库的 Azure AI 搜索服务。
更新知识库的权限。 使用分配给用户帐户的 Search Service 参与者角色配置 无密钥身份验证或使用 API 密钥。
对于向 LLM 发出的出站调用,搜索服务必须具有托管标识,并在 Microsoft 资源上具有认知服务用户权限。
- 最新的
Azure.Search.Documents预览包:dotnet add package Azure.Search.Documents --prerelease
- 最新的
azure-search-documents预览包:pip install --pre azure-search-documents
- 搜索服务 REST API 的 2026-05-01-preview 版本。
限制和注意事项
-
minimal检索推理功能会禁用 LLM 处理流程,因此在知识库定义和检索请求中都无法与答案生成一起使用。 有关详细信息,请参阅 设置检索推理工作。
在knowledge base中启用答案合成
本部分演示如何在现有知识库中启用答案合成。 尽管可以将此配置用于新的知识库,但knowledge base创建超出了本文的范围。
在OutputMode定义中,将"answerSynthesis"设置为KnowledgeBase。 (可选)设置为 AnswerInstructions 自定义答案输出。 本示例指示知识库Use concise bulleted lists。
Reference:SearchIndexClient、 KnowledgeBase
在output_mode定义中,将"answerSynthesis"设置为KnowledgeBase。 (可选)设置为 answer_instructions 自定义答案输出。 本示例指示知识库Use concise bulleted lists。
Reference:SearchIndexClient、 KnowledgeBase
在知识库定义中,将 outputMode 设置为 "answerSynthesis"。 (可选)设置为 answerInstructions 自定义答案输出。 本示例指示知识库Use concise bulleted lists。
### Enable answer synthesis in a knowledge base
PUT {{search-url}}/knowledgebases/{{knowledge-base-name}}?api-version=2026-05-01-preview
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"
}
参考:知识库 - 创建或更新
在检索请求中启用应答合成
对于对响应格式的按查询控制,可以在查询时启用答案合成。 此方法替代在knowledge base中指定的默认输出模式。
在 OutputMode 上将 "answerSynthesis" 设置为 KnowledgeBaseRetrievalRequest。
var client = new KnowledgeBaseRetrievalClient(
endpoint: new Uri(searchEndpoint),
knowledgeBaseName: knowledgeBaseName,
credential: credential);
var request = new KnowledgeBaseRetrievalRequest();
request.Messages.Add(
new KnowledgeBaseMessage(
content: new[]
{
new KnowledgeBaseMessageTextContent("What is healthcare?")
}) { Role = "user" });
request.OutputMode = "answerSynthesis";
var result = await client.RetrieveAsync(request);
参考:KnowledgeBaseRetrievalClient、 KnowledgeBaseRetrievalRequest
在 output_mode 上将 "answerSynthesis" 设置为 KnowledgeBaseRetrievalRequest。
from azure.search.documents.knowledgebases import KnowledgeBaseRetrievalClient
from azure.search.documents.knowledgebases.models import (
KnowledgeBaseMessage,
KnowledgeBaseMessageTextContent,
KnowledgeBaseRetrievalRequest,
)
agent_client = KnowledgeBaseRetrievalClient(
endpoint=search_endpoint,
credential=credential,
knowledge_base_name=knowledge_base_name,
)
request = KnowledgeBaseRetrievalRequest(
messages=[
KnowledgeBaseMessage(
role="user",
content=[KnowledgeBaseMessageTextContent(text="What is healthcare?")],
)
],
output_mode="answerSynthesis",
)
result = agent_client.retrieve(retrieval_request=request)
参考:KnowledgeBaseRetrievalClient、 KnowledgeBaseRetrievalRequest
在检索请求中将 outputMode 设置为 "answerSynthesis"。
### Enable answer synthesis in a retrieve request
POST {{search-url}}/knowledgebases/{{knowledge-base-name}}/retrieve?api-version=2026-05-01-preview
Content-Type: application/json
api-key: {{api-key}}
{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "What is healthcare?"
}
]
}
],
"outputMode": "answerSynthesis"
}
参考:知识检索 - 检索
获取合成答案
启用答案合成后,知识库会根据你在知识库中指定的说明返回自然语言答案。 对知识源的引文的格式设置为 [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 ..."
}
]
}
]
}
完整 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]."
根据knowledge base的配置,响应可能包含其他信息,例如活动日志和引用数组。 有关详细信息,请参阅 创建 knowledge base。