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

调用Chroma Collection的get()时embeddings始终为None的问题求助

解决Chroma Collection.get()返回embeddings为None的问题

核心解决方案

调用collection.get()时,必须显式指定include=["embeddings"]参数,否则默认不会返回存储的嵌入向量。

原因说明

Chroma的get()方法默认的include参数为["documents", "metadatas"],仅返回文档和元数据,不包含embeddings。而你使用query()时显式指定了include=["embeddings"],所以能正常获取到嵌入向量,这是两者的关键区别。

修改后的验证代码

import chromadb

chroma_client = chromadb.Client()
collection = chroma_client.create_collection(name="my_collection")
collection.add(
    embeddings=[[1.2, 2.3, 4.5], [6.7, 8.2, 9.2]],
    documents=["This is a document", "This is another document"],
    metadatas=[{"source": "my_source"}, {"source": "my_source"}],
    ids=["id1", "id2"]
)

# 显式指定需要返回的字段,包含embeddings
print(collection.get(include=["embeddings", "documents", "metadatas"]))

预期输出

{'ids': ['id1', 'id2'], 'embeddings': [[1.2, 2.3, 4.5], [6.7, 8.2, 9.2]], 'documents': ['This is a document', 'This is another document'], 'metadatas': [{'source': 'my_source'}, {'source': 'my_source'}]}

LangChain包装器的适配

使用LangChain的Chroma集成时,同样需要在调用get()方法时指定include参数:

from langchain.vectorstores import Chroma

# 假设已完成vector_store的初始化配置
results = vector_store.get(include=["embeddings"])

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 02:40:06