Setup
Example
import asyncio
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
),
)
asyncio.run(
knowledge.ainsert(
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"})
For hosted ChromaDB (Chroma Cloud)
from chromadb.config import Settings
vector_db = ChromaDb(
collection="vectors",
settings=Settings(
chroma_api_impl="chromadb.api.fastapi.FastAPI",
chroma_server_host="your-tenant-id.api.trychroma.com",
chroma_server_http_port=443,
chroma_server_ssl_enabled=True,
chroma_client_auth_provider="chromadb.auth.token_authn.TokenAuthClientProvider",
chroma_client_auth_credentials="your-api-key"
)
)
Async Support ⚡
ChromaDB also supports asynchronous operations, enabling concurrency and leading to better performance.
# install chromadb - `pip install chromadb`
import asyncio
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.chroma import ChromaDb
# Initialize ChromaDB
vector_db = ChromaDb(collection="recipes", path="tmp/chromadb", persistent_client=True)
# Create knowledge base
knowledge = Knowledge(
vector_db=vector_db,
)
# Create and use the agent
agent = Agent(knowledge=knowledge)
if __name__ == "__main__":
# Comment out after first run
asyncio.run(
knowledge.ainsert(url="https://docs.agno.com/introduction/agents.md")
)
# Create and use the agent
asyncio.run(
agent.aprint_response("What is the purpose of an Agno Agent?", markdown=True)
)
Use ainsert() and aprint_response() methods with asyncio.run() for non-blocking operations in high-throughput applications.
ChromaDB has a batch size limit due to SQLite constraints.
When inserting documents that exceed this limit, Agno automatically splits them into smaller batches.
The batch size is auto-detected from ChromaDB’s server configuration.You can also set batch_size to override the auto-detected value.
ChromaDb Params