Redis Vector Store
This notebook covers how to get started with the Redis vector store.
Redis is a popular open-source, in-memory data structure store that can be used as a database, cache, message broker, and queue. It now includes vector similarity search capabilities, making it suitable for use as a vector store.
What is Redis?โ
Most developers are familiar with Redis
. At its core, Redis
is a NoSQL Database in the key-value family that can used as a cache, message broker, stream processing and a primary database. Developers choose Redis
because it is fast, has a large ecosystem of client libraries, and has been deployed by major enterprises for years.
On top of these traditional use cases, Redis
provides additional capabilities like the Search and Query capability that allows users to create secondary index structures within Redis
. This allows Redis
to be a Vector Database, at the speed of a cache.
Redis as a Vector Databaseโ
Redis
uses compressed, inverted indexes for fast indexing with a low memory footprint. It also supports a number of advanced features such as:
- Indexing of multiple fields in Redis hashes and
JSON
- Vector similarity search (with
HNSW
(ANN) orFLAT
(KNN)) - Vector Range Search (e.g. find all vectors within a radius of a query vector)
- Incremental indexing without performance loss
- Document ranking (using tf-idf, with optional user-provided weights)
- Field weighting
- Complex boolean queries with
AND
,OR
, andNOT
operators - Prefix matching, fuzzy matching, and exact-phrase queries
- Support for double-metaphone phonetic matching
- Auto-complete suggestions (with fuzzy prefix suggestions)
- Stemming-based query expansion in many languages (using Snowball)
- Support for Chinese-language tokenization and querying (using Friso)
- Numeric filters and ranges
- Geospatial searches using Redis geospatial indexing
- A powerful aggregations engine
- Supports for all
utf-8
encoded text - Retrieve full documents, selected fields, or only the document IDs
- Sorting results (for example, by creation date)
Clientsโ
Since Redis
is much more than just a vector database, there are often use cases that demand the usage of a Redis
client besides just the LangChain
integration. You can use any standard Redis
client library to run Search and Query commands, but it's easiest to use a library that wraps the Search and Query API. Below are a few examples, but you can find more client libraries here.
Project | Language | License | Author | Stars |
---|---|---|---|---|
jedis | Java | MIT | Redis | |
redisvl | Python | MIT | Redis | |
redis-py | Python | MIT | Redis | |
node-redis | Node.js | MIT | Redis | |
nredisstack | .NET | MIT | Redis |
Deployment optionsโ
There are many ways to deploy Redis with RediSearch. The easiest way to get started is to use Docker, but there are are many potential options for deployment such as
- Redis Cloud
- Docker (Redis Stack)
- Cloud marketplaces: AWS Marketplace, Google Marketplace, or Azure Marketplace
- On-premise: Redis Enterprise Software
- Kubernetes: Redis Enterprise Software on Kubernetes
Redis connection Url schemasโ
Valid Redis Url schemas are:
redis://
- Connection to Redis standalone, unencryptedrediss://
- Connection to Redis standalone, with TLS encryptionredis+sentinel://
- Connection to Redis server via Redis Sentinel, unencryptedrediss+sentinel://
- Connection to Redis server via Redis Sentinel, booth connections with TLS encryption
More information about additional connection parameters can be found in the redis-py documentation.
Setupโ
To use the RedisVectorStore, you'll need to install the langchain-redis
partner package, as well as the other packages used throughout this notebook.
%pip install -qU langchain-redis langchain-huggingface sentence-transformers scikit-learn
Note: you may need to restart the kernel to use updated packages.