Course contentsShow
← AI Engineering
Lesson 306 of 1,8868. Vector Databases - ToolsFree lesson

Chroma: Getting Started

Installing Chroma, creating collections, and performing basic vector operations with in-memory and persistent storage.

Chroma: Getting Started

What you'll learn: How to install Chroma and perform your first vector operations using both in-memory and persistent storage modes.

What is Chroma?

Chroma is an open-source vector database designed specifically for AI applications. Think of it as a specialized filing system that organizes information by meaning rather than keywords — perfect for storing and searching embeddings you generate from text, images, or other data.

Installation

Chroma installs easily via pip:

pip install chromadb

Creating Your First Collection

A collection in Chroma is like a table in a traditional database — it holds your vectors and their metadata:

import chromadb

# In-memory mode (data lost when program stops)
client = chromadb.Client()

# Create a collection
collection = client.create_collection(name="my_documents")

Basic Vector Operations

Here's how to add vectors and search them:

# Add vectors with IDs, embeddings, and optional metadata
collection.add(
    ids=["doc1", "doc2", "doc3"],
    embeddings=[[0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.7, 0.8, 0.9]],
    metadatas=[{"source": "web"}, {"source": "book"}, {"source": "web"}]
)

# Query with a vector
results = collection.query(
    query_embeddings=[[0.1, 0.2, 0.3]],
    n_results=2
)

Persistent Storage

To keep your data between sessions:

client = chromadb.PersistentClient(path="./chroma_data")
collection = client.get_or_create_collection(name="my_documents")

Key Takeaway: Chroma provides a lightweight, Python-native way to store and query vectors with just a few lines of code, supporting both temporary in-memory experiments and persistent production storage.