Create a RedisVectorStore from a list of Document objects.
from_documents(
cls,
documents: List[Document],
embedding: Embeddings,
config: Optional[RedisConfig] = None,
return_keys: bool = False,
**kwargs: Any = {}
) -> RedisVectorStoreExample:
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.| Name | Type | Description |
|---|---|---|
documents* | List[Document] | List of |
embedding* | Embeddings |
|
config | Optional[RedisConfig] | Default: NoneOptional If not provided, one will be created from kwargs. |
return_keys | bool | Default: FalseWhether to return the keys of the added documents. |
**kwargs | Any | Default: {}Additional keyword arguments to pass to Common kwargs include:
|