你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

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

注释

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

默认情况下,Azure AI 搜索中的 知识代理 执行 数据提取,该提取从知识源返回原始地面区块。 数据提取对于检索特定信息很有用,但它缺少复杂查询所需的上下文和推理。

可以将代理配置为执行 答案合成,该合成使用部署的聊天完成模型以自然语言响应查询。 每个答案包括检索到的源的引文,并遵循提供的任何说明,例如使用项目符号列表。

本文介绍如何为现有代理配置和测试答案合成。 尽管可以将此配置用于新代理,但代理创建超出了本文的范围。

重要

答案合成会产生 Azure OpenAI 的即用即付费用,该费用基于输入和输出令牌的数量。 费用显示在分配给代理的聊天完成模型中。 有关详细信息,请参阅 代理检索的可用性和定价

先决条件

  • 使用 2025-08-01-preview 语法的知识代理,它需要 knowledgeSources 而不是 targetIndexes

  • 具有 REST 客户端扩展Visual Studio Code 或提供知识代理 REST API 的 Azure SDK 的预发行版包。 目前,没有门户支持。

配置答案合成

若要为知识代理配置答案合成,请使用知识代理的 2025-08-01-preview - 创建或更新(REST API)。

outputConfiguration 部分中:

  1. modality 设置为 answerSynthesis

  2. (可选)用于 answerInstructions 自定义答案输出。 我们的示例指示代理 Use concise bulleted lists

@search-url = <YourSearchServiceUrl>
@agent-name = <YourAgentName>
@api-key = <YourApiKey>

### Configure answer synthesis
PUT https://{{search-url}}/knowledgeAgents/{{agent-name}}?api-version=2025-08-01-preview  HTTP/1.1
    Content-Type: application/json
    api-key: {{api-key}}

    {
        "name": "{{agent-name}}",
        "models": [
            ... // Redacted for brevity
        ],
        "knowledgeSources": [
            ... // Redacted for brevity
        ],
        "outputConfiguration": {
            "modality": "answerSynthesis",
            "answerInstructions": "Use concise bulleted lists"
        }
    }

重要

此示例假定你使用基于密钥的身份验证进行本地概念证明测试。 建议对生产工作负荷使用基于角色的访问控制。 有关详细信息,请参阅使用角色连接到 Azure AI 搜索

获取合成答案

为知识代理配置答案合成后,请使用 2025-08-01-preview of Knowledge Retrieve - Retrieve (REST API) 测试其输出。

### Send a query to the agent
POST https://{{search-url}}/agents/{{agent-name}}/retrieve?api-version=2025-08-01-preview  HTTP/1.1
    Content-Type: application/json
    api-key: {{api-key}}
        
    {
      "messages": [
            {
                "role": "user",
                "content" : [
                    {
                        "text": "<YourQueryText>",
                        "type": "text"
                    }
                ]
            }
        ]
    }

响应应包含基于说明的自然语言答案,其中对知识源的引文格式为 [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
        }
      ]
    }
  ],
  ... // Redacted 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]."

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