Agno is a Python framework for building multi-agent systems with shared memory, knowledge and reasoning.
Agno stores an agent's knowledge base in a vector database, and its SurrealDb class uses a SurrealDB table with an HNSW index for that. This page shows how to configure it. The tutorial Build an AI agent with Python has a complete program that loads a PDF of Thai recipes into the knowledge base and asks an agent a question about it.
Setup
Start a SurrealDB server that accepts the root user with the password secret, for example with Docker:
docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:latest start --user root --pass secretConfigure the vector database
Connect with the SurrealDB Python SDK, then pass the client to SurrealDb:
from agno.vectordb.surrealdb import SurrealDb
from surrealdb import Surreal
client = Surreal(url="ws://localhost:8000")
client.signin({"username": "root", "password": "secret"})
client.use(namespace="main", database="main")
surrealdb = SurrealDb(
client=client,
collection="recipes", # Table name for storing documents
efc=150, # HNSW construction time/accuracy trade-off
m=12, # HNSW max number of connections per element
search_ef=40, # HNSW search time/accuracy trade-off
)collection names the table that holds the documents and their embeddings. efc and m set the EFC and M parameters of the HNSW index, and search_ef sets the size of the candidate list that a search uses, as in the <|K,EF|> KNN operator. Larger values give more accurate results and make building the index or searching it slower.
Use it in a knowledge base
Pass the vector database to a knowledge base as its vector_db, together with an embedder such as OpenAIEmbedder(), and give the knowledge base to an Agent. Agno embeds the documents when the knowledge base loads, stores them in the recipes table, and searches the table when the agent needs context for a question.
Developer resources
View Cookbook (Sync)
View Cookbook (Async)
View Agno documentation