|
|
@ -654,6 +654,31 @@ class AzureSearch(VectorStore):
|
|
|
|
azure_search.add_texts(texts, metadatas, **kwargs)
|
|
|
|
azure_search.add_texts(texts, metadatas, **kwargs)
|
|
|
|
return azure_search
|
|
|
|
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):
|
|
|
|
class AzureSearchVectorStoreRetriever(BaseRetriever):
|
|
|
|
"""Retriever that uses `Azure Cognitive Search`."""
|
|
|
|
"""Retriever that uses `Azure Cognitive Search`."""
|
|
|
@ -676,8 +701,13 @@ class AzureSearchVectorStoreRetriever(BaseRetriever):
|
|
|
|
"""Validate search type."""
|
|
|
|
"""Validate search type."""
|
|
|
|
if "search_type" in values:
|
|
|
|
if "search_type" in values:
|
|
|
|
search_type = values["search_type"]
|
|
|
|
search_type = values["search_type"]
|
|
|
|
if search_type not in ("similarity", "hybrid", "semantic_hybrid"):
|
|
|
|
if search_type not in (
|
|
|
|
raise ValueError(f"search_type of {search_type} not allowed.")
|
|
|
|
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 values
|
|
|
|
return values
|
|
|
|
|
|
|
|
|
|
|
|
def _get_relevant_documents(
|
|
|
|
def _get_relevant_documents(
|
|
|
|