Skip to content

Commit

Permalink
fix: Set default search_type to 'similarity' in as_retriever method o…
Browse files Browse the repository at this point in the history
…f AzureSearch (#28376)

**Description**
This PR updates the `as_retriever` method in the `AzureSearch` to ensure
that the `search_type` parameter defaults to 'similarity' when not
explicitly provided.

Previously, if the `search_type` was omitted, it did not default to any
specific value. So it was inherited from
`AzureSearchVectorStoreRetriever`, which defaults to 'hybrid'.

This change ensures that the intended default behavior aligns with the
expected usage.

**Issue**
No specific issue was found related to this change.

**Dependencies**
No new dependencies are introduced with this change.

---------

Co-authored-by: prrao87 <[email protected]>
Co-authored-by: Erick Friis <[email protected]>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent 8c6eec5 commit 0f0df2d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions libs/community/langchain_community/vectorstores/azuresearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,10 +1545,9 @@ def as_retriever(self, **kwargs: Any) -> AzureSearchVectorStoreRetriever: # typ
"""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_type (Optional[str]): Overrides the type of search that
the Retriever should perform. Defaults to `self.search_type`.
Can be "similarity", "hybrid", or "semantic_hybrid".
search_kwargs (Optional[Dict]): Keyword arguments to pass to the
search function. Can include things like:
score_threshold: Minimum relevance threshold
Expand All @@ -1561,6 +1560,9 @@ def as_retriever(self, **kwargs: Any) -> AzureSearchVectorStoreRetriever: # typ
Returns:
AzureSearchVectorStoreRetriever: Retriever class for VectorStore.
"""
search_type = kwargs.get("search_type", self.search_type)
kwargs["search_type"] = search_type

tags = kwargs.pop("tags", None) or []
tags.extend(self._get_retriever_tags())
return AzureSearchVectorStoreRetriever(vectorstore=self, **kwargs, tags=tags)
Expand Down

0 comments on commit 0f0df2d

Please sign in to comment.