Setup
Install dependencies:uv pip install -U agno openai pypdf valkey-glide-sync
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
valkey/valkey-bundle Docker image which includes it:
docker run -d --name my-valkey \
-p 6379:6379 \
valkey/valkey-bundle
Example
agent_with_knowledge.py
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.valkey import ValkeyDB
from agno.vectordb.search import SearchType
# Initialize Valkey Vector DB
vector_db = ValkeyDB(
index_name="agno_docs",
host="localhost",
port=6379,
search_type=SearchType.vector,
)
# Build a Knowledge base backed by Valkey
knowledge = Knowledge(
name="My Valkey Knowledge Base",
description="Knowledge base using Valkey as the vector store",
vector_db=vector_db,
)
# Add content
knowledge.insert(
name="Recipes",
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
metadata={"category": "recipe_book"},
skip_if_exists=True,
)
# Query with an Agent
agent = Agent(knowledge=knowledge)
agent.print_response("List down the ingredients to make Massaman Gai", markdown=True)
Valkey Params
| Parameter | Type | Default | Description |
|---|---|---|---|
index_name | str | Required | Name of the Valkey search index to store vector data |
host | str | "localhost" | Valkey server host |
port | int | 6379 | Valkey server port |
username | Optional[str] | None | Username for authentication |
password | Optional[str] | None | Password for authentication |
use_tls | bool | False | Enable TLS encryption |
database_id | Optional[int] | None | Logical database index (e.g. 0-15) |
request_timeout | Optional[int] | None | Milliseconds to wait for a request to complete. If unset, the GLIDE client default (250 ms) applies |
client_name | str | "agno_vectordb_client" | Connection name, visible in CLIENT LIST |
glide_client | Optional[GlideClient] | None | Pre-configured Valkey GLIDE client instance |
embedder | Optional[Embedder] | None | Embedder instance to generate embeddings (defaults to OpenAIEmbedder() when unset) |
search_type | SearchType | SearchType.vector | Type of search to perform (vector, keyword) |
distance | Distance | Distance.cosine | Distance metric (cosine, l2, max_inner_product) |
vector_algorithm | str | "HNSW" | Vector index algorithm (HNSW or FLAT) |
reranker | Optional[Reranker] | None | Reranker for search results |
id | Optional[str] | None | Optional custom ID. If not provided, an ID will be generated |
name | Optional[str] | None | Optional name for the vector database |
description | Optional[str] | None | Optional description for the vector database |