咨询Azure OpenAI可识别的复杂类型搜索索引创建方法
解决Azure OpenAI无法识别Azure AI Search复杂类型字段的方案
问题根源
Azure OpenAI的聊天功能(含AI Chat Playground)仅支持直接引用顶级可搜索字符串字段,无法直接识别嵌套在复杂类型(Complex Type)中的字段,因此需要将嵌套字段提取为顶级字段,或构造包含嵌套内容的聚合顶级字段。
方法一:将嵌套字段映射为顶级可搜索字段
修改索引定义
在Azure AI Search的索引中,新增对应嵌套字段的顶级Edm.String类型字段,并设置searchable: true。
示例(原复杂类型结构):"fields": [ { "name": "document", "type": "Edm.ComplexType", "fields": [ {"name": "title", "type": "Edm.String", "searchable": true}, {"name": "content", "type": "Edm.String", "searchable": true} ] } ]修改后新增顶级字段:
"fields": [ { "name": "document", "type": "Edm.ComplexType", "fields": [ {"name": "title", "type": "Edm.String", "searchable": true}, {"name": "content", "type": "Edm.String", "searchable": true} ] }, {"name": "document_title", "type": "Edm.String", "searchable": true}, {"name": "document_content", "type": "Edm.String", "searchable": true} ]配置索引器字段映射
在索引器的fieldMappings中添加映射规则,将复杂类型的嵌套字段值同步到顶级字段:"fieldMappings": [ { "sourceFieldName": "/document/title", "targetFieldName": "document_title" }, { "sourceFieldName": "/document/content", "targetFieldName": "document_content" } ]重新运行索引器
触发索引器同步,确保嵌套字段的数据被正确写入顶级字段。此时Azure OpenAI的GUI下拉列表会显示这些顶级字段,可直接选择作为内容、标题等配置项。
方法二:创建聚合内容的顶级字段
如果无需单独引用嵌套字段,可将所有需要用于问答的嵌套内容拼接为一个顶级字段:
- 在索引中新增
aggregated_content字段,类型为Edm.String且searchable: true。 - 在索引器中使用拼接函数整合嵌套内容:
"fieldMappings": [ { "sourceFieldName": "/document/title", "targetFieldName": "aggregated_content", "mappingFunction": { "name": "concat", "parameters": { "separator": "\n\n", "expressions": ["/document/title", "/document/content"] } } } ] - 重新运行索引器后,在Azure OpenAI中选择
aggregated_content作为内容字段即可。
关键注意事项
- 所有供Azure OpenAI使用的字段必须是顶级Edm.String类型,且
searchable属性为true,否则不会出现在下拉列表中。 - 修改索引后必须重新运行索引器,确保新字段被正确填充数据。
- 若原索引已有大量数据,建议创建新索引并重新导入数据,避免修改现有索引引发的数据同步问题。
内容的提问来源于stack exchange,提问作者Snowy
相关产品推荐
相关产品推荐

