Package: redisvl
🔥 Redis Vector Librarythe AI-native Redis Python clientHomeDocumentationMore ProjectsIntroductionThe Python Redis Vector Library (RedisVL) is a tailor-made client for AI applications leveragingRedis.It's specifically designed for:Information retrieval & vector similarity searchReal-time RAG pipelinesRecommendation enginesEnhance your applications with Redis'speed,flexibility, andreliability, incorporating capabilities like vector-based semantic search, full-text search, and geo-spatial search.🚀 Why RedisVL?The emergence of the modern GenAI stack, includingvector databasesandLLMs, has become increasingly popular due to accelerated innovation & research in information retrieval, the ubiquity of tools & frameworks (e.g.LangChain,LlamaIndex,EmbedChain), and the never-ending stream of business problems addressable by AI.However, organizations still struggle with delivering reliable solutionsquickly(time to value) atscale(beyond a demo).Redishas been a staple for over a decade in the NoSQL world, and boasts a number of flexibledata structuresandprocessing enginesto handle realtime application workloads like caching, session management, and search. Most notably, Redis has been used as a vector database for RAG, as an LLM cache, and chat session memory store for conversational AI applications.The vector librarybridges the gap betweenthe emerging AI-native developer ecosystem and the capabilities of Redis by providing a lightweight, elegant, and intuitive interface. Built on the back of the popular Python client,redis-py, it abstracts the features Redis into a grammar that is more aligned to the needs of today's AI/ML Engineers or Data Scientists.💪 Getting StartedInstallationInstallredisvlinto your Python (>=3.8) environment usingpip:pipinstallredisvlFor more instructions, visit theredisvlinstallation guide.Setting up RedisChoose from multiple Redis deployment options:Redis Cloud: Managed cloud database (free tier available)Redis Stack: Docker image for developmentdockerrun-d--nameredis-stack-p6379:6379-p8001:8001redis/redis-stack:latestRedis Enterprise: Commercial, self-hosted databaseEnhance your experience and observability with the freeRedis Insight GUI.What's included?🗃️ Redis Index ManagementDesign anIndexSchemathat models your dataset with built-in Redisdata structures(Hash or JSON) and indexable fields (e.g. text, tags, numerics, geo, and vectors).Load a schemafrom aYAML file:index:name:user-index-v1prefix:userstorage_type:jsonfields:-name:usertype:tag-name:credit_scoretype:tag-name:embeddingtype:vectorattrs:algorithm:flatdims:3distance_metric:cosinedatatype:float32fromredisvl.schemaimportIndexSchemaschema=IndexSchema.from_yaml("schemas/schema.yaml")Or load directly from a Python dictionary:schema=IndexSchema.from_dict({"index":{"name":"user-index-v1","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 SearchIndexclass with an input schema and client connection in order to perform admin and search operations on your index in Redis:fromredisimportRedisfromredisvl.indeximportSearchIndex# Establish Redis connection and define indexclient=Redis.from_url("redis://localhost:6379")index=SearchIndex(schema,client)# Create the index in Redisindex.create()Async compliant search index class also available:AsyncSearchIndexLoadandfetchdata 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")🔍 Realtime SearchDefine 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 filtersFilterQuery- Standard search using filters and the full-text searchCountQuery- Count the number of indexed records given attributesRead more about building advanced Redis querieshere.🖥️ Command Line InterfaceCreate, destroy, and manage Redis index configurations from a purpose-built CLI interface:rvl.$rvl-h

usage:rvl<command>[<args>]Commands:indexIndexmanipulation(create,delete,etc.)versionObtaintheversionofRedisVLstatsObtainstatisticsaboutanindexRead more about using theredisvlCLIhere.⚡  Community IntegrationsIntegrate with popular embedding models and providers to greatly simplify the process of vectorizing unstructured data for your index and queries:CohereOpenAIHuggingFaceGCP VertexAIfromredisvl.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 usingredisvlVectorizers in your workflowshere.💫 Beyond Vector SearchIn order to perform well in production, modern GenAI applications require much more than vector search for retrieval.redisvlprovides some common extensions that
aim to improve applications working with LLMs:LLM Semantic Cachingis designed to increase application throughput and reduce the cost of using LLM models in production by leveraging previously generated knowledge.fromredisvl.extensions.llmcacheimportSemanticCache# init cache with TTL (expiration) policy and semantic distance threshholdllmcache=SemanticCache(name="llmcache",ttl=360,redis_url="redis://localhost:6379")llmcache.set_threshold(0.2)# can be changed on-demand# store user queries and LLM responses in the semantic cachellmcache.store(prompt="What is the capital city of France?",response="Paris",metadata={})# quickly check the cache with a slightly different prompt (before invoiking an LLM)response=llmcache.check(prompt="What is France's capital city?")print(response[0]["response"])>>> "Paris"Learn more about Semantic Cachinghere.LLM Session Management (COMING SOON)aims to improve personalization and accuracy of the LLM application by providing user chat session information and conversational memory.LLM Contextual Access Control (COMING SOON)aims to improve security concerns by preventing malicious, irrelevant, or problematic user input from reaching LLMs and infrastructure.Helpful LinksTo get started, check out the following guides:Getting Started GuideAPI ReferenceExample GalleryOfficial Redis Vector Search Docs🫱🏼‍🫲🏽 ContributingPlease 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!🚧 MaintenanceThis project is supported byRedis, Incon a good faith effort basis. To report bugs, request features, or receive assistance, pleasefile an issue.