This section walks you through setting up RedisVectorStore to store document embeddings and perform similarity searches.

What is Redis?

Redis is an open source (BSD licensed), in-memory data structure store used as a database, cache, message broker, and streaming engine. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams.

Redis Search and Query extends the core features of Redis OSS and allows you to use Redis as a vector database:

  • Store vectors and the associated metadata within hashes or JSON documents

  • Retrieve vectors

  • Perform vector searches


  1. EmbeddingClient instance to compute the document embeddings. Several options are available:

    • Transformers Embedding - computes the embedding in your local environment. Follow the ONNX Transformers Embedding instructions.

    • OpenAI Embedding - uses the OpenAI embedding endpoint. You need to create an account at OpenAI Signup and generate the api-key token at API Keys.

    • You can also use the Azure OpenAI Embedding.

  2. A Redis Stack instance

    1. Redis Cloud (recommended)

    2. Docker image redis/redis-stack:latest


Add these dependencies to your project:

  • Embedding Client boot starter, required for calculating embeddings.

  • Transformers Embedding (Local) and follow the ONNX Transformers Embedding instructions.


or use OpenAI (Cloud)

Refer to the Dependency Management section to add the Spring AI BOM to your build file.

You’ll need to provide your OpenAI API Key. Set it as an environment variable like so:

  • Add the Redis Vector Store and Jedis dependencies


Refer to the Dependency Management section to add the Spring AI BOM to your build file.


Create a RedisVectorStore instance connected to your Redis database:

public VectorStore vectorStore(EmbeddingClient embeddingClient) {
  RedisVectorStoreConfig config = RedisVectorStoreConfig.builder()
     // Define the metadata fields to be used
     // in the similarity search filters.

  return new RedisVectorStore(config, embeddingClient);
It is more convenient and preferred to create the RedisVectorStore as a Bean. But if you decide to create it manually, then you must call the RedisVectorStore#afterPropertiesSet() after setting the properties and before using the client.
You must list explicitly all metadata field names and types (TAG, TEXT, or NUMERIC) for any metadata field used in filter expression. The withMetadataFields above registers filterable metadata fields: country of type TAG, year of type NUMERIC.

Then in your main code, create some documents:

List<Document> documents = List.of(
   new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("country", "UK", "year", 2020)),
   new Document("The World is Big and Salvation Lurks Around the Corner", Map.of()),
   new Document("You walk forward facing the past and you turn back toward the future.", Map.of("country", "NL", "year", 2023)));

Now add the documents to your vector store:


And finally, retrieve documents similar to a query:

List<Document> results = vectorStore.similaritySearch(

If all goes well, you should retrieve the document containing the text "Spring AI rocks!!".

Metadata filtering

You can leverage the generic, portable metadata filters with RedisVectorStore as well.

For example, you can use either the text expression language:

      .query("The World")
      .withFilterExpression("country in ['UK', 'NL'] && year >= 2020"));

or programmatically using the expression DSL:

FilterExpressionBuilder b = new FilterExpressionBuilder();

      .query("The World")
      .withFilterExpression(b.and("country", "UK", "NL"),
         b.gte("year", 2020)).build()));

The portable filter expressions get automatically converted into Redis search queries. For example, the following portable filter expression:

country in ['UK', 'NL'] && year >= 2020

is converted into Redis query:

@country:{UK | NL} @year:[2020 inf]