Build AI Apps with Python: Search by Meaning with ChromaDB | Episode 15
Video: Build AI Apps with Python: Search by Meaning with ChromaDB | Episode 15 by Taught by Celeste AI - AI Coding Coach
Watch full page →Build AI Apps with Python: Search by Meaning with ChromaDB
ChromaDB is a lightweight, in-memory vector database that automatically embeds documents and enables natural language search. In this example, we create a small recipe knowledge base and demonstrate how to query it by meaning, finding relevant recipes based on ingredient or meal preferences without manual embedding steps.
Code
from chromadb import Client
# Initialize ChromaDB client and create a collection
client = Client()
collection = client.create_collection(name="recipes")
# Add recipe documents; ChromaDB embeds them automatically
recipes = [
{"id": "1", "text": "Fried rice with chicken, eggs, and vegetables."},
{"id": "2", "text": "Banana smoothie with yogurt and honey, a healthy breakfast."},
{"id": "3", "text": "Classic Italian carbonara pasta with eggs, cheese, and pancetta."},
{"id": "4", "text": "Vegetable stir fry with tofu and soy sauce."},
{"id": "5", "text": "Avocado toast with cherry tomatoes and basil."},
{"id": "6", "text": "Beef tacos with salsa and guacamole."}
]
for recipe in recipes:
collection.add(documents=[recipe["text"]], ids=[recipe["id"]])
# Query examples: search by natural language meaning
queries = [
"What can I make with chicken?",
"I want something healthy for breakfast",
"How do I make Italian pasta?"
]
for query in queries:
results = collection.query(query_texts=[query], n_results=1)
print(f'Query: "{query}"')
for doc, dist in zip(results["documents"][0], results["distances"][0]):
print(f' Result: {doc} (distance: {dist:.3f})')
print()
Key Points
- ChromaDB automatically generates embeddings for added documents, removing the need for manual embedding code.
- It supports natural language queries to find documents by semantic meaning, not just keyword matching.
- Collections organize documents and enable efficient similarity search in-memory.
- Distance scores indicate how closely query and document embeddings match, with lower values meaning higher relevance.
- ChromaDB is ideal for building lightweight AI-powered search applications with minimal setup.