Practical: Your First Database with ChromaDB

Harry · 13 Sep 2026 · 2 views

Why ChromaDB

ChromaDB is an open-source vector database that stores documents, embeddings and metadata together, with a simple Python API and no server needed for small projects.

Install and Create

pip install chromadb

import chromadb

client = chromadb.PersistentClient(path="demo_chroma")
movies = client.get_or_create_collection(
    "movies", metadata={"hnsw:space": "cosine"}
)

Add and Query

movies.add(
    ids=["m1", "m2", "m3"],
    documents=[
        "A submarine crew explores the deep ocean.",
        "Astronauts battle robots in outer space.",
        "Two neighbours plan a heist in Mumbai.",
    ],
    metadatas=[
        {"genre": "adventure"},
        {"genre": "sci-fi"},
        {"genre": "comedy"},
    ],
)

results = movies.query(query_texts=["a space mission"], n_results=2)
print(results["documents"][0])

Filter with Metadata

filtered = movies.query(
    query_texts=["ocean adventure"],
    n_results=2,
    where={"genre": "adventure"},
)
print(filtered["documents"][0])

Update and Clean Up

movies.update(ids=["m2"], documents=["Astronauts explore Mars."])
client.delete_collection("movies")

Key Points

  • ChromaDB stores documents, vectors and metadata.
  • PersistentClient saves data to a folder.
  • Pass where filters to narrow results.
  • Cosine space is a solid default for text.
Share this post:

Comments (0)

Please login or register to comment.