langchain_community.vectorstores.redis.base.Redis¶
class langchain_community.vectorstores.redis.base.Redis(redis_url: str, index_name: str, embedding: Embeddings, index_schema: Optional[Union[Dict[str, str], str, PathLike]] = None, vector_schema: Optional[Dict[str, Union[str, int]]] = None, relevance_score_fn: Optional[Callable[[float], float]] = None, key_prefix: Optional[str] = None, **kwargs: Any)[source]¶
Redis vector database.
To use, you should have the redis python package installed
and have a running Redis Enterprise or Redis-Stack server
For production use cases, it is recommended to use Redis Enterprise
as the scaling, performance, stability and availability is much
better than Redis-Stack.
For testing and prototyping, however, this is not required.
Redis-Stack is available as a docker container the full vector
search API available.
# to run redis stack in docker locally
docker run -d -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
Once running, you can connect to the redis server with the following url schemas:
- redis://<host>:<port> # simple connection
- redis://<username>:<password>@<host>:<port> # connection with authentication
- rediss://<host>:<port> # connection with SSL
- rediss://<username>:<password>@<host>:<port> # connection with SSL and auth
Examples:
The following examples show various ways to use the Redis VectorStore with
LangChain.
For all the following examples assume we have the following imports:
from langchain_community.vectorstores import Redis
from langchain_community.embeddings import OpenAIEmbeddings
Initialize, create index, and load Documentsfrom langchain_community.vectorstores import Redis