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

Azure AI Search索引器浮点数组类型映射不匹配问题求助

Azure AI Search索引器浮点数组类型映射不匹配问题求助

我在构建Azure AI Search索引器时遇到了一个类型不匹配的问题,想请教大家怎么解决。

我用了一个带Custom.WebApiSkill的技能集,它返回的响应体格式如下:

{
  "values": [
    {
      "recordId": "1",
      "data": {
        "embedding": [
          -0.013657977,
          0.004854262,
          -0.015335504,
          -0.010732211,
          ...
        ]
      }
    }
  ]
}

作为索引器的一部分,我尝试把响应里的embedding值映射到索引的content_vector字段,配置的输出字段映射是:

"outputFieldMappings": [
    {
      "sourceFieldName": "/document/pages/*/embedding",
      "targetFieldName": "content_vector",
      "mappingFunction": null
    }
  ]

我的索引里content_vector字段的定义是这样的:

{
      "name": "content_vector",
      "type": "Collection(Edm.Single)",
      "key": false,
      "retrievable": true,
      "stored": true,
      "searchable": true,
      "filterable": false,
      "sortable": false,
      "facetable": false,
      "synonymMaps": [],
      "dimensions": 1536,
      "vectorSearchProfile": "myHnswProfile"
    }

但执行的时候收到了这个错误:

The data field 'content_vector/0' in the document with key 'aHR0cHM6Ly9zdHJhZ3Byb3RvdHlwZGV2My5ibG9iLmNvcmUud2luZG93cy5uZXQvdGVzdGRhdGEvS29tbXVuaWthdGlvbnN0ZWNobmlrLUZpYmVsLnBkZg2' has an invalid value of type 'Collection(Edm.Double)' ('JSON arrays with element type 'Float' map to Collection(Edm.Double)'). The expected type was 'Collection(Edm.Single)'.

我想知道怎么才能让自定义WebAPI返回float32(Edm.Single)类型的embedding数组,或者怎么让索引器把值识别为float32而不是float64(Edm.Double)?


已尝试的方法

我在Python写的自定义WebAPI里用numpy把embedding转成了float32类型,代码大概是这样的:

embedding_float32 = np.array(embedding, dtype=np.float32).tolist()

但这个方法没起作用。


更新补充

我按照上面的方式用numpy转成了float32,但索引器还是把它识别成float64(Edm.Double),错误信息变成了:

The data field 'content_vector/0' in the document with key 'xyz' has an invalid value of type 'Collection(Edm.Double)' ('JSON arrays with element type 'Float' map to Collection(Edm.Double)'). The expected type was 'Collection(Edm.Single)

我现在的疑问是:有没有办法让索引器把值识别为float32(Edm.Single),或者在自定义WebAPI里强制指定数据类型?毕竟Python本身不原生区分float32和float64,默认会把值当成float64处理和返回。

备注:内容来源于stack exchange,提问作者Alex123

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 16:34:51