Redis
Insert a PDF into a Redis knowledge base, query it with an agent, and delete content by name.
Code
import os
from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.redis import RedisDB, SearchType
# Configure Redis connection
REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379/0")
INDEX_NAME = os.getenv("REDIS_INDEX", "agno_cookbook_vectors")
# Initialize Redis Vector DB
vector_db = RedisDB(
index_name=INDEX_NAME,
redis_url=REDIS_URL,
search_type=SearchType.vector, # try SearchType.hybrid for hybrid search
)
contents_db = PostgresDb(
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
knowledge_table="knowledge_contents",
)
knowledge = Knowledge(
name="My Redis Vector Knowledge Base",
description="This is a knowledge base that uses a Redis Vector DB",
vector_db=vector_db,
contents_db=contents_db,
)
knowledge.insert(
name="Recipes",
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
metadata={"doc_type": "recipe_book"},
)
agent = Agent(knowledge=knowledge)
agent.print_response("List down the ingredients to make Massaman Gai", markdown=True)
vector_db.delete_by_name("Recipes")
Redis metadata deletion requires tag fields that are both stored on each vector document and indexed. The adapter does not index doc_type, and this URL-ingestion path does not merge the caller metadata into each stored vector document. Use the demonstrated delete_by_name for these recipe chunks.
Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U redis redisvl sqlalchemy psycopg pypdf openai agnoRun Redis
docker run -d --name my-redis -p 6379:6379 -p 8001:8001 redis/redis-stack:latestRun PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql \
-v pgvolume:/var/lib/postgresql \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18Set environment variables
export OPENAI_API_KEY=xxxRun Agent
python redis_db.py