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

使用Azure内容理解技能对内容进行区块和矢量化

注释

Foundry IQ (Azure AI 搜索) 提供直接索引和查询 API 以及用于托管检索的高级知识库和知识库 API。 使用 Azure 门户、REST API 或Azure SDK配置这些功能,或将代理连接到 Microsoft Foundry 门户中的知识库。

Important

这些特性和功能支持与其他Microsoft 服务和第三方服务的连接。 使用这些服务受其各自的条款的约束,可能会导致数据处理或存储超出Azure符合性边界,以及流入Azure符合性边界的数据。

您有责任管理您的数据是否会流出您组织的合规和地理边界之外及其任何相关影响,并确保已配置适当的权限、边界和审批。

你负责仔细查看和测试在特定用例上下文中生成的应用程序,并做出所有适当的决策和自定义。 这包括实施自己的负责任的 AI 缓解措施,例如元系统、内容筛选器或其他安全系统,并确保应用程序满足适当的质量、可靠性、安全性和可信度标准。 有关更多信息,请参阅Foundry IQ(Azure AI 搜索)透明度说明。

在本文中,使用Azure内容理解技能生成索引管道,以便:

  • 从文档中提取文本和图像
  • 生成遵循段落和节边界的语义上一致的区块
  • 可选择为图表、示意图和其他内联图像生成 AI 描述
  • 为每个区块嵌入矢量搜索,并将其投影到 Foundry IQ 索引中

Azure内容理解技能返回每个文档的一个或多个区块。 每个区块都包含 Markdown 格式的内容、位置元数据(页码和边界多边形),以及对提取的图像的可选引用。 当您将 chunkingProperties.method 设置为 semantic 时,分块将按照段落和标题边界进行划分,而不是按固定字符长度划分。 当你设置 modelName 和 modelDeployment 时,该技能会调用 Azure OpenAI 聊天补全部署,以生成内嵌图像的描述。 然后,技能将这些说明合并到区块内容中。

语义分块和图像描述通常可在 Search REST API 2026-10-01 中找到,本教程全部使用该版本。 此可用性独立于 技能调用的内容理解 API。

本文使用 Blob 存储中的运行状况计划示例 PDF。 有关SharePoint文档,请参阅 Foundry IQ 中的提取和扩充SharePoint文档。 请勿将本演练的可选映像存储步骤应用于受权限保护的内容。 若要了解详细信息,请参阅 SharePoint ACL 限制。

先决条件

内容理解不支持Azure API 管理(APIM)终结点。

对于每个 HTTP 请求,请将 {endpoint} 替换为 https://<search-service>.search.windows.net,并将 <access-token> 替换为 Foundry IQ 服务的令牌。 将 Foundry 资源和模型部署占位符替换为自己的值。 <MODEL_NAME> 是可选说明模型; <EMBEDDING_MODEL_NAME> 是嵌入模型,而不是其部署名称。

在嵌入技能与查询时向量器中使用相同的嵌入资源终结点、部署和模型。 这些示例使用 Foundry 资源终结点(https://<resource>.services.ai.azure.com),而不是项目 URL。

Overview

本文构建了一个一对多的索引流水线。 每个源文档生成多个搜索文档(每个区块一个):

  1. 索引器从Azure Blob 存储读取每个文件,并通过 /document/file_data 将二进制内容传递给技能组。

  2. Azure内容理解技能使用语义分块生成text_sections。 设置这modelDeployment两者modelName时,技能还会生成嵌入图像说明,并将其内联到区块的 Markdown 中。

  3. Azure OpenAI 嵌入技能每个区块运行一次,并为区块内容生成矢量。

  4. 索引投影会将每个区块写入为目标索引中的一份搜索文档,并将内容、页面元数据、图像引用和向量映射到各个字段。

  5. (可选)知识存储将normalized_images投影到 Azure Blob 存储,以便客户端应用可以通过 URL 检索提取的图像。

准备数据文件

Azure内容理解技能处理每个文档的二进制内容,因此源文件必须采用技能支持的格式。 有关当前列表,请参阅 内容理解服务限制。 常见的支持格式包括 PDF、DOCX、XLSX、PPTX 和许多图像格式。

将文件上传到Blob 存储容器。 可以使用Azure门户、REST API 或Azure SDK创建数据源。

以下最小请求创建在本演练中使用的数据源。

POST {endpoint}/datasources?api-version=2026-10-01
Authorization: Bearer <access-token>
Content-Type: application/json

{
  "name": "my_blob_datasource",
  "type": "azureblob",
  "credentials": {
    "connectionString": "<your-blob-connection-string>"
  },
  "container": {
    "name": "my-container"
  }
}

为一对多索引编制创建索引

每个搜索文档对应于内容理解技能生成的一个区块。 索引需要:

  • 关键字段(chunk_id)。
  • 一个父字段,用于标识区块来自的源文档(parent_id)。
  • 存储区块内容、页面元数据和图像引用的字段。
  • 用于分块嵌入的向量字段。

以下索引定义与在下一部分中创建的技能集匹配。

PUT {endpoint}/indexes/my_content_understanding_index?api-version=2026-10-01
Authorization: Bearer <access-token>
Content-Type: application/json

{
  "name": "my_content_understanding_index",
  "fields": [
    {
      "name": "chunk_id",
      "type": "Edm.String",
      "key": true,
      "searchable": true,
      "filterable": false,
      "retrievable": true,
      "stored": true,
      "sortable": true,
      "facetable": false,
      "analyzer": "keyword"
    },
    {
      "name": "parent_id",
      "type": "Edm.String",
      "searchable": false,
      "filterable": true,
      "retrievable": true,
      "stored": true,
      "sortable": false,
      "facetable": false
    },
    {
      "name": "title",
      "type": "Edm.String",
      "searchable": true,
      "filterable": false,
      "retrievable": true,
      "stored": true,
      "sortable": false,
      "facetable": false
    },
    {
      "name": "chunk",
      "type": "Edm.String",
      "searchable": true,
      "filterable": false,
      "retrievable": true,
      "stored": true,
      "sortable": false,
      "facetable": false
    },
    {
      "name": "page_number_from",
      "type": "Edm.Int32",
      "searchable": false,
      "filterable": true,
      "retrievable": true,
      "stored": true,
      "sortable": true,
      "facetable": false
    },
    {
      "name": "page_number_to",
      "type": "Edm.Int32",
      "searchable": false,
      "filterable": true,
      "retrievable": true,
      "stored": true,
      "sortable": true,
      "facetable": false
    },
    {
      "name": "image_path",
      "type": "Edm.String",
      "searchable": false,
      "filterable": false,
      "retrievable": true,
      "stored": true,
      "sortable": false,
      "facetable": false
    },
    {
      "name": "text_vector",
      "type": "Collection(Edm.Single)",
      "searchable": true,
      "retrievable": false,
      "stored": false,
      "dimensions": 1536,
      "vectorSearchProfile": "profile"
    }
  ],
  "semantic": {
    "defaultConfiguration": "semantic-config",
    "configurations": [
      {
        "name": "semantic-config",
        "prioritizedFields": {
          "titleField": {"fieldName": "title"},
          "prioritizedContentFields": [{"fieldName": "chunk"}]
        }
      }
    ]
  },
  "vectorSearch": {
    "profiles": [
      {
        "name": "profile",
        "algorithm": "algorithm",
        "vectorizer": "query-vectorizer"
      }
    ],
    "algorithms": [
      {
        "name": "algorithm",
        "kind": "hnsw"
      }
    ],
    "vectorizers": [
      {
        "name": "query-vectorizer",
        "kind": "azureOpenAI",
        "azureOpenAIParameters": {
          "resourceUri": "https://<embedding-resource>.services.ai.azure.com",
          "deploymentId": "<embedding-deployment>",
          "modelName": "<EMBEDDING_MODEL_NAME>"
        }
      }
    ]
  }
}

定义语义分块和矢量化的技能集

有了目标索引后,定义一个技能组,用于生成输入该索引的块、矢量和投影映射。

技能组有两种技能:

  • Azure 内容理解技能将每个文档分块。 将chunkingProperties.method设置为semantic可遵循段落和标题边界。 在矢量化之前,单独设置这两个模型属性可启用图像说明。 有关支持的值,请参阅 Skill 参数。

  • Azure OpenAI 嵌入技能为每个区块的内容生成矢量。

该技能集使用 indexProjections 将每个内容块映射到单独的搜索文档中。 有关详细信息,请参阅定义索引投影。

该请求使用 Foundry IQ 服务的系统分配托管标识进行 Foundry 和嵌入访问。 Blob 连接字符串示例是独立的;对于无密钥源连接,请使用 数据源的托管标识。

以下示例包含图像说明。 如果跳过可选说明部署,请使用 计费和映像说明控件 在提交技能集之前删除其配置。 在运行管道之前查看适用的费用。

POST {endpoint}/skillsets?api-version=2026-10-01
Authorization: Bearer <access-token>
Content-Type: application/json

{
  "name": "my_content_understanding_skillset",
  "description": "Semantic chunking, image descriptions, and vectorization with the Azure Content Understanding skill",
  "skills": [
    {
      "@odata.type": "#Microsoft.Skills.Util.ContentUnderstandingSkill",
      "name": "my_content_understanding_skill",
      "context": "/document",
      "modelName": "<MODEL_NAME>",
      "modelDeployment": "<chat-deployment>",
      "chunkingProperties": {
        "method": "semantic",
        "unit": "tokens",
        "maximumLength": 500
      },
      "extractionOptions": ["images", "locationMetadata"],
      "inputs": [
        {
          "name": "file_data",
          "source": "/document/file_data"
        }
      ],
      "outputs": [
        {
          "name": "text_sections",
          "targetName": "text_sections"
        },
        {
          "name": "normalized_images",
          "targetName": "normalized_images"
        }
      ]
    },
    {
      "@odata.type": "#Microsoft.Skills.Text.AzureOpenAIEmbeddingSkill",
      "name": "my_azure_openai_embedding_skill",
      "context": "/document/text_sections/*",
      "inputs": [
        {
          "name": "text",
          "source": "/document/text_sections/*/content"
        }
      ],
      "outputs": [
        {
          "name": "embedding",
          "targetName": "text_vector"
        }
      ],
      "resourceUri": "https://<embedding-resource>.services.ai.azure.com",
      "deploymentId": "<embedding-deployment>",
      "modelName": "<EMBEDDING_MODEL_NAME>",
      "dimensions": 1536
    }
  ],
  "cognitiveServices": {
    "@odata.type": "#Microsoft.Azure.Search.AIServicesByIdentity",
    "subdomainUrl": "https://<foundry-resource>.services.ai.azure.com",
    "identity": null
  },
  "indexProjections": {
    "selectors": [
      {
        "targetIndexName": "my_content_understanding_index",
        "parentKeyFieldName": "parent_id",
        "sourceContext": "/document/text_sections/*",
        "mappings": [
          {
            "name": "chunk",
            "source": "/document/text_sections/*/content"
          },
          {
            "name": "text_vector",
            "source": "/document/text_sections/*/text_vector"
          },
          {
            "name": "page_number_from",
            "source": "/document/text_sections/*/locationMetadata/pageNumberFrom"
          },
          {
            "name": "page_number_to",
            "source": "/document/text_sections/*/locationMetadata/pageNumberTo"
          },
          {
            "name": "image_path",
            "source": "/document/text_sections/*/imagePath"
          },
          {
            "name": "title",
            "source": "/document/metadata_storage_name"
          }
        ]
      }
    ],
    "parameters": {
      "projectionMode": "skipIndexingParentDocuments"
    }
  }
}

有关内容理解技能的完整参数引用、支持的值和验证规则,请参阅Azure内容理解技能。

选择分块和说明选项

分块、图像提取和图像说明是独立的选择。 有关说明配置,请使用 规范说明控件。

对于固定大小的区块,请将内容理解技能的 chunkingProperties 替换为 {"method": "fixedSize", "unit": "characters", "maximumLength": 1325, "overlapLength": 0}。 有关允许的范围和重叠规则,请参阅 chunkingProperties。

配置和运行索引器

创建并运行一个索引器,使其从数据源读取数据、调用技能集,并将分块投射到索引中。 将 allowSkillsetToReadFileData 设置为 true,以便内容理解技能接收文件内容,并将 parsingMode 设置为 default。

在这种情况下,你不需要 outputFieldMappings。 技能组中的 indexProjections 块已将每个块映射到目标索引字段。

POST {endpoint}/indexers?api-version=2026-10-01
Authorization: Bearer <access-token>
Content-Type: application/json

{
  "name": "my_content_understanding_indexer",
  "dataSourceName": "my_blob_datasource",
  "targetIndexName": "my_content_understanding_index",
  "skillsetName": "my_content_understanding_skillset",
  "parameters": {
    "batchSize": 1,
    "configuration": {
      "dataToExtract": "contentAndMetadata",
      "parsingMode": "default",
      "allowSkillsetToReadFileData": true
    }
  },
  "fieldMappings": [],
  "outputFieldMappings": []
}

索引器运行时,内容理解技能会分块文件,并选择性地生成说明。 索引投影为每个区块写入一个搜索文档。 如果更新现有索引器,并且需要将该管道应用于之前索引的文件,请重置并运行该索引器。 如果不先重置而直接运行,则只会处理新的或已更改的文件。

检查索引器状态

在查询之前,请确认索引器运行已完成:

GET {endpoint}/indexers/my_content_understanding_indexer/status?api-version=2026-10-01
Authorization: Bearer <access-token>

检查 lastResult.status、 itemsProcessed、 itemsFailed、 errors和 warnings。 检查代表性区块并调查缺少的文档,即使处理计数为非零。 有关详细信息,请参阅 监视器索引器状态。

验证结果

查询索引以验证区块是否包含预期内容,以及矢量搜索是否按预期工作。 使用 搜索资源管理器 或任何发送 HTTP 请求的工具。

以下请求运行混合查询:关键字 chunk 搜索和针对 text_vector的向量查询。 查询时向量器使用配置的嵌入部署嵌入查询文本。

POST {endpoint}/indexes/my_content_understanding_index/docs/search?api-version=2026-10-01
Authorization: Bearer <access-token>
Content-Type: application/json

{
  "search": "copay for in-network providers",
  "searchFields": "chunk",
  "count": true,
  "searchMode": "all",
  "vectorQueries": [
    {
      "kind": "text",
      "text": "copay for in-network providers",
      "fields": "text_vector"
    }
  ],
  "select": "chunk, title, page_number_from, page_number_to, image_path"
}

响应包含带有所选字段的 value 条目。 检查区块内容和页面关联。 如需单独验证矢量检索,请重新发起请求,移除 search、searchFields 和 searchMode,保留 vectorQueries。 仅依靠混合结果,无法证明矢量检索已成功执行。

以下响应结构是一个示例,而不是从实时运行捕获的输出;区块边界、文本、计数和分数各不相同:

{
  "@odata.count": 2,
  "value": [
    {
      "@search.score": 0.0317,
      "chunk": "## Cost sharing\n\nFor in-network providers, the copay is $20 per visit...\n\n![Chart: Copay comparison across plans](figures/3)",
      "title": "Northwind_Standard_Benefits_Details.pdf",
      "page_number_from": 4,
      "page_number_to": 4,
      "image_path": "figures/3"
    },
    {
      "@search.score": 0.0289,
      "chunk": "### Out-of-network providers\n\nWhen you visit a provider that isn't in the Northwind network, the copay is $40 per visit...",
      "title": "Northwind_Standard_Benefits_Details.pdf",
      "page_number_from": 5,
      "page_number_to": 6,
      "image_path": null
    }
  ]
}

响应包括:

  • chunk:每个区块的 Markdown 内容。 当你在内容理解技能上配置这两个模型属性时,生成的图像描述将随适用的图形内联显示。
  • page_number_from 和 page_number_to:生成区块的页面范围。
  • image_path:使用区块提取的图像的路径,或者,当区块跨越多个图像时,路径的分号分隔列表。 确切的形状取决于是否配置了知识存储文件投影。 如果没有文件投影,路径是示例(figures/3)中显示的短格式。 使用文件投影时,路径是知识存储中图像的相对路径。 若要使这些映像可供客户端应用使用,请参阅 (可选)用于检索的项目映像。

(可选)用于检索的项目图片

存储在索引中的 image_path 值不是可直接检索的 URL。 如需检索图像,请使用知识存储将 normalized_images 投影至 Azure Blob 存储。 然后,客户端应用可以从存储的图像路径构造 Blob URL。

此步骤是可选的。 仅当客户端应用需要显示或下载提取的图像时,才添加它。

将以下配置片段中的 knowledgeStore 属性添加到技能组有效负载中。 使用 PUT {endpoint}/skillsets/my_content_understanding_skillset?api-version=2026-10-01 更新现有技能集。 受权限保护SharePoint内容不支持此可选 Blob 方案。

{
  "knowledgeStore": {
    "storageConnectionString": "<your-azure-storage-connection-string>",
    "projections": [
      {
        "files": [
          {
            "storageContainer": "extracted-images",
            "source": "/document/normalized_images/*"
          }
        ],
        "tables": [],
        "objects": []
      }
    ]
  }
}

若要填充已编制索引的文档的新文件投影, 请重置并运行索引器。 这会使用更新的技能集重新处理源文件。

索引器运行后,容器中的每个 extracted-images Blob 对应于一个 normalized_images 元素。 Blob URL 的格式为 https://<storage-account>.blob.core.windows.net/<container>/<imagePath>。 当分块的 image_path 包含多条以分号间隔的路径时,请分别使用每条独立的存储图像路径。 你的应用还需要获得对Blob 存储的授权访问权限;文件投影不会公开图像或启用知识库映像服务。

有关完整架构定义,包括其他投影类型(tables和objects)以及身份验证选项,请参阅Foundry IQ 中的知识存储“投影”。

控制生成图像的文字描述

有关直接和生成的管道设置,包括选择退出验证和资产存储约束,请参阅 计费和图像说明控件。

清理资源

不再需要引入时,请停止或删除索引器及其计划。 不再需要数据源、技能集和索引时,请将其删除。 搜索容量、Blob 文件和提取的图像、Foundry 资源和模型部署具有单独的生命周期:删除搜索对象不会删除这些外部资源或已产生反向费用。

对于生成的知识源,请使用其记录的删除过程并 查看其生成的对象。 不要删除其他管道使用的共享资源。

故障排除

如果索引器失败或返回意外结果,请检查以下常见原因。

技能集验证失败并返回 400 错误

当参数组合冲突时,技能将返回错误 400 Skill validation failed 。 常见原因:

  • modelName 的设置未配备 modelDeployment,反之亦然。 两者必须同时设置。
  • 将method设置为semantic,并将overlapLength设置为大于0的值。 overlapLength设置为0或省略它。
  • method 和 unit 不是受支持的组合。 将 fixedSize 与 characters 一起使用,或将 semantic 与 tokens 一起使用。

针对 Foundry 资源的授权失败

如果在调用 Foundry 资源时技能返回 401 或 403,请验证:

text_sections 为空

如果索引文档没有区块,请验证:

  • 该文件格式受支持。 有关列表,请参阅 支持的文件格式。
  • Foundry 资源位于受支持的区域中。
  • 在编制索引之前,密码保护的 PDF 将解锁。

缺少图像说明

如果区块不包含内联映像说明,请检查 说明配置、附加的 Foundry 资源中的部署及其可用的 TPM 或 RPM 配额。

内容理解分析疑难解答

默认文档分析轮询窗口为 8 分钟。 当此窗口过期时,进程将返回技能超时错误,并生成该文档的内容理解输出。 此过期不一定会让整个索引器运行失败。

使用执行详细信息来区分原因:

症状或证据 检查
分析轮询后的技能超时 代表性文档复杂度、可选任务、资源位置以及标准的大文档相关说明。 批的大小不会改变该窗口。
分析器创建未能就绪 具有 5 分钟就绪性轮询超时的单独操作,而不是 8 分钟的文档分析窗口。
终端内容理解失败或格式不正确的输出 报告的服务错误以及支持的文件/输入格式。 不要把每个缺失的数据块都诊断为轮询期满。
HTTP 超时、429 或服务不可用 请求和网络故障、限流以及配置的模型和服务容量。 重试延迟可能会占用轮询时间。
401 或 403 标识、角色分派、资源终结点和网络访问。
文件和页面配额或索引器运行时耗尽 内容理解服务限制 和 搜索索引器限制(单独)。

记录索引器名称、执行时间、受影响的源标识符、技能名称、错误详细信息以及支持请求和关联 ID。 请勿包含访问令牌、密钥或受保护的文档内容。 请参阅 索引器故障排除 和 常见错误和警告。

在重新运行或重置之前,请考虑重复提取、描述和嵌入的成本。 不要假设会使用缓存分析、恢复轮询、取消先前的内容理解操作,也不要认为不会产生重复处理费用。