Redis Vector / RedisVL
The official AI-native Python client for vector search on Redis. Wraps redis-py with a high-level interface for defining vector schemas, building HNSW/FLAT indexes, running hybrid search, semantic routing, LLM caching, and session memory. Requires Redis 7.2+ with Search & Query module, or Redis Stack (self-hosted), or Redis Cloud. The underlying redis-py client is a separate package ('redis') — redisvl depends on it. Import root is 'redisvl'. Maintained by Redis Inc.
Warnings
- breaking Plain redis (Redis OSS) does not support vector search. You must use Redis Stack, Redis Cloud, or Redis Enterprise — all of which include the Search & Query module. pip install redisvl succeeds but all index operations fail against plain Redis.
- breaking HybridQuery (native hybrid text+vector search) requires Redis 8.4.0+. Using it against Redis 7.x or 8.x < 8.4.0 raises a command error. AggregateHybridQuery is the backward-compatible alternative.
- breaking redis-py 6.0.0 introduced a client-side default dialect override (DIALECT 2) for FT.SEARCH and FT.AGGREGATE. This can change query results compared to older versions. Affects raw redis-py users who rely on default dialect behavior.
- gotcha COSINE distance in Redis uses the range [0, 2], not [0, 1]. 0 = identical, 2 = opposite. Documentation has historically stated [0, 1] in some places — this was incorrect. Fixed in redisvl release notes.
- gotcha Vectors must be stored as bytes (np.array(..., dtype='float32').tobytes()) for HASH storage type. Passing a Python list or numpy array directly to index.load() silently stores wrong data.
- gotcha redisvl previously had an unintentional dependency on botocore (AWS SDK). Any environment without boto would get an ImportError on redisvl.utils.vectorize. Fixed in a patch release.
Install
-
pip install redisvl -
pip install redisvl[openai] -
pip install redisvl[all] -
pip install redisvl[hiredis] -
docker run -d --name redis -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
Imports
- SearchIndex
from redisvl.index import SearchIndex
- VectorQuery
from redisvl.query import VectorQuery
- IndexSchema
from redisvl.schema import IndexSchema
Quickstart
import numpy as np
from redis import Redis
from redisvl.index import SearchIndex
from redisvl.schema import IndexSchema
from redisvl.query import VectorQuery
# Define schema
schema = IndexSchema.from_dict({
"index": {"name": "docs", "prefix": "doc", "storage_type": "hash"},
"fields": [
{"name": "text", "type": "text"},
{
"name": "embedding",
"type": "vector",
"attrs": {
"algorithm": "hnsw",
"datatype": "float32",
"dims": 4,
"distance_metric": "cosine"
}
}
]
})
# Connect and create index
index = SearchIndex(schema, redis_url="redis://localhost:6379")
index.create(overwrite=True)
# Load data
index.load([
{"id": "1", "text": "hello world", "embedding": np.array([0.1, 0.2, 0.3, 0.4], dtype='float32').tobytes()},
])
# Search
query = VectorQuery(
vector=[0.1, 0.2, 0.3, 0.4],
vector_field_name="embedding",
num_results=5
)
results = index.query(query)
print(results)