Skip to main content
You can use Valkey as a vector database with Agno using the valkey-search module.

Setup

Valkey vector search requires the valkey-search module. Use the 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

ParameterTypeDefaultDescription
index_namestrRequiredName of the Valkey search index to store vector data
hoststr"localhost"Valkey server host
portint6379Valkey server port
usernameOptional[str]NoneUsername for authentication
passwordOptional[str]NonePassword for authentication
use_tlsboolFalseEnable TLS encryption
database_idOptional[int]NoneLogical database index (e.g. 0-15)
request_timeoutOptional[int]NoneMilliseconds to wait for a request to complete. If unset, the GLIDE client default (250 ms) applies
client_namestr"agno_vectordb_client"Connection name, visible in CLIENT LIST
glide_clientOptional[GlideClient]NonePre-configured Valkey GLIDE client instance
embedderOptional[Embedder]NoneEmbedder instance to generate embeddings (defaults to OpenAIEmbedder() when unset)
search_typeSearchTypeSearchType.vectorType of search to perform (vector, keyword)
distanceDistanceDistance.cosineDistance metric (cosine, l2, max_inner_product)
vector_algorithmstr"HNSW"Vector index algorithm (HNSW or FLAT)
rerankerOptional[Reranker]NoneReranker for search results
idOptional[str]NoneOptional custom ID. If not provided, an ID will be generated
nameOptional[str]NoneOptional name for the vector database
descriptionOptional[str]NoneOptional description for the vector database