Redis Vector / RedisVL

0.14.1 · active · verified Sat Feb 28

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

Install

Imports

Quickstart

Requires Redis Stack or Redis Cloud running locally. Vectors stored as bytes (float32.tobytes()) in HASH storage. HNSW index supports incremental inserts. Use AsyncSearchIndex for async workflows.

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)

view raw JSON →