VOOZH about

URL: https://thenewstack.io/exploring-chroma-the-open-source-vector-database-for-llms/

⇱ Exploring Chroma: The Open Source Vector Database for LLMs - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-07-28 09:00:43
Exploring Chroma: The Open Source Vector Database for LLMs
sponsor-promptops,sponsored-topic,tutorial,
AI / Data / Large Language Models / Open Source

Exploring Chroma: The Open Source Vector Database for LLMs

Chroma is the open-source embedding database that makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs. Find out here how it works.
Jul 28th, 2023 9:00am by Janakiram MSV
👁 Featued image for: Exploring Chroma: The Open Source Vector Database for LLMs

The rise of large language models has accelerated the adoption of vector databases that store word embeddings.

A vector database stores data in vector form, leveraging the potential of advanced machine learning algorithms. It enables highly efficient similarity search, which is crucial for AI applications, including recommendation systems, image recognition, and natural language processing.

Each data point stored in a vector database is represented as a multidimensional vector, capturing the essence of complex data. Advanced indexing methods, like k-d trees or hashing, facilitate quick retrieval of similar vectors. This architecture creates highly scalable, efficient solutions for data-heavy industries, transforming how we approach big data analytics.

In this article, we will take a closer look at Chroma, a lightweight, open source vector database.

PromptOps, powered by advanced machine learning and Large Language Models (LLMs), streamlines operational data access, team coordination, and process automation. PromptOps enables DevOps teams to maintain superior platform performance and deliver an unparalleled customer experience.
Learn More
The latest from PromptOps

Overview of Chroma

Chroma can be used with Python or JavaScript code to generate word embeddings. It has a simple API that can be used against the database backend that’s running in-memory or in client/server mode. Developers can install Chroma, consume the API in a Jupyter Notebook while prototyping, and then use the same code in a production environment, which may run the database in client/server mode.

When running in-memory, Chroma database collections can be saved to the disk in Apache Parquet format. Since generating word embeddings is an expensive task, saving them for later retrieval reduces the cost and performance overhead.

Let’s see the Chroma vector database in action.

Using Chroma with Python

The first step to using Chroma is installing it through pip.

pip install chroma

Once installed, you can then import the module into your code.

import chromadb

Let’s now create a list of strings that we will encode into embeddings.

phrases=[
 "Amanda baked cookies and will bring Jerry some tomorrow.",
 "Olivia and Olivier are voting for liberals in this election.",
 "Sam is confused, because he overheard Rick complaining about him as a roommate. Naomi thinks Sam should talk to Rick. Sam is not sure what to do.",
 "John's cookies were only half-baked but he still carries them for Mary."
]

We also need a list of strings that uniquely identify the above strings.

ids=["001","002","003","004"]

It’s also possible to associate additional metadata with each string that has a reference or a pointer to the original source. This is completely optional. For our tutorial, we will add some dummy metadata. This is structured as a list of dictionary objects.

metadatas=[{"source": "pdf-1"},{"source": "doc-1"},{"source": "pdf-2"},{"source": "txt-1"}]

Now, we have all the entities that can be stored in Chroma. Let’s initialize the client.

chroma_client = chromadb.Client()

If you want to persist the data to the disk, you can pass the location of the directory to save the database.

chroma_client = chromadb.PersistentClient(path="/path/to/save/to")

Chroma calls a set of relevant content a collection. Each collection has documents, which are simply a list of strings, ids that act as unique identifiers for the documents, and, optionally, metadata.

Embeddings are an important part of collections. They can be implicitly generated based on the word embedding model included within Chroma, or you can generate them based on an external word embedding model based on OpenAI, PaLM, or Cohere. Chroma makes it easy to integrate external APIs to automate the process of generating embeddings and then storing them. We will explore this concept in more detail in the next part of this tutorial.

Chroma creates embeddings by default using the Sentence Transformers, all-MiniLM-L6-v2 model. This embedding model can generate sentence and document embeddings for a variety of tasks. This embedding function runs locally on your machine and may necessitate the download of model files, which will occur automatically.

Since we are relying on the inbuilt word embedding model offered by Chroma, we will only ingest the data and let Chroma automatically generate the embeddings for each of the documents in the collection.

Let’s go ahead and create a collection.

collection = chroma_client.create_collection(name="tns_tutorial")

We are now ready to insert the documents into the collection.

collection.add(
 documents=phrases,
 metadatas=metadatas,
 ids=ids
)

We can quickly check if the embeddings are generated for the inserted documents.

collection.peek()

You should see the embeddings automatically generated and added to the embeddings list of the collection.

We can now perform a similarity search on the collection. Let’s search for phrases that match the phrase “Mary got half-baked from John”. Notice that it only has a similar meaning to one of the documents but not an exact match.

results = collection.query(
 query_texts=["Mary got half-baked cake from John"],
 n_results=2
)

When you access the results variable, it has the following content:

{'ids': [['004', '001']],
 'distances': [[0.4699302613735199, 1.333911657333374]],
 'metadatas': [[{'source': 'txt-1'}, {'source': 'pdf-1'}]],
 'embeddings': None,
 'documents': [["John's cookies were only half-baked but he still carries them for Mary.",
 'Amanda baked cookies and will bring Jerry some tomorrow.']]}

Based on the distance, the first document in the list is a perfect match. We can now access the actual phrase by accessing the element directly. The embeddings element is empty because it’s expensive to fetch the embeddings for each query. But, behind the scenes, Chroma is performing a cosine similarity search on the embeddings stored as vectors.

print(results['documents'][0][0])

The Chroma database also supports querying based on the metadata, or ids. This makes it handy to perform a search based on the source of the documents.

results = collection.query(
 query_texts=["cookies"],
 where={"source": "pdf-1"},
 n_results=1
)

The above query first performs a similarity search and then filters the query based on the where condition, which specifies the metadata.

Finally, let’s delete the collection.

collection.delete()

In the next part of this tutorial, scheduled for next week, we will extend the Academy Awards chatbot to use the Chroma vector database. Stay tuned.

Below is the complete code that you can try on your machine.

PromptOps, powered by advanced machine learning and Large Language Models (LLMs), streamlines operational data access, team coordination, and process automation. PromptOps enables DevOps teams to maintain superior platform performance and deliver an unparalleled customer experience.
Learn More
The latest from PromptOps
TRENDING STORIES
Janakiram MSV (Jani) is a practicing architect, research analyst, and advisor to Silicon Valley startups. He focuses on the convergence of modern infrastructure powered by cloud-native technology and machine intelligence driven by generative AI. Before becoming an entrepreneur, he spent...
Read more from Janakiram MSV
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Pragma, OpenAI.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.