mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-07 13:40:46 +00:00
Harrison/from keys redis (#4653)
Co-authored-by: Christoph Kahl <christoph@zauberware.com>
This commit is contained in:
parent
e781ff9256
commit
9ba3a798c4
@ -358,7 +358,7 @@ class Redis(VectorStore):
|
|||||||
return [(doc, self.relevance_score_fn(score)) for doc, score in docs_and_scores]
|
return [(doc, self.relevance_score_fn(score)) for doc, score in docs_and_scores]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_texts(
|
def from_texts_return_keys(
|
||||||
cls: Type[Redis],
|
cls: Type[Redis],
|
||||||
texts: List[str],
|
texts: List[str],
|
||||||
embedding: Embeddings,
|
embedding: Embeddings,
|
||||||
@ -369,7 +369,7 @@ class Redis(VectorStore):
|
|||||||
vector_key: str = "content_vector",
|
vector_key: str = "content_vector",
|
||||||
distance_metric: REDIS_DISTANCE_METRICS = "COSINE",
|
distance_metric: REDIS_DISTANCE_METRICS = "COSINE",
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Redis:
|
) -> Tuple[Redis, List[str]]:
|
||||||
"""Create a Redis vectorstore from raw documents.
|
"""Create a Redis vectorstore from raw documents.
|
||||||
This is a user-friendly interface that:
|
This is a user-friendly interface that:
|
||||||
1. Embeds documents.
|
1. Embeds documents.
|
||||||
@ -414,7 +414,49 @@ class Redis(VectorStore):
|
|||||||
instance._create_index(dim=len(embeddings[0]), distance_metric=distance_metric)
|
instance._create_index(dim=len(embeddings[0]), distance_metric=distance_metric)
|
||||||
|
|
||||||
# Add data to Redis
|
# 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
|
return instance
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user