What is RedisVL?

CK CK 3788 
Created at  
117 0 0

RedisVL (Redis Vector Library) is an official Python client library designed to simplify using Redis as a vector database. It provides an intuitive, high-level interface for AI/ML developers to manage vector schemas, create indexes, store embeddings, and perform real-time semantic searches (Vector Search) and Retrieval-Augmented Generation (RAG) workflows.

What is RedisVL?

 

Key Features

  • Schema Management: Simple YAML or dictionary-based schema definitions for document attributes and vector fields.
  • Integrated Vectorizers: Native integrations with popular embedding providers (OpenAI, HuggingFace, Cohere, VertexAI) to automatically generate vectors.
  • Efficient Search: Built-in support for K-Nearest Neighbors (KNN), range queries, and hybrid search (combining metadata filtering with vector similarity).
  • Async & Sync Support: Supports both synchronous and asynchronous operations for high-throughput applications.


 

Prerequisites & Environment

To use RedisVL, you need both a Python environment and a running instance of Redis equipped with vector search capabilities.

 

1. Python Environment

  • Python Version: 3.8 or higher.

 

2. Redis Database Requirement

Standard Redis OSS does not include vector search capabilities. You must run Redis Stack or Redis Enterprise, which includes the required search (RediSearch) and JSON modules.

 

 

Local Setup via Docker (Recommended)

The fastest way to set up a compatible Redis instance is using Docker:

docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
  • Port 6379: Redis Database server.
  • Port 8001: Redis Insight (GUI web interface accessible via browser).

 

Installation

Install RedisVL via pip:

# Basic installation
pip install redisvl

# Optional: Install with specific vectorizer support (e.g., OpenAI or Sentence-Transformers)
pip install redisvl[openai]
pip install sentence-transformers

 

 

How Embeddings Are Generated

RedisVL provides built-in Vectorizer classes within the redisvl.utils.vectorize module. You do not need to write custom pipeline code to convert text into embeddings; RedisVL handles the transformation directly.

 

Supported Vectorizers:

  • OpenAIVectorizer: Uses OpenAI's API (text-embedding-3-small, text-embedding-ada-002, etc.).
  • HFTextVectorizer: Runs HuggingFace models locally via sentence-transformers.
  • CohereVectorizer: Uses Cohere's embedding API.
  • VertexAIVectorizer: Uses Google Cloud Vertex AI.

 

Vectorizer Usage Example:

from redisvl.utils.vectorize import HFTextVectorizer, OpenAIVectorizer

# Option 1: Local HuggingFace Model (No API key required)
hf_vectorizer = HFTextVectorizer(model="sentence-transformers/all-MiniLM-L6-v2")
vector = hf_vectorizer.embed("RedisVL makes vector search easy.")

# Option 2: OpenAI API (Requires OPENAI_API_KEY environment variable)
# openai_vectorizer = OpenAIVectorizer(model="text-embedding-3-small")
# vector = openai_vectorizer.embed("RedisVL makes vector search easy.")

print(f"Vector dimension: {len(vector)}")
print(f"Sample vector data: {vector[:3]}...")


 

Usage Sample Code

Here is a complete end-to-end example demonstrating how to define a schema, initialize an index, generate embeddings, store documents, and perform vector similarity queries.

import os
from redisvl.index import SearchIndex
from redisvl.query import VectorQuery
from redisvl.utils.vectorize import HFTextVectorizer

# ------------------------------------------------------------------
# 1. Initialize the Vectorizer
# ------------------------------------------------------------------
# We will use a lightweight HuggingFace model running locally
vectorizer = HFTextVectorizer(model="sentence-transformers/all-MiniLM-L6-v2")

# ------------------------------------------------------------------
# 2. Define Index Schema
# ------------------------------------------------------------------
schema = {
    "index": {
        "name": "tech_docs",
        "prefix": "doc",
    },
    "fields": [
        {"name": "doc_id", "type": "tag"},
        {"name": "category", "type": "tag"},
        {"name": "content", "type": "text"},
        {
            "name": "content_vector",
            "type": "vector",
            "attrs": {
                "dims": 384,  # Matches all-MiniLM-L6-v2 dimension output
                "algorithm": "hnsw",
                "distance_metric": "cosine"
            }
        }
    ]
}

# ------------------------------------------------------------------
# 3. Create Index and Connect to Redis
# ------------------------------------------------------------------
index = SearchIndex.from_dict(schema)
index.connect("redis://localhost:6379")

# Create the index in Redis (overwrites if it already exists)
index.create(overwrite=True)

# ------------------------------------------------------------------
# 4. Prepare and Insert Data (with Embeddings)
# ------------------------------------------------------------------
data = [
    {"doc_id": "1", "category": "database", "content": "Redis is an in-memory data structure store used as a database, cache, and message broker."},
    {"doc_id": "2", "category": "database", "content": "PostgreSQL is a powerful, open-source object-relational database system."},
    {"doc_id": "3", "category": "ai", "content": "Large language models require fast vector databases for context retrieval in RAG systems."}
]

# Generate vectors for each document
for item in data:
    item["content_vector"] = vectorizer.embed(item["content"])

# Load data into Redis
keys = index.load(data, id_field="doc_id")
print(f"Successfully loaded {len(keys)} documents into Redis.")

# ------------------------------------------------------------------
# 5. Perform Vector Search (KNN Query)
# ------------------------------------------------------------------
user_query = "What database is best for fast caching?"

# Embed the query text
query_vector = vectorizer.embed(user_query)

# Build a Vector Query to find the top 2 most similar documents
query = VectorQuery(
    vector=query_vector,
    vector_field_name="content_vector",
    return_fields=["doc_id", "category", "content"],
    num_results=2
)

# Execute search
results = index.query(query)

# Print results
print("\n--- Search Results ---")
for doc in results:
    print(f"ID: {doc['doc_id']} | Category: {doc['category']}")
    print(f"Content: {doc['content']}")
    print(f"Score (Distance): {doc['vector_distance']}\n")

# ------------------------------------------------------------------
# 6. Cleanup (Optional)
# ------------------------------------------------------------------
# index.delete(drop_attributes=True)

 

Does the embedding value created using RedisVL always produce the same result for the same input, and can it be searched using Similarity Search?

The embeddings generated using RedisVL are deterministic and will always yield the exact same vector for identical inputs, provided the underlying embedding model and configurations remain unchanged. Furthermore, RedisVL fully supports vector similarity searches, enabling you to store these generated embeddings in Redis and efficiently perform vector similarity queries using distance metrics such as cosine similarity or Euclidean distance to retrieve the most semantically relevant results.

Tags AI Embeddings Deterministic Embeddings Embedding Consistency Embeddings Redis Vector Database RedisVL Semantic Search Similarity Search Vector Database Vector Embeddings Vector Search Facebook X
Comments 0
Similar posts
  1. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    303
  2. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    247
  3. Designing a Data Curation System Around a Vector Database
    230
  4. Embeddings on the Lakehouse: What Snowflake and Databricks Actually Do (and Don't)
    303
  5. Vector Database Integration on Fully Managed Multi-Agent Environment
    319
  6. Demystifying FAISS: Your Guide to ANN(Approximate Nearest Neighbor) Search
    327
  7. Your Blueprint for an LLM & Vector DB Insurance Product Q&A
    267
  8. The Core of Vector Databases: Embeddings and LLM Dependency
    267
  9. Architecting ML/LLM Ad Targeting with Kafka, Flink, FAISS, and Milvus
    285
  10. Integrating VectorDB stored in S3 with Amazon Bedrock
    429
  11. Milvus and LLM Integration - Very Smart Approach!
    304
  12. Why Reranking is Crucial for RAG and Agentic AI Systems?
    276
  13. Understanding Elasticsearch from Installation to Trouble Shooting
    915
  14. Getting Started with FAISS: A CentOS 7 Installation Guide
    288
  15. Milvus & FAISS: Decoding Their ML Synergy
    286
  16. FAISS Already Does ANN... So Why Do Top Teams Still Pay for SageMaker?
    314
  17. Recommended Vector DB Structure for Amazon Bedrock Integration
    393
  18. Deep Dive into Vector Databases: Understanding Collections (Not Tables) and Embeddings
    240
  19. Image Embeddings for Vector Databases
    257
  20. Vector Databases: From Embeddings to Application
    323
  21. Two-Tower Model for Recommendation Service having a Very Large Catalog
    271
  22. Content-Based Filtering for Recommendation Service (aka User-based Model)
    194
  1. What “GPU Clustering” Really Means (And How to Code for It)
    215
  2. How to Build a Python Chatbot That Writes and Runs Code Using Microsoft AutoGen (With Sample Code)
    244
  3. Beyond Prompt Engineering: Why Loop Engineering is the Future of Autonomous AI
    310
  4. A Python Code to get the Server Instance ID for Remote Management
    366
  5. From Local Python Web to Standalone
    2,056
  6. TensorRT for LLMs: Speed, Scale, and Why Startups Choose It Over TensorFlow
    467
  7. Python ML Technologies used for the target Segmentation
    381
  8. Managing WHITE_LIST in FastAPI to Improve the Server Security
    355
  9. A common async example
    990
  10. Automated API Documentation with PyCharm
    896
  11. How to install python 3.9 alongside python 3.8 on CentOS 7?
    719
  12. How to run Python 3.9 on Mac?
    656
  13. Python Quizs
    502
  14. Automated OpenAPI documentation for a Python Flask API
    1,127
  15. Automated API documentation for a Django REST Framework (DRF) project using drf-yasg (Yet Another Swagger Generator)
    1,033
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    31
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    57
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    51
  4. How do I create animated background for Google Meet?
    23,252
  5. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    273
  6. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    104
  7. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    170
  8. Array of arguments passed to script in PHP
    99
  9. Invalid Auction Storms in Ad Tech
    107
  10. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    209
  11. The Two Clocks of Ad Server Architecture
    78
  12. Frequency Cap Architecture Overview
    527
  13. Collecting Proof-of-Play from 100,000 Screens
    153
  14. TPU & GPU Cluster Management Tools
    258
  15. The Concept of Scaffolding in AI Agents
    245
  16. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    598
  17. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    269
  18. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    355
  19. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    207
  20. Machine Learning: Training vs. Ranking
    230
  21. The Continuous Learning Machine: Designing a Loop That Actually Turns
    229
  22. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    204
  23. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  24. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    674
  25. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    201
  26. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    233
  27. Understanding Data Lineage
    272
  28. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    176
  29. GPU & LLM Cluster Infrastructure & Task Scheduling Architecture
    255
  30. Java Variant Type
    213