MacOS 14(Intel)下使用ChromaDB添加文档时出现ONNXRuntimeError
ChromaDB在MacOS 14 Intel环境下运行报错的问题分析与解决
问题详情
运行脚本
import chromadb client = chromadb.Client() collection = client.create_collection(name="example") collection.add( documents=["Sky is unlimited.", "Tree is a plant."], ids=["d_1", "d_2"] ) items = collection.get() collection.peek(limit=5)
报错信息
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running CoreML_10659388614159815537_1 node. Name:'CoreMLExecutionProvider_CoreML_10659388614159815537_1_1' Status Message: Error executing model: Unable to compute the prediction using a neural network model. It can be an invalid input data or broken/unsupported model (error code: -1)
硬件环境
MacOS 14, Intel
可能原因
- CoreML执行器兼容性问题:ChromaDB默认会启用CoreML执行器加速嵌入模型推理,但CoreML在Intel芯片的MacOS 14系统上存在适配缺陷,导致ONNX Runtime调用时触发报错。
- 嵌入模型文件损坏:Chroma自动下载的默认嵌入模型(如all-MiniLM-L6-v2)可能因网络波动导致文件不完整,或者其CoreML转换版本无法在Intel Mac上正常运行。
解决方法
1. 禁用CoreML,强制使用CPU执行器
初始化Chroma客户端时,明确指定使用CPU执行器,绕过CoreML的调用:
import chromadb from chromadb.config import Settings client = chromadb.Client(Settings( anonymized_telemetry=False, onnxruntime_execution_providers=["CPUExecutionProvider"], chroma_embedding_impl="default" )) collection = client.create_collection(name="example") collection.add( documents=["Sky is unlimited.", "Tree is a plant."], ids=["d_1", "d_2"] ) items = collection.get() print(items) collection.peek(limit=5)
2. 重置嵌入模型缓存
如果是模型文件损坏,手动删除Chroma的缓存目录后重新运行脚本,让它重新下载完整的模型文件:
- 缓存路径:
~/.cache/chroma - 删除该目录后再次执行脚本即可
3. Docker替代方案(非必需)
这个问题是本地环境兼容性问题,Docker是可选解决方案而非必须。若不想修改代码,可通过Docker启动Chroma服务,本地脚本连接远程服务:
# 启动Chroma Docker容器 docker run -p 8000:8000 chromadb/chroma
修改脚本连接远程服务:
import chromadb client = chromadb.HttpClient(host='localhost', port=8000) # 后续集合创建、添加文档等操作保持不变 collection = client.create_collection(name="example") collection.add( documents=["Sky is unlimited.", "Tree is a plant."], ids=["d_1", "d_2"] ) items = collection.get() collection.peek(limit=5)
内容的提问来源于stack exchange,提问作者Dmitri Galkin
相关产品推荐
相关产品推荐

