Agno has a generic knowledge solution that supports many forms of content.See more details in the knowledge documentation.
Example: Say we are building a Text2Sql Agent, we’ll need to give the table schemas, column names, data types, example queries, etc to the agent to help it generate the best-possible SQL query.It is not viable to put this all in the system message, instead we store this information as knowledge and let the Agent query it at runtime.Using this information, the Agent can then generate the best-possible SQL query. This is called dynamic few-shot learning.
Knowledge for Agents
Agno Agents use Agentic RAG by default, meaning when we provideknowledge
to an Agent, it will search this knowledge base, at runtime, for the specific information it needs to achieve its task.
For example:
- We can set
search_knowledge=True
to add asearch_knowledge_base()
tool to the Agent.search_knowledge
isTrue
by default if you addknowledge
to an Agent. - We can set
add_knowledge_to_context=True
to automatically add references from the knowledge base to the Agent’s context, based in your user message. This is the traditional RAG approach.
Custom knowledge retrieval
If you need complete control over the knowledge base search, you can pass your ownknowledge_retriever
function with the following signature:
search_knowledge_base()
and is used by the Agent to retrieve references from the knowledge base.
Async retrievers are supported. Simply create an async function and pass it to
the
knowledge_retriever
parameter.Knowledge storage
Knowledge content is tracked in a “Contents DB” and vectorized and stored in a “Vector DB”.Contents database
The Contents DB is a database that stores the name, description, metadata and other information for any content you add to the knowledge base. Below is the schema for the Contents DB:Field | Type | Description |
---|---|---|
id | str | The unique identifier for the knowledge content. |
name | str | The name of the knowledge content. |
description | str | The description of the knowledge content. |
metadata | dict | The metadata for the knowledge content. |
type | str | The type of the knowledge content. |
size | int | The size of the knowledge content. Applicable only to files. |
linked_to | str | The ID of the knowledge content that this content is linked to. |
access_count | int | The number of times this content has been accessed. |
status | str | The status of the knowledge content. |
status_message | str | The message associated with the status of the knowledge content. |
created_at | int | The timestamp when the knowledge content was created. |
updated_at | int | The timestamp when the knowledge content was last updated. |
external_id | str | The external ID of the knowledge content. Used when external vector stores are used, like LightRAG. |
Vector databases
Vector databases offer the best solution for retrieving relevant results from dense information quickly.Adding contents
The typical way content is processed when being added to the knowledge base is:1
Parse the content
A reader is used to parse the content based on the type of content that is
being inserted
2
Chunk the information
The content is broken down into smaller chunks to ensure our search query
returns only relevant results.
3
Embed each chunk
The chunks are converted into embedding vectors and stored in a vector
database.
See more details on Loading the Knowledge
Base.
Knowledge filters are currently supported on the following knowledge base
types: PDF, PDF_URL, Text, JSON, and DOCX.
For more details, see the Knowledge Filters
documentation.
Example: Agentic RAG Agent
Let’s build a RAG Agent that answers questions from a PDF.1
Set up the database
Let’s use Install required packages:
Postgres
as both our contents and vector databases.Install docker desktop and run Postgres on port 5532 using:This docker container contains a general purpose Postgres database with the
pgvector
extension installed.2
Do agentic RAG
Create a file
agentic_rag.py
with the following contentsagentic_rag.py
3
Run the agent
Run the agent
Developer Resources
- View the Agent schema
- View the Knowledge schema
- View Cookbook