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

使用LangChain+ChromaDB构建QA系统时遇create_collection参数错误

解决LangChain + ChromaDB TypeError: create_collection() got an unexpected keyword argument 'embedding_fn'

这个错误的核心原因是LangChain与ChromaDB版本不兼容:

  • 旧版LangChain调用ChromaDB的create_collection方法时使用了embedding_fn参数
  • 新版ChromaDB(v0.4.0及以上)已将该参数重命名为embedding_function,但你的LangChain版本仍在使用旧参数名发起调用

解决办法(二选一即可)

  1. 降级ChromaDB到兼容版本
    执行命令安装适配旧版LangChain的ChromaDB版本:

    pip install chromadb==0.3.29
    
  2. 升级LangChain到最新稳定版
    新版LangChain已适配ChromaDB的参数变更,执行升级命令:

    pip install --upgrade langchain
    

验证

重新运行你的代码,错误应该会消失。如果仍有问题,检查是否存在多环境版本冲突,建议在虚拟环境中操作。

内容的提问来源于stack exchange,提问作者Ishaan Gupta

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 00:50:23