- Notifications
You must be signed in to change notification settings - Fork55
Redis Vector Library (RedisVL) -- the AI-native Python client for Redis.
License
redis/redis-vl-python
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Redis Vector Library (RedisVL) is the production-ready Python client for AI applications built on Redis.Lightning-fast vector search meets enterprise-grade reliability.
🎯 Core Capabilities | 🚀 AI Extensions | 🛠️ Dev Utilities |
---|---|---|
Index Management Schema design, data loading, CRUD ops | Semantic Caching Reduce LLM costs & boost throughput | CLI Index management from terminal |
Vector Search Similarity search with metadata filters | LLM Memory Agentic AI context management | Async Support Async indexing and search for improved performance |
Hybrid Queries Vector + text + metadata combined | Semantic Routing Intelligent query classification | Vectorizers 8+ embedding provider integrations |
Multi-Query Types Vector, Range, Filter, Count queries | Embedding Caching Cache embeddings for efficiency | Rerankers Improve search result relevancy |
- RAG Pipelines → Real-time retrieval with hybrid search capabilities
- AI Agents → Short term & long term memory and semantic routing for intent-based decisions
- Recommendation Systems → Fast retrieval and reranking
Installredisvl
into your Python (>=3.9) environment usingpip
:
pip install redisvl
For more detailed instructions, visit theinstallation guide.
Choose from multiple Redis deployment options:
- Redis Cloud: Managed cloud database (free tier available)
- Redis Stack: Docker image for development
docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
- Redis Enterprise: Commercial, self-hosted database
- Azure Managed Redis: Fully managed Redis Enterprise on Azure
Enhance your experience and observability with the freeRedis Insight GUI.
Design a schema for your use case that models your dataset with built-in Redis and indexable fields (e.g. text, tags, numerics, geo, and vectors).Load a schema from a YAML file:
index:name:user-idxprefix:userstorage_type:jsonfields: -name:usertype:tag -name:credit_scoretype:tag -name:embeddingtype:vectorattrs:algorithm:flatdims:4distance_metric:cosinedatatype:float32
fromredisvl.schemaimportIndexSchemaschema=IndexSchema.from_yaml("schemas/schema.yaml")
Or load directly from a Python dictionary:
schema=IndexSchema.from_dict({"index": {"name":"user-idx","prefix":"user","storage_type":"json" },"fields": [ {"name":"user","type":"tag"}, {"name":"credit_score","type":"tag"}, {"name":"embedding","type":"vector","attrs": {"algorithm":"flat","datatype":"float32","dims":4,"distance_metric":"cosine" } } ]})
Create a SearchIndex class with an input schema to perform admin and search operations on your index in Redis:
fromredisimportRedisfromredisvl.indeximportSearchIndex# Define the indexindex=SearchIndex(schema,redis_url="redis://localhost:6379")# Create the index in Redisindex.create()
An async-compatible index class also available:AsyncSearchIndex.
Loadandfetch 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" fieldindex.load([data],id_field="user")# fetch by "id"john=index.fetch("john")
Define queries and perform advanced searches over your indices, including the combination of vectors, metadata filters, and more.
VectorQuery - Flexible vector queries with customizable filters enabling semantic search:
fromredisvl.queryimportVectorQueryquery=VectorQuery(vector=[0.16,-0.34,0.98,0.23],vector_field_name="embedding",num_results=3)# run the vector search query against the embedding fieldresults=index.query(query)
Incorporate complex metadata filters on your queries:
fromredisvl.query.filterimportTag# define a tag match filtertag_filter=Tag("user")=="john"# update query definitionquery.set_filter(tag_filter)# execute queryresults=index.query(query)
RangeQuery - Vector search within a defined range paired with customizable filters
FilterQuery - Standard search using filters and the full-text search
CountQuery - Count the number of indexed records given attributes
Read more about buildingadvanced Redis queries.
Integrate with popular embedding providers to greatly simplify the process of vectorizing unstructured data for your index and queries:
fromredisvl.utils.vectorizeimportCohereTextVectorizer# set COHERE_API_KEY in your environmentco=CohereTextVectorizer()embedding=co.embed(text="What is the capital city of France?",input_type="search_query")embeddings=co.embed_many(texts=["my document chunk content","my other document chunk content"],input_type="search_document")
Learn more about using vectorizers in your embedding workflows.
Integrate with popular reranking providers to improve the relevancy of the initial search results from Redis
We're excited to announce the support forRedisVL Extensions. These modules implement interfaces exposing best practices and design patterns for working with LLM memory and agents. We've taken the best from what we've learned from our users (that's you) as well as bleeding-edge customers, and packaged it up.
Have an idea for another extension? Open a PR or reach out to us atapplied.ai@redis.com. We're always open to feedback.
Increase application throughput and reduce the cost of using LLM models in production by leveraging previously generated knowledge with theSemanticCache
.
fromredisvl.extensions.cache.llmimportSemanticCache# init cache with TTL and semantic distance thresholdllmcache=SemanticCache(name="llmcache",ttl=360,redis_url="redis://localhost:6379",distance_threshold=0.1)# store user queries and LLM responses in the semantic cachellmcache.store(prompt="What is the capital city of France?",response="Paris")# quickly check the cache with a slightly different prompt (before invoking an LLM)response=llmcache.check(prompt="What is France's capital city?")print(response[0]["response"])
>>> Paris
Learn more about semantic caching for LLMs.
Reduce computational costs and improve performance by caching embedding vectors with their associated text and metadata using theEmbeddingsCache
.
fromredisvl.extensions.cache.embeddingsimportEmbeddingsCachefromredisvl.utils.vectorizeimportHFTextVectorizer# Initialize embedding cacheembed_cache=EmbeddingsCache(name="embed_cache",redis_url="redis://localhost:6379",ttl=3600# 1 hour TTL)# Initialize vectorizer with cachevectorizer=HFTextVectorizer(model="sentence-transformers/all-MiniLM-L6-v2",cache=embed_cache)# First call computes and caches the embeddingembedding=vectorizer.embed("What is machine learning?")# Subsequent calls retrieve from cache (much faster!)cached_embedding=vectorizer.embed("What is machine learning?")
>>> Cache hit! Retrieved from Redis in <1ms
Learn more aboutembedding caching for improved performance.
Improve personalization and accuracy of LLM responses by providing user conversation context. Manage access to memory data using recency or relevancy,powered by vector search with theMessageHistory
.
fromredisvl.extensions.message_historyimportSemanticMessageHistoryhistory=SemanticMessageHistory(name="my-session",redis_url="redis://localhost:6379",distance_threshold=0.7)history.add_messages([ {"role":"user","content":"hello, how are you?"}, {"role":"assistant","content":"I'm doing fine, thanks."}, {"role":"user","content":"what is the weather going to be today?"}, {"role":"assistant","content":"I don't know"}])
Get recent chat history:
history.get_recent(top_k=1)
>>> [{"role": "assistant", "content": "I don't know"}]
Get relevant chat history (powered by vector search):
history.get_relevant("weather",top_k=1)
>>> [{"role": "user", "content": "what is the weather going to be today?"}]
Learn more about LLM memory.
Build fast decision models that run directly in Redis and route user queries to the nearest "route" or "topic".
fromredisvl.extensions.routerimportRoute,SemanticRouterroutes= [Route(name="greeting",references=["hello","hi"],metadata={"type":"greeting"},distance_threshold=0.3, ),Route(name="farewell",references=["bye","goodbye"],metadata={"type":"farewell"},distance_threshold=0.3, ),]# build semantic router from routesrouter=SemanticRouter(name="topic-router",routes=routes,redis_url="redis://localhost:6379",)router("Hi, good morning")
>>> RouteMatch(name='greeting', distance=0.273891836405)
Learn more aboutsemantic routing.
Create, destroy, and manage Redis index configurations from a purpose-built CLI interface:rvl
.
$ rvl -husage: rvl<command> [<args>]Commands: index Index manipulation (create, delete, etc.) version Obtain the version of RedisVL stats Obtain statistics about an index
Read more aboutusing the CLI.
Redis is a proven, high-performance database that excels at real-time workloads. With RedisVL, you get a production-ready Python client that makes Redis's vector search, caching, and session management capabilities easily accessible for AI applications.
Built on theRedis Python client, RedisVL provides an intuitive interface for vector search, LLM caching, and conversational AI memory - all the core components needed for modern AI workloads.
For additional help, check out the following resources:
Please help us by contributing PRs, opening GitHub issues for bugs or new feature ideas, improving documentation, or increasing test coverage.Read more about how to contribute!
This project is supported byRedis, Inc on a good faith effort basis. To report bugs, request features, or receive assistance, pleasefile an issue.
About
Redis Vector Library (RedisVL) -- the AI-native Python client for Redis.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.