langchain.vectorstores.redis.base.Redis¶
class langchain.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, **kwargs: Any)[source]¶
Wrapper around 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.
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.vectorstores import Redis
from langchain.embeddings import OpenAIEmbeddings
Initialize, create index, and load Documentsfrom langchain.vectorstores import Redis
from langchain.embeddings import OpenAIEmbeddings
rds = Redis.from_documents(
    documents, # a list of Document objects from loaders or created
    embeddings, # an Embeddings object
    redis_url="redis://localhost:6379",
)