You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

现有配置下存储AzureOpenAIEmbeddingSkill向量及解决401授权错误

问题后续:向索引器存入AzureOpenAIEmbeddingSkill生成的向量及权限错误处理

这是此前相关问题的后续提问,当前核心需求为:基于现有配置完成AzureOpenAIEmbeddingSkill生成向量向索引器的存入操作,同时解决遇到的权限错误。

现有配置信息

自定义WebApiSkill代码

combined_list = [{'textItems': text, 'numberItems': number} for text, number in zip(chunks, page_numbers)]

# 单个PDF的响应对象
response_record = {
    "recordId": recordId,
    "data": {
        "subdata": combined_list
    }
}
response_body['values'].append(response_record)

技能集定义

{
  ...
  "description": "用于分割文档并生成向量的技能集",
  "skills": [
    {
      "@odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
      "name": "splitclean",
      "description": "自定义分割技能,按指定大小和重叠度分割文档",
      "context": "/document",
      "httpMethod": "POST",
      "timeout": "PT30S",
      "batchSize": 1,
      "degreeOfParallelism": null,
      "authResourceId": null,
      "inputs": [
        {
          "name": "text",
          "source": "/document/content"
        }
      ],
      "outputs": [
        {
          "name": "subdata",
          "targetName": "subdata"
        }
      ],
      "authIdentity": null
    },
    {
      "@odata.type": "#Microsoft.Skills.Text.AzureOpenAIEmbeddingSkill",
      "name": "#2",
      "description": "通过Azure OpenAI生成向量的技能",
      "context": "/document/subdata/*",
      "apiKey": "<redacted>",
      "deploymentId": "embedding-ada-002",
      "dimensions": null,
      "modelName": "experimental",
      "inputs": [
        {
          "name": "text",
          "source": "/document/subdata/*/textItems"
        }
      ],
      "outputs": [
        {
          "name": "embedding",
          "targetName": "vector"
        }
      ],
      "authIdentity": null
    }
  ],
  "cognitiveServices": null,
  "knowledgeStore": null,
  "indexProjections": {
    "selectors": [
      {
        "parentKeyFieldName": "parent_id",
        "sourceContext": "/document/subdata/*",
        "mappings": [
          {
            "name": "chunk",
            "source": "/document/subdata/*/textItems",
            "sourceContext": null,
            "inputs": []
          },
          {
            "name": "vector",
            "source": "/document/subdata/*/vector",
            "sourceContext": null,
            "inputs": []
          },
          {
            "name": "title",
            "source": "/document/metadata_storage_name",
            "sourceContext": null,
            "inputs": []
          },
          {
            "name": "page_number",
            "source": "/document/subdata/*/numberItems",
            "sourceContext": null,
            "inputs": []
          }
        ]
      }
    ],
    "parameters": {
      "projectionMode": "skipIndexingParentDocuments"
    }
  },
  "encryptionKey": null
}

遇到的错误

在AzureOpenAIEmbeddingSkill执行时触发401未授权错误:

Web Api response status: 'Unauthorized', Web Api response details: '{"error":{"code":"401","message":"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}'

解决步骤

一、优先修复401权限错误(核心阻碍)

  1. 验证并替换API密钥
    • 登录Azure门户,找到目标Azure OpenAI资源,在「密钥和终结点」页面复制有效密钥(两个密钥任选其一),替换技能集中的<redacted>占位符,确保密钥未过期且资源处于活动状态。
  2. 指定正确的OpenAI终结点
    • 若Azure OpenAI资源与认知搜索服务不在同一区域,需在AzureOpenAIEmbeddingSkill中添加endpoint参数:
      {
        "@odata.type": "#Microsoft.Skills.Text.AzureOpenAIEmbeddingSkill",
        "name": "#2",
        // 保留其他原有参数
        "endpoint": "https://<你的OpenAI资源名称>.openai.azure.com/"
      }
      
  3. 确认资源访问权限
    • 若使用托管标识,需确保认知搜索服务的托管标识拥有Azure OpenAI资源的「认知服务用户」角色;若使用密钥认证,直接确保密钥权限正常即可。

二、确保向量正常存入索引器的配置检查

  1. 匹配索引字段结构
    • 目标索引需包含对应字段:
      • chunk(字符串类型)
      • vector(向量类型,维度需与ada-002模型一致,默认1536维)
      • title(字符串类型)
      • page_number(整数类型)
      • parent_id(字符串类型,用于关联父文档)
  2. 验证上下文与映射一致性
    • AzureOpenAIEmbeddingSkill的上下文/document/subdata/*已正确指向每个分块,索引投影中vector字段的源路径/document/subdata/*/vector与技能输出的targetName完全匹配,无需调整。
  3. 测试技能集全流程
    • 在Azure认知搜索门户中使用「测试技能集」功能,输入测试文档内容,验证分块生成、向量计算、索引投影的全链路是否正常,排除其他潜在配置问题。

内容的提问来源于stack exchange,提问作者Mike B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 13:27:13