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

使用ChromaDB Server无法保存嵌入向量问题求助

解决ChromaDB HttpClient模式下无法获取Embeddings的问题

针对你使用Python 3.9、ChromaDB 0.4.3版本,通过chromadb.HttpClient连接本地Server时无法获取embeddings,但chromadb.Client()本地模式功能正常的问题,以下是具体解决步骤:

1. 确保ChromaDB Server启动时配置嵌入模型

Server模式不会自动加载默认嵌入模型,必须在启动时明确指定相关参数:

  • 强制启用嵌入模型:
    chroma run --host localhost --port 8000 --chroma-require-embedding-function
    
  • 或者直接指定具体嵌入模型(比如使用默认的sentence-transformers模型):
    chroma run --host localhost --port 8000 --embedding-function sentence-transformers/all-MiniLM-L6-v2
    

2. 在HttpClient的Collection中显式指定嵌入函数

创建Collection时,传入和本地模式一致的嵌入函数,确保客户端与Server端使用相同逻辑生成embeddings:

from chromadb.utils import embedding_functions
import chromadb

chroma_client = chromadb.HttpClient(host='localhost', port='8000')
# 初始化默认嵌入函数
default_ef = embedding_functions.DefaultEmbeddingFunction()
# 创建Collection时绑定嵌入函数
collection = chroma_client.get_or_create_collection(name="my_collectionvvv", embedding_function=default_ef)

collection.add(
    documents=["This is a document", "This is another document"],
    metadatas=[{"source": "my_source"}, {"source": "my_source"}],
    ids=["id1", "id2"]
)

results = collection.query(
    query_texts=["document"],
    n_results=2,
    include=["embeddings", "documents", "metadatas","distances"]
)
results1 = collection.get(
    ids=['id1'],
    include=["embeddings", "documents", "metadatas"]
)
print(results)
print(results1)

3. 验证Server端数据状态

通过ChromaDB的API直接查询Server端的Collection数据,确认embeddings是否存在:

curl -X POST http://localhost:8000/api/v1/collections/my_collectionvvv/get \
  -H "Content-Type: application/json" \
  -d '{"ids": ["id1"], "include": ["embeddings", "documents", "metadatas"]}'

如果返回结果中embeddings为空,说明数据添加时未生成embeddings,需重新检查Server启动配置。

4. 确认客户端与Server端版本一致

确保两端ChromaDB版本完全匹配:

  • Server端执行:chroma --version
  • 客户端执行:pip show chromadb
    若版本不一致,统一升级或降级到0.4.3版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 16:43:19