Skip to main content
Build an agent that answers questions about your documents.

Create an Agent with Knowledge

knowledge_agent.py
from agno.agent import Agent
from agno.knowledge.embedder.google import GeminiEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.models.google import Gemini
from agno.vectordb.chroma import ChromaDb
from agno.vectordb.search import SearchType

# Create a knowledge base with ChromaDB
knowledge = Knowledge(
    vector_db=ChromaDb(
        collection="docs",
        path="tmp/chromadb",
        persistent_client=True,
        search_type=SearchType.hybrid,
        embedder=GeminiEmbedder(id="gemini-embedding-001"),
    ),
)

# Load content into the knowledge base
knowledge.insert(url="https://docs.agno.com/introduction.md", skip_if_exists=True)

# Create an agent that searches the knowledge base
agent = Agent(
    model=Gemini(id="gemini-3-flash-preview"),
    knowledge=knowledge,
    search_knowledge=True,
    markdown=True,
)

agent.print_response("What is Agno?", stream=True)

Setup

1

Create virtual environment

uv venv --python 3.12
source .venv/bin/activate
2

Install dependencies

uv pip install -U agno chromadb google-genai
3

Export your API key

export GOOGLE_API_KEY=your-google-api-key
4

Run the agent

python knowledge_agent.py
The agent searches the knowledge base, finds relevant content, and answers based on what it found.

Load Different Content Types

  knowledge.insert(path="docs/product-guide.pdf")
  knowledge.insert(path="data/")  # Entire directory
Agno detects file types automatically and uses the appropriate reader for PDFs, DOCX, CSV, Markdown, and more.

What’s Happening

  1. Insert: Content is chunked, embedded with Gemini, and stored in ChromaDB
  2. Query: The agent receives your question and decides to search the knowledge base using the search_knowledge_base tool
  3. Response: The agent uses the retrieved content to answer, grounding its response in your data
This is Agentic RAG. The agent decides when to search rather than blindly injecting context on every query.

Next Steps