from_documents(
cls,
documents: List[Document],
embedding: Embeddings,
config: Optional| Name | Type | Description |
|---|---|---|
documents* | List[Document] | List of |
embedding* | Embeddings |
|
config | Optional[RedisConfig] | Default: None |
return_keys | bool | Default: False |
**kwargs | Any | Default: {} |
Create a RedisVectorStore from a list of Document objects.
Example:
from langchain_redis import RedisVectorStore
from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document
documents = [
Document(
page_content="The quick brown fox",
metadata={"animal": "fox"}
),
Document(
page_content="jumps over the lazy dog",
metadata={"animal": "dog"}
)
]
embeddings = OpenAIEmbeddings()
vector_store = RedisVectorStore.from_documents(
documents=documents,
embedding=embeddings,
index_name="animal-docs",
redis_url="redis://localhost:6379"
)
# Now you can use the vector_store for similarity search
results = vector_store.similarity_search("quick animal", k=1)
print(results[0].page_content)
Note:
RedisVectorStore instance and adds the
provided documents to it.Document object.RedisConfig object is not provided, one will be created using
the additional kwargs passed to this method.Optional RedisConfig object.
If not provided, one will be created from kwargs.
Whether to return the keys of the added documents.
Additional keyword arguments to pass to RedisConfig if config
is not provided.
Common kwargs include:
index_name: Name of the Redis index to create.redis_url: URL of the Redis instance to connect to.distance_metric: Distance metric to use for similarity search.
'COSINE'.'FLAT'.