PAYATHON 2026

Azure CUS 的 Extract Content 如何提取元数据并复用 schema?

AI 小顾

可以复用已有的 schema,不必为每个新建的 analyzer 手工录入一遍字段。添加 knowledge base 并不表示字段定义会自动导入,也不能保证知识库中的所有 metadata 都会随分析结果返回。先确认需要的是自定义业务字段、文件内嵌元数据,还是存储系统里的属性。

knowledge base 与 schema 分别负责什么?

如果这里的 knowledge base 指 Studio 的 Knowledge 页签中配置的示例文档和标注数据,那么它用于 in-context learning,让模型参考示例完成提取。输出哪些业务字段由 schema 决定。官方流程先定义 schema,再添加知识库并检查标注结果。Studio 自定义 analyzer 指南

想提取文档编号、部门等自定义 metadata,需要在 fieldSchema.fields 中配置对应字段。已有字段定义可以复用。

如何复用已有 schema?

可以通过 REST API 读取已有 analyzer,再用其中的 fieldSchema 创建新 analyzer。以下端点使用 2025-11-01 API:

GET {endpoint}/contentunderstanding/analyzers/{existingAnalyzerId}?api-version=2025-11-01

返回的 analyzer 配置包含 fieldSchema。复制时应保留字段类型、描述和字段引用所需的 definitions。Get API 文档

然后将复用的 schema 放入新 analyzer 的创建请求:

PUT {endpoint}/contentunderstanding/analyzers/{newAnalyzerId}?api-version=2025-11-01

以下只展示 schema 配置片段,字段名称仅作示例:

{
  "fieldSchema": {
    "name": "DocumentMetadata",
    "fields": {
      "DocumentId": {
        "type": "string",
        "description": "Document identifier explicitly written in the document."
      },
      "Department": {
        "type": "string",
        "description": "Department explicitly named in the document."
      }
    }
  }
}

完整的创建请求还需要配置适用的 baseAnalyzerId、模型和其他处理选项。不要直接把 GET 返回的整个对象作为请求体,status、createdAt 等响应属性不属于创建配置。创建是异步操作,需要等待完成后再调用分析。Create Or Replace API 文档

以上是在 API 层复用 schema。Studio 是否提供直接导入入口,应以当前界面为准,不能认定所有版本都有相同按钮。外部系统的 JSON Schema 也需要先转换为 Content Understanding 支持的 fieldSchema 结构。

提取结果从哪里读取?

使用新 analyzer 分析目标文档。分析成功后,可以从 result.contents 各项的 fields 中读取自定义字段。以字符串字段为例:

# response 是已经完成且成功的分析结果 JSON
for content in response.get("result", {}).get("contents", []):
    fields = content.get("fields", {})
    document_id = fields.get("DocumentId", {}).get("valueString")
    print(document_id)

字符串字段使用 valueString,其他类型应读取对应的值属性。这段代码读取的是本次输入文档的分析结果,不会批量导出知识库标注数据。分析结果 API 文档

如果 metadata 指文件属性怎么办?

文件内嵌的作者、创建时间和标题等元数据不同于自定义业务字段。官方文档注明,2026-06-01-preview 支持在各 content 对象的 metadata 中返回可提取的文档元数据。可返回的键取决于文件类型及源文件实际包含的信息;没有可用元数据时,该对象可能被省略。不能假定前面的 2025-11-01 示例也支持这一能力。文档元数据说明

如果所需信息是 Blob 自定义 metadata、数据库属性或其他外部记录,应通过相应数据源读取,再与分析结果关联。仅配置 knowledge base,不能据此认定这些外部属性会自动成为提取字段。

备注:内容仅供参考。