The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community[patch]: Add missing async similarity_distance_threshold handling in RedisVectorStoreRetriever (#16359)
Michard Hugoe9d3527b79b6
diff --git a/libs/community/langchain_community/vectorstores/redis/base.py b/libs/community/langchain_community/vectorstores/redis/base.pyindex bcad15f369..78cbffcbc7 100644--- a/libs/community/langchain_community/vectorstores/redis/base.py+++ b/libs/community/langchain_community/vectorstores/redis/base.py@@ -23,7 +23,10 @@ from typing import (import numpy as npimport yamlfrom langchain_core._api import deprecated-from langchain_core.callbacks import CallbackManagerForRetrieverRun+from langchain_core.callbacks import (+ AsyncCallbackManagerForRetrieverRun,+ CallbackManagerForRetrieverRun,+)from langchain_core.documents import Documentfrom langchain_core.embeddings import Embeddingsfrom langchain_core.utils import get_from_dict_or_env@@ -1464,6 +1467,37 @@ class RedisVectorStoreRetriever(VectorStoreRetriever):raise ValueError(f"search_type of {self.search_type} not allowed.")return docs+ async def _aget_relevant_documents(+ self, query: str, *, run_manager: AsyncCallbackManagerForRetrieverRun+ ) -> List[Document]:+ if self.search_type == "similarity":+ docs = await self.vectorstore.asimilarity_search(+ query, **self.search_kwargs+ )+ elif self.search_type == "similarity_distance_threshold":+ if self.search_kwargs["distance_threshold"] is None:+ raise ValueError(+ "distance_threshold must be provided for "+ + "similarity_distance_threshold retriever"+ )+ docs = await self.vectorstore.asimilarity_search(+ query, **self.search_kwargs+ )+ elif self.search_type == "similarity_score_threshold":+ docs_and_similarities = (+ await self.vectorstore.asimilarity_search_with_relevance_scores(+ query, **self.search_kwargs+ )+ )+ docs = [doc for doc, _ in docs_and_similarities]+ elif self.search_type == "mmr":+ docs = await self.vectorstore.amax_marginal_relevance_search(+ query, **self.search_kwargs+ )+ else:+ raise ValueError(f"search_type of {self.search_type} not allowed.")+ return docs+def add_documents(self, documents: List[Document], **kwargs: Any) -> List[str]:"""Add documents to vectorstore."""return self.vectorstore.add_documents(documents, **kwargs)