The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community[patch]: AzureSearch incorrectly converted to retriever (#20601)
Massimiliano Pronesti2542a09abc63
diff --git a/libs/community/langchain_community/vectorstores/azuresearch.py b/libs/community/langchain_community/vectorstores/azuresearch.pyindex e2b23e8a19..b07628d5a7 100644--- a/libs/community/langchain_community/vectorstores/azuresearch.py+++ b/libs/community/langchain_community/vectorstores/azuresearch.py@@ -654,6 +654,31 @@ class AzureSearch(VectorStore):azure_search.add_texts(texts, metadatas, **kwargs)return azure_search+ def as_retriever(self, **kwargs: Any) -> AzureSearchVectorStoreRetriever: # type: ignore+ """Return AzureSearchVectorStoreRetriever initialized from this VectorStore.++ Args:+ search_type (Optional[str]): Defines the type of search that+ the Retriever should perform.+ Can be "similarity" (default), "hybrid", or+ "semantic_hybrid".+ search_kwargs (Optional[Dict]): Keyword arguments to pass to the+ search function. Can include things like:+ k: Amount of documents to return (Default: 4)+ score_threshold: Minimum relevance threshold+ for similarity_score_threshold+ fetch_k: Amount of documents to pass to MMR algorithm (Default: 20)+ lambda_mult: Diversity of results returned by MMR;+ 1 for minimum diversity and 0 for maximum. (Default: 0.5)+ filter: Filter by document metadata++ Returns:+ AzureSearchVectorStoreRetriever: Retriever class for VectorStore.+ """+ tags = kwargs.pop("tags", None) or []+ tags.extend(self._get_retriever_tags())+ return AzureSearchVectorStoreRetriever(vectorstore=self, **kwargs, tags=tags)+class AzureSearchVectorStoreRetriever(BaseRetriever):"""Retriever that uses `Azure Cognitive Search`."""@@ -676,8 +701,13 @@ class AzureSearchVectorStoreRetriever(BaseRetriever):"""Validate search type."""if "search_type" in values:search_type = values["search_type"]- if search_type not in ("similarity", "hybrid", "semantic_hybrid"):- raise ValueError(f"search_type of {search_type} not allowed.")+ if search_type not in (+ allowed_search_types := ("similarity", "hybrid", "semantic_hybrid")+ ):+ raise ValueError(+ f"search_type of {search_type} not allowed. Valid values are: "+ f"{allowed_search_types}"+ )return valuesdef _get_relevant_documents(