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

使用chromadb时遇AttributeError:hnswlib.Index无file_handle_count属性

解决Chromadb中AttributeError: 'hnswlib.Index'无'file_handle_count'属性的问题

错误详情

运行Chromadb时触发以下错误:

c:\Users\satya\AppData\Local\Programs\Python\Python39\lib\site-packages\chromadb\config.py in instance(self, type)
hnswlib_count = hnswlib.Index.file_handle_count
hnswlib_count = cast(int, hnswlib_count)

AttributeError: type object 'hnswlib.Index' has no attribute 'file_handle_count'

当前环境版本

  • Python 3.9
  • hnswlib 0.7.0
  • Chromadb 0.4.5

解决方案

问题根源是版本冲突:Chromadb 0.4.5依赖的是chroma-hnswlib(官方适配的分支版本),但你同时安装了官方原版hnswlib,导致代码调用了错误的库文件。

执行以下步骤修复:

  1. 卸载官方原版hnswlib:
pip uninstall -y hnswlib
  1. 确保Chromadb依赖的chroma-hnswlib已正确安装,若缺失则手动安装:
pip install chroma-hnswlib
  1. 重启Python环境后重新运行代码。

也可以直接指定兼容版本一次性安装,彻底避免冲突:

pip install chromadb==0.4.5 chroma-hnswlib==0.7.3

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 19:05:01