0
0
LangChainframework~10 mins

Chroma vector store setup in LangChain - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Chroma vector store setup
Import Chroma and dependencies
Create embeddings model
Initialize Chroma vector store
Add documents to vector store
Query vector store for similar docs
Use results
This flow shows how to set up Chroma vector store: import, create embeddings, initialize store, add docs, then query.
Execution Sample
LangChain
from langchain.vectorstores import Chroma
from langchain.embeddings import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
vectorstore = Chroma(embedding_function=embeddings)
vectorstore.add_texts(["Hello world", "Langchain rocks"])
This code imports Chroma and embeddings, creates embeddings, initializes Chroma vector store, and adds two texts.
Execution Table
StepActionEvaluationResult
1Import Chroma and OpenAIEmbeddingsModules loadedReady to use classes
2Create embeddings instanceembeddings = OpenAIEmbeddings()embeddings object created
3Initialize Chroma vector storevectorstore = Chroma(embedding_function=embeddings)Empty vector store ready
4Add texts to vector storevectorstore.add_texts(["Hello world", "Langchain rocks"])Texts embedded and stored
5Query vector store (not shown here)vectorstore.similarity_search("Hello")Returns similar documents
💡 Setup complete, vector store ready for queries
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
embeddingsNoneOpenAIEmbeddings instanceOpenAIEmbeddings instanceOpenAIEmbeddings instanceOpenAIEmbeddings instance
vectorstoreNoneNoneEmpty Chroma vector storeChroma vector store with 2 textsChroma vector store with 2 texts
Key Moments - 2 Insights
Why do we need to create an embeddings instance before initializing Chroma?
Chroma needs an embedding function to convert texts into vectors. The embeddings instance provides this function, as shown in step 2 and used in step 3.
What happens when we call add_texts on the vector store?
The texts are converted into vectors using the embeddings function and stored inside Chroma. This is shown in step 4 where texts become embedded and stored.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of 'vectorstore' after step 3?
AChroma vector store with 2 texts stored
BEmpty Chroma vector store ready to add texts
CNone, vectorstore not created yet
DAn embeddings instance
💡 Hint
Check the 'Result' column for step 3 in the execution table
At which step are the texts converted into vectors and stored?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look for 'Texts embedded and stored' in the execution table
If we skip creating the embeddings instance, what will happen when initializing Chroma?
AError because embedding_function is missing
BChroma initializes with default embeddings
CVector store initializes empty anyway
DTexts are automatically embedded
💡 Hint
Refer to step 3 where embeddings instance is passed to Chroma
Concept Snapshot
Chroma vector store setup:
1. Import Chroma and embeddings.
2. Create embeddings instance.
3. Initialize Chroma with embeddings.
4. Add texts to store (embedding happens here).
5. Query vector store for similar texts.
Full Transcript
To set up a Chroma vector store in Langchain, first import the Chroma class and an embeddings model like OpenAIEmbeddings. Then create an embeddings instance. Next, initialize the Chroma vector store by passing the embeddings instance as the embedding_function parameter. After that, add your texts to the vector store using add_texts, which converts texts into vectors and stores them. Finally, you can query the vector store to find similar documents. This process ensures your texts are searchable by their meaning, not just words.