Chroma 向量存储。
Chroma is a AI-native open-source vector database focused on developer productivity and happiness. Chroma is licensed under Apache 2.0. View the full docs of Chroma at this page, and find the API reference for the LangChain integration at this page.
Chroma CloudChroma Cloud powers serverless vector and full-text search. It’s extremely fast, cost-effective, scalable and painless. Create a DB and try it out in under 30 seconds with $5 of free credits.Get started with Chroma Cloud
设置
要访问Chroma 向量存储,您需要安装 langchain-chroma 集成包。
凭证
您无需任何凭证即可使用Chroma 向量存储,只需安装上述包即可!
如果您是 Chroma Cloud 用户,请设置 CHROMA_TENANT、CHROMA_DATABASE 和 CHROMA_API_KEY 环境变量。
When you install the chromadb package you also get access to the Chroma CLI, which can set these for you. First, login via the CLI, and then use the connect command:
初始化
基本初始化
以下是基本初始化,包括使用目录在本地保存数据。本地运行(内存模式)
您可以通过简单地使用集合名称和向量嵌入提供者实例化Chroma 来在内存中运行 Chroma 服务器:
本地运行(持久化数据)
您可以提供persist_directory 参数来在程序多次运行之间保存数据:
Connecting to a chroma Server
If you have a Chroma server running locally, or you have deployed one yourself, you can connect to it by providing thehost argument.
For example, you can start a Chroma server running locally with chroma run, and then connect it with host='localhost':
port, ssl, and headers arguments to customize your connection.
Chroma cloud
Chroma Cloud users can also build with LangChain. Provide yourChroma instance with your Chroma Cloud API key, tenant, and DB name:
Initialization from client
You can also initialize from aChroma client, which is particularly useful if you want easier access to the underlying database.
本地运行(内存模式)
本地运行(持久化数据)
Connecting to a chroma Server
For example, if you are running a Chroma server locally (usingchroma run):
Chroma cloud
After setting yourCHROMA_API_KEY, CHROMA_TENANT, and CHROMA_DATABASE, you can simply instantiate:
Access your chroma DB
Create a chroma vectorstore
管理向量存储
创建向量存储后,我们可以通过添加和删除不同的项目来与其交互。向向量存储添加项目
我们可以使用add_documents 函数向向量存储添加项目。
Update items in vector store
Now that we have added documents to our vector store, we can update existing documents by using theupdate_documents function.
从向量存储删除项目
We can also delete items from our vector store as follows:查询向量存储
一旦创建了向量存储并添加了相关文档,您很可能希望在链或智能体运行期间对其进行查询。直接查询
相似度搜索
可以按以下方式执行简单的相似度搜索:带分数的相似度搜索
如果您想执行相似度搜索并获取对应分数,可以运行:Search by vector
You can also search by vector:其他搜索方法
There are a variety of other search methods that are not covered in this notebook, such as MMR search. For a full list of the search abilities available forChroma check out the API reference.
转换为检索器进行查询
您还可以将向量存储转换为检索器,以便在链中更方便地使用。 For more information on the different search types and kwargs you can pass, please visit the Chroma API reference.用于检索增强生成
有关如何将此向量存储用于检索增强生成 (RAG) 的指南,请参阅以下部分:API 参考
For detailed documentation of allChroma vector store features and configurations head to the API reference
连接这些文档到 Claude、VSCode 等工具,通过 MCP 获取实时答案。

