Skip to main content
Build agents that search and retrieve information from your documents, databases, and APIs.
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector

knowledge = Knowledge(
    vector_db=PgVector(table_name="documents", db_url="postgresql://..."),
)

# Add documents from any source
knowledge.add_content(url="https://example.com/docs.pdf")
knowledge.add_content(path="./local_docs/")

# Create an agent with knowledge
agent = Agent(knowledge=knowledge, search_knowledge=True)
agent.print_response("What does the documentation say about authentication?")

Knowledge Categories

Quick Examples

Basic Knowledge Base

cookbook/07_knowledge/vector_db/pgvector/pgvector_db.py
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector

vector_db = PgVector(
    table_name="recipes",
    db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
)

knowledge = Knowledge(
    name="Recipe Knowledge",
    vector_db=vector_db,
)

# Add content from URL
knowledge.add_content(
    name="Thai Recipes",
    url="https://example.com/recipes.pdf",
)

agent = Agent(
    knowledge=knowledge,
    search_knowledge=True,
)

agent.print_response("How do I make pad thai?", markdown=True)

Multiple Sources

cookbook/07_knowledge/basic_operations/sync/04_from_multiple.py
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector

knowledge = Knowledge(
    vector_db=PgVector(table_name="docs", db_url="postgresql://..."),
)

# Add from multiple sources
knowledge.add_content(path="./documentation/")
knowledge.add_content(url="https://docs.example.com/api.pdf")
knowledge.add_content(topic="Python best practices")

Async Operations

cookbook/07_knowledge/basic_operations/async/01_from_path.py
import asyncio
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector

async def build_knowledge():
    knowledge = Knowledge(
        vector_db=PgVector(table_name="docs", db_url="postgresql://..."),
    )

    # Async content loading
    await knowledge.add_content_async(path="./large_docs/")

    return knowledge

knowledge = asyncio.run(build_knowledge())

Run Examples

git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/07_knowledge

# PgVector example
python vector_db/pgvector/pgvector_db.py

# Multiple sources
python basic_operations/sync/04_from_multiple.py

# Embedders
python embedders/openai_embedder.py