Skip to main content
Redis is an in-memory data platform with vector search, full-text search, and semantic caching capabilities, designed for real-time AI applications.
This notebook shows how to use functionality related to the RedisVectorStore.

Setup

To use the RedisVectorStore you first need to install the partner package, as well as the other packages used throughout this notebook.
You’ll need a running Redis instance with Redis Search features enabled. We recommend Redis 8.4+. You can start one locally with Docker:
Or use Redis Cloud for a managed deployment. (Optional) Download RedisInsight — a browser-based GUI for inspecting your data and indexes.

Credentials

Configure your Redis connection by setting the following environment variable:
For Redis with authentication:
For Redis Cloud, use the connection string from your database dashboard:
This package also supports SSL/TLS (rediss://) and high-availability Redis Sentinel deployments (redis+sentinel://). See the langchain-redis README for full connection options. Set your OpenAI API key:
The langchain-redis package also provides RedisChatMessageHistory for conversation memory and RedisSemanticCache for LLM response caching — all backed by the same Redis instance as your vector store.

Initialization

The metadata_schema parameter tells Redis which metadata fields to index. Fields not listed here cannot be used in filters. Use "tag" for categorical string values and "numeric" for numbers.

Manage vector store

Add items to vector store

You can also add documents with custom keys:
Or use add_documents with LangChain Document objects:

Delete items from vector store

Query vector store

Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent.

Query directly

Performing a simple similarity search can be done as follows:

Similarity search with score

Similarity search with filtering

Other search methods

There are more search methods not listed in this notebook, to find all of them be sure to read the API reference.
Redis supports hybrid search combining vector similarity with full-text search. See the API reference for similarity_search parameters including return_all and distance_threshold.

Query by turning into retriever

You can also transform the vector store into a retriever for easier usage in your chains.

Usage for retrieval-augmented generation

For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections: For a full RAG walkthrough using langchain-redis, see this example notebook.

API reference

For detailed documentation of RedisVectorStore features and configurations head to the API reference.