Harrison/from keys redis (#4653)

Co-authored-by: Christoph Kahl <christoph@zauberware.com>
textloader_autodetect_encodings
Harrison Chase 1 year ago committed by GitHub
parent e781ff9256
commit 9ba3a798c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -358,7 +358,7 @@ class Redis(VectorStore):
return [(doc, self.relevance_score_fn(score)) for doc, score in docs_and_scores]
@classmethod
def from_texts(
def from_texts_return_keys(
cls: Type[Redis],
texts: List[str],
embedding: Embeddings,
@ -369,7 +369,7 @@ class Redis(VectorStore):
vector_key: str = "content_vector",
distance_metric: REDIS_DISTANCE_METRICS = "COSINE",
**kwargs: Any,
) -> Redis:
) -> Tuple[Redis, List[str]]:
"""Create a Redis vectorstore from raw documents.
This is a user-friendly interface that:
1. Embeds documents.
@ -414,7 +414,49 @@ class Redis(VectorStore):
instance._create_index(dim=len(embeddings[0]), distance_metric=distance_metric)
# Add data to Redis
instance.add_texts(texts, metadatas, embeddings)
keys = instance.add_texts(texts, metadatas, embeddings)
return instance, keys
@classmethod
def from_texts(
cls: Type[Redis],
texts: List[str],
embedding: Embeddings,
metadatas: Optional[List[dict]] = None,
index_name: Optional[str] = None,
content_key: str = "content",
metadata_key: str = "metadata",
vector_key: str = "content_vector",
**kwargs: Any,
) -> Redis:
"""Create a Redis vectorstore from raw documents.
This is a user-friendly interface that:
1. Embeds documents.
2. Creates a new index for the embeddings in Redis.
3. Adds the documents to the newly created Redis index.
This is intended to be a quick way to get started.
Example:
.. code-block:: python
from langchain.vectorstores import Redis
from langchain.embeddings import OpenAIEmbeddings
embeddings = OpenAIEmbeddings()
redisearch = RediSearch.from_texts(
texts,
embeddings,
redis_url="redis://username:password@localhost:6379"
)
"""
instance, _ = cls.from_texts_return_keys(
cls=cls,
texts=texts,
embedding=embedding,
metadatas=metadatas,
index_name=index_name,
content_key=content_key,
metadata_key=metadata_key,
vector_key=vector_key,
kwargs=kwargs,
)
return instance
@staticmethod

Loading…
Cancel
Save