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 accessChroma vector stores you’ll need to install the langchain-chroma integration package.
Credentials
You can use theChroma 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:
Initialization
Basic Initialization
Below is a basic initialization, including the use of a directory to save the data locally.Running Locally (In-Memory)
You can get a Chroma server running in memory by simply instantiating aChroma instance with a collection name and your embeddings provider:
Running Locally (with Data Persistence)
You can provide thepersist_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 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.
Running Locally (In-Memory)
Running Locally (with Data Persistence)
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
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 theadd_documents function.
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.
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
Similarity search
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 or searching by vector. For a full list of the search abilities available forAstraDBVectorStore 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 API reference here.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 allChroma vector store features and configurations head to the API reference: python.langchain.com/api_reference/chroma/vectorstores/langchain_chroma.vectorstores.Chroma.html
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.