redisvl
Python client library and CLI for using Redis as a vector database
Description
Documentation • Recipes • GitHub
</div>Introduction
Redis Vector Library (RedisVL) is the production-ready Python client for AI applications built on Redis. Lightning-fast vector search meets enterprise-grade reliability.
Perfect for building RAG pipelines with real-time retrieval, AI agents with memory and semantic routing, and recommendation systems with fast search and reranking.
<div align="center">| 🎯 Core Capabilities | 🚀 AI Extensions | 🛠️ Dev Utilities |
|---|---|---|
| Index Management<br/>Schema design, data loading, CRUD ops | Semantic Caching<br/>Reduce LLM costs & boost throughput | CLI<br/>Index management from terminal |
| Vector Search<br/>Similarity search with metadata filters | LLM Memory<br/>Agentic AI context management | Async Support<br/>Async indexing and search for improved performance |
| Complex Filtering<br/>Combine multiple filter types | Semantic Routing<br/>Intelligent query classification | Vectorizers<br/>8+ embedding provider integrations |
| Hybrid Search<br/>Combine semantic & full-text signals | Embedding Caching<br/>Cache embeddings for efficiency | Rerankers<br/>Improve search result relevancy |
💪 Getting Started
Installation
Install redisvl into your Python (>=3.9) environment using pip:
pip install redisvl
For more detailed instructions, visit the installation guide.
Redis
Choose from multiple Redis deployment options:
<details> <summary><b>Redis Cloud</b> - Managed cloud database (free tier available)</summary>Redis Cloud offers a fully managed Redis service with a free tier, perfect for getting started quickly.
</details> <details> <summary><b>Docker</b> - Local development</summary>Run Redis locally using Docker:
docker run -d --name redis -p 6379:6379 redis:latest
This runs Redis 8+ with built-in vector search capabilities.
</details> <details> <summary><b>Redis Enterprise</b> - Commercial, self-hosted database</summary>Redis Enterprise provides enterprise-grade features for production deployments.
</details> <details> <summary><b>Redis Sentinel</b> - High availability with automatic failover</summary>Configure Redis Sentinel for high availability:
# Connect via Sentinel
redis_url="redis+sentinel://sentinel1:26379,sentinel2:26379/mymaster"
</details>
<details>
<summary><b>Azure Managed Redis</b> - Fully managed Redis Enterprise on Azure</summary>
Azure Managed Redis provides fully managed Redis Enterprise on Microsoft Azure.
</details>💡 Tip: Enhance your experience and observability with the free Redis Insight GUI.
Overview
Index Management
-
Design a schema for your use case that models your dataset with built-in Redis indexable fields (e.g. text, tags, numerics, geo, and vectors).
<details> <summary><b>Load schema from YAML file</b></summary>index: name: user-idx prefix: user storage_type: json fields: - name: user type: tag - name: credit_score type: tag - name: job_title type: text attrs: sortable: true no_index: false # Index for search (default) unf: false # Normalize case for sorting (default) - name: embedding type: vector attrs: algorithm: flat dims: 4 distance_metric: cosine datatype: float32
</details> <details> <summary><b>Load schema from Python dictionary</b></summary>from redisvl.schema import IndexSchema schema = IndexSchema.from_yaml("schemas/schema.yaml")
</details>from redisvl.schema import IndexSchema schema = IndexSchema.from_dict({ "index": { "name": "user-idx", "prefix": "user", "storage_type": "json" }, "fields": [ {"name": "user", "type": "tag"}, {"name": "credit_score", "type": "tag"}, { "name": "job_title", "type": "text", "attrs": { "sortable": True, "no_index": False, # Index for search "unf": False # Normalize case for sorting } }, { "name": "embedding", "type": "vector", "attrs": { "algorithm": "flat", "datatype": "float32", "dims": 4, "distance_metric": "cosine" } } ] })📚 Learn more about schema design and schema creation.
-
Create a SearchIndex class with an input schema to perform admin and search operations on your index in Redis:
from redis import Redis from redisvl.index import SearchIndex # Define the index index = SearchIndex(schema, redis_url="redis://localhost:6379") # Create the index in Redis index.create()An async-compatible index class also available: AsyncSearchIndex.
-
Load and fetch data to/from your Redis instance:
data = {"user": "john", "credit_score": "high", "embedding": [0.23, 0.49, -0.18, 0.95]} # load list of dictionaries, specify the "id" field index.load([data], id_field="user") # fetch by "id" john = index.fetch("john")
Retrieval
Define queries and perform advanced searches over your indices, including vector search, complex filtering, and hybrid search combining semantic and full-text signals.
<details> <summary><b>Quick Reference: Query Types</b></summary>| Query Type | Use Case | Description |
|---|---|---|
VectorQuery | Semantic similarity search | Find similar vectors with optional filters |
RangeQuery | Distance-based search | Vector search within a defined distance range |
FilterQuery | Metadata filtering | Filter and search using metadata fields |
TextQuery | Full-text search | BM25-based keyword search with field weighting |
HybridQuery | Combined search | Combine semantic + full-text signals (Redis 8.4.0+) |
CountQuery | Counting records | Count documents matching filter criteria |
Vector Search
-
VectorQuery - Flexible vector queries with customizable filters enabling semantic search:
from redisvl.query import VectorQuery query = VectorQuery( vector=[0.16, -0.34, 0.98, 0.23], vector_field_name="embedding", num_results=3, # Optional: tune search performance with runtime parameters ef_runtime=100 # HNSW: higher for better recall ) # run the vector search query against the embedding field results = index.query(query) -
RangeQuery - Vector search within a defined range paired with customizable filters
Complex Filtering
Build complex filtering queries by combining multiple filter types (tags, numerics, text, geo, timestamps) using logical operators:
```python
from redisvl.query import VectorQuery
from redisvl.query.filter import Tag, Num
# Combine multiple filter types
tag_filter = Tag("user") == "john"
price_filter = Num("price") >= 100
# Create complex filtering query with combined filters
query = VectorQuery(
vector=[0.16, -0.34, 0.98, 0.23],
vector_field_name="embedding",
filter_expression=tag_filter & price_filter,
num_results=10
)
results = index.query(query)
```
- FilterQuery - Standard search using filters and