다음을 통해 공유

在 Azure AI 搜索中对引文支持的响应使用答案合成

注释

此功能目前处于公开预览状态。 此预览版未随附服务级别协议,建议不要用于生产工作负载。 某些功能可能不受支持或者受限。 有关详细信息,请参阅适用于 Azure 预览版的补充使用条款

默认情况下,Azure AI 搜索中的 知识库 执行 数据提取,该过程从知识源返回原始的基础数据块。 数据提取可用于检索特定信息,但缺少复杂查询所需的上下文和推理。

可以改为启用 答案合成,该合成使用知识库中指定的 LLM 以自然语言回答查询。 每个答案包括检索到的源的引文,并遵循提供的任何说明,例如使用项目符号列表。

可以通过两种方式启用答案合成:

  • 在知识库上(成为所有查询的默认值)
  • 在单个检索请求上(替代默认值)

重要

  • minimal检索推理工作会禁用 LLM 处理,因此它与知识库定义和检索请求中的答案合成不兼容。 有关详细信息,请参阅 设置检索推理工作

  • 答案合成会产生 Azure OpenAI 的标准预付费套餐费用,该费用基于输入和输出令牌的数量。 费用显示在分配给知识库的 LLM 下。 有关详细信息,请参阅 代理检索的可用性和定价

先决条件

注释

尽管可以使用 Azure 门户配置答案合成,但门户使用 2025-08-01-preview,该预览版使用以前的“知识代理”术语,并且不支持所有 2025-11-01-preview 功能。 如需中断性变更方面的帮助,请参阅迁移智能体检索代码

在知识库上启用答案合成

本部分介绍如何对现有知识库启用答案合成。 尽管可以将此配置用于新的知识库,但知识库创建超出了本文的范围。

若要对知识库启用答案合成,请:

  1. 使用 2025-11-01-preview 的知识库 - 创建或更新(REST API)来制定请求。

  2. 在请求正文中,将outputMode设置为answerSynthesis.

  3. (可选)用于 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 on 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 搜索

对检索请求启用应答合成

对于对响应格式的按查询控制,可以在查询时启用答案合成。 此方法替代知识库中指定的默认输出模式。

若要对检索请求启用应答合成,请执行以下作:

  1. 使用 2025-11-01 预览版 知识检索 - 检索(REST API) 来生成请求。

  2. 在请求正文中,将outputMode设置为answerSynthesis.

@search-url = <YOUR SEARCH SERVICE URL>
@api-key = <YOUR API KEY>
@knowledge-base-name = <YOUR KNOWLEDGE BASE NAME>

### Enable answer synthesis on a retrieval 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]."

根据知识库的配置,响应可能包含其他信息,例如活动日志和引用数组。 有关详细信息,请参阅 创建知识库