Skip to main content
This notebook covers how to get started with the Chroma vector store.
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

Setup

To access Chroma vector stores you’ll need to install the langchain-chroma integration package.

Credentials

You can use the Chroma vector store without any credentials, simply installing the package above is enough! If you are a Chroma Cloud user, set your CHROMA_TENANT, CHROMA_DATABASE, and CHROMA_API_KEY environment variables. 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:
If you want to get best in-class automated tracing of your model calls, set your LangSmith API key and enable tracing:

Initialization

Basic initialization

The following example shows setting up an embedding function for Chroma, followed by configuring local persistence for storing vector data.

Running locally (In-Memory)

You can get a Chroma server running in memory by simply instantiating a Chroma instance with a collection name and your embeddings provider:
If you don’t need data persistence, this is a great option for experimenting while building your AI application with LangChain.

Running locally (with data persistence)

You can provide the persist_directory argument to save your data across multiple runs of your program:

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 the host argument. For example, you can start a Chroma server running locally with chroma run, and then connect it with host='localhost':
For other deployments you can use the port, ssl, and headers arguments to customize your connection.

Chroma cloud

Chroma Cloud users can also build with LangChain. Provide your Chroma instance with your Chroma Cloud API key, tenant, and DB name:

Initialization from client

You can also initialize from a Chroma client, which is particularly useful if you want easier access to the underlying database.

Running locally (In-Memory)

Running locally (with data persistence)

Connecting to a chroma Server

For example, if you are running a Chroma server locally (using chroma run):

Chroma cloud

After setting your CHROMA_API_KEY, CHROMA_TENANT, and CHROMA_DATABASE, you can simply instantiate:

Access your chroma DB

Create a chroma vectorstore

Manage vector store

Once you have created your vector store, we can interact with it by adding and deleting different items.

Add items to vector store

We can add items to our vector store by using the add_documents function.

Update items in vector store

Now that we have added documents to our vector store, we can update existing documents by using the update_documents function.

Delete items from vector store

We can also delete items from our vector store as follows:

Query vector store

Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent.

Query directly

Performing a simple similarity search can be done as follows:

Similarity search with score

If you want to execute a similarity search and receive the corresponding scores you can run:

Search by vector

You can also search by vector:

Other search methods

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 for Chroma check out the API reference.

Query by turning into retriever

You can also transform the vector store into a retriever for easier usage in your chains. For more information on the different search types and kwargs you can pass, please visit the Chroma API reference.

Usage for retrieval-augmented generation

For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:

API reference

For detailed documentation of all Chroma vector store features and configurations head to the API reference.