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

升级LangChain后Azure AI Search向量存储配置报错求助

问题解决方案

错误1:无法导入ExhaustiveKnnAlgorithmConfiguration

  • 版本适配调整:你当前使用的azure-search-documents==11.4.0b8是预览版,该版本中ExhaustiveKnnAlgorithmConfiguration的模块位置发生了变更。建议切换到稳定版11.3.0,该版本中该类仍在标准路径下,执行安装命令:
    pip install azure-search-documents==11.3.0
    
  • 若必须使用预览版,修改导入路径为内部生成模块(注意预览版内部结构不稳定,不建议生产环境使用):
    from azure.search.documents.indexes._generated.models import ExhaustiveKnnAlgorithmConfiguration
    

错误2:向量字段content_vector必须设置vectorSearchProfile属性

该问题是Azure Cognitive Search的强制要求:向量字段必须关联已定义的向量搜索配置文件。修改你的索引创建代码,补充以下关键逻辑:

  1. 定义向量搜索算法与配置文件:

    from azure.search.documents.indexes.models import (
        SearchIndex,
        SearchField,
        SearchFieldDataType,
        VectorSearch,
        VectorSearchProfile,
        ExhaustiveKnnAlgorithmConfiguration
    )
    
    # 定义穷尽KNN算法配置
    exhaustive_knn_config = ExhaustiveKnnAlgorithmConfiguration(name="exhaustive-knn-config")
    # 定义向量搜索配置文件
    vector_search_profile = VectorSearchProfile(
        name="vector-search-profile",
        algorithm_configuration_name="exhaustive-knn-config"
    )
    # 组装向量搜索配置
    vector_search = VectorSearch(
        algorithms=[exhaustive_knn_config],
        profiles=[vector_search_profile]
    )
    
  2. 给向量字段关联配置文件:

    fields = [
        SearchField(name="id", type=SearchFieldDataType.String, key=True),
        SearchField(name="content", type=SearchFieldDataType.String),
        # 为向量字段指定关联的配置文件名称
        SearchField(
            name="content_vector",
            type=SearchFieldDataType.Collection(SearchFieldDataType.Single),
            searchable=True,
            vector_search_profile_name="vector-search-profile"
        )
    ]
    
  3. 创建索引时传入向量搜索配置:

    index = SearchIndex(
        name="your-target-index",
        fields=fields,
        vector_search=vector_search
    )
    

最后建议固定版本组合:使用langchain==0.1.8搭配azure-search-documents==11.3.0,能最大程度避免版本兼容性问题。

内容的提问来源于stack exchange,提问作者Kakobo kakobo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 13:42:36