Using Redis as a Vector Database

Redis Vector Database

Given the fact that not everybody knows that Redis is also a fully functional Vector Database, I have decided to write a short summary to explain how to use Redis as a Vector Database. Spoiler alert: you will need to use Redis Stack in your development environment. The bare Redis OSS version does not deliver the capability to use Redis as a Vector Database.

Redis, when used as a Vector Database, supports:

  1. Storing vectors of floats in Hash or JSON documents
  2. Vectors can be indexed using the FLAT or HNSW methods, with support to several distances (L2, IP, COSINE)
  3. Vector Similarity Search retrieves most similar vectors (hence, the documents containing the related vectors) and supports score-based range searches
  4. Hybrid queries are supported, meaning you can filter the documents by other search methods (full-text, numeric, tags, geographical). Using the tagging feature you can partition the vector space into multiple sub-spaces, or using geo data, you can partition your vectors geographically. And more with other types stored in the document.

If you are already a Redis user, you will discover that you can run modern use cases where support for vectors is required. Let’s have a look.

1. What is Redis Stack

Strictly seen, Redis Stack consists of Redis + additional features + RedisInsight. Support for vectors is provided by the extended search and query features, so it is easier to just install Redis Stack which comes with all the extensions including the support to vectors out-of-the-box. Read more here.

2. Installing Redis Stack

There are several ways to install Redis Stack and play with it:

Using Docker

An official Redis Stack image is available in the Docker hub. Run a container with a click and you have a fresh Vector Database at hand:

docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest

Platform-specific

You can install Redis Stack on your Linux, Windows, or MacOS box. Find the right installation method in the documentation.

Using a Redis Cloud free subscription

There is also a managed Redis Stack instance in Redis Cloud for free: Redis Stack instances are managed in the cloud provider of your choice (AWS, GCP, or Azure) so the database can be close to your cloud application. Unfortunately, the database size is limited to 30 megabytes only, but it is more than enough to run a basic use case. For a production-grade database, you can scale to Redis Cloud plans (fixed or flexible).

3. Using Redis Stack as a Vector Database

To start using Redis Stack as a Vector Database, you can use the standard client libraries that you would normally use with Redis. Click on your library of choice to find examples:

Learn how to work with client libraries!

And if you would like to run concrete examples for many different use cases, browse my blog:

4. See your data with RedisInsight

Now that you have followed the example and are capable of writing an application supporting vector data, you can download here the RedisInsight graphical management tool to see and manage your data.

5. Vector Database in production

You can certainly move from your development environment to production with Redis Stack. However, if you want to benefit from a production-grade, managed, and multi-tenancy environment, scaling to hundreds of millions of operations per second and with automated scalability out-of-the-box, you may want to move your workload to Redis Enterprise or Redis Cloud. Both are drop-in replacements of Redis Stack, meaning you can point your application to Redis Enterprise or Redis Cloud databases without changing your application. Find the description of a production setup in the documentation.

Doubts about Redis as Vector Database? Drop me a line!

Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Any use by mortensi is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis and mortensi.

Leave A Comment