Chroma 报错合集:覆盖向量库持久化、embedding 维度锁定与 SentenceTransformer 模型拉取失败等向量数据库集成高频坑,每条案例都附根因分析与验证过的解法。
collection 生命周期、维度锁定、持久化与 SentenceTransformer 模型集成
用 chromadb.Client()(内存模式)建 collection 写数据,重启 Python 进程后 get_collection 报 Collection not found,根因是 Client() 不落盘、数据只在内存。改 PersistentClient(path=...) 后重启数据仍在。
同一 collection 换 embedding 模型后 add/query 报 InvalidDimensionException 维度不匹配,根因是 collection 维度在首次写入时锁定且不可改,需删库重建并全程用同一 embedding 函数。
SentenceTransformerEmbeddingFunction 首次加载模型时 huggingface.co 连接超时报错,根因是 HuggingFace 直连不通。设 HF_ENDPOINT=https://hf-mirror.com(或 modelscope 下载到本地)即可,无需梯子。