Code
cookbook/08_knowledge/vector_db/chroma_db/chroma_db.py
Copy
Ask AI
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.chroma import ChromaDb
# Create Knowledge Instance with ChromaDB
knowledge = Knowledge(
name="Basic SDK Knowledge Base",
description="Agno 2.0 Knowledge Implementation with ChromaDB",
vector_db=ChromaDb(
collection="vectors", path="tmp/chromadb", persistent_client=True
),
)
knowledge.insert(
name="Recipes",
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
metadata={"doc_type": "recipe_book"},
)
# Create and use the agent
agent = Agent(knowledge=knowledge)
agent.print_response("List down the ingredients to make Massaman Gai", markdown=True)
# Delete operations examples
vector_db = knowledge.vector_db
vector_db.delete_by_name("Recipes")
# or
vector_db.delete_by_metadata({"user_tag": "Recipes from website"})
Usage
1
Set up your virtual environment
Copy
Ask AI
uv venv --python 3.12
source .venv/bin/activate
2
Install dependencies
Copy
Ask AI
uv pip install -U chromadb pypdf openai agno
3
Set environment variables
Copy
Ask AI
export OPENAI_API_KEY=xxx
4
Run Agent
Copy
Ask AI
python cookbook/08_knowledge/vector_db/chroma_db/chroma_db.py