mirror of
https://github.com/hwchase17/langchain
synced 2024-11-18 09:25:54 +00:00
community[patch]:Support filter for AzureAISearchRetriever (#22303)
**Description**: The AzureAISearchRetriever does not support the "$filter" argument offered in the AISearch API: https://learn.microsoft.com/en-us/rest/api/searchservice/documents/search-get?view=rest-searchservice-2023-11-01&tabs=HTTP The $filter allows filtering of indexes based on values in metadata. **Issue**: https://github.com/langchain-ai/langchain/issues/19885 **Dependencies**: No **Twitter handle**: @Jeffreym9M - [ ] **Add tests and docs**: Not relevant - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/
This commit is contained in:
parent
148088a588
commit
5fc5ed463c
@ -36,6 +36,8 @@ class AzureAISearchRetriever(BaseRetriever):
|
|||||||
"""Key in a retrieved result to set as the Document page_content."""
|
"""Key in a retrieved result to set as the Document page_content."""
|
||||||
top_k: Optional[int] = None
|
top_k: Optional[int] = None
|
||||||
"""Number of results to retrieve. Set to None to retrieve all results."""
|
"""Number of results to retrieve. Set to None to retrieve all results."""
|
||||||
|
filter: Optional[str] = None
|
||||||
|
"""OData $filter expression to apply to the search query."""
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
extra = Extra.forbid
|
extra = Extra.forbid
|
||||||
@ -72,7 +74,8 @@ class AzureAISearchRetriever(BaseRetriever):
|
|||||||
base_url = self.service_name
|
base_url = self.service_name
|
||||||
endpoint_path = f"indexes/{self.index_name}/docs?api-version={self.api_version}"
|
endpoint_path = f"indexes/{self.index_name}/docs?api-version={self.api_version}"
|
||||||
top_param = f"&$top={self.top_k}" if self.top_k else ""
|
top_param = f"&$top={self.top_k}" if self.top_k else ""
|
||||||
return base_url + endpoint_path + f"&search={query}" + top_param
|
filter_param = f"&$filter={self.filter}" if self.filter else ""
|
||||||
|
return base_url + endpoint_path + f"&search={query}" + top_param + filter_param
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _headers(self) -> Dict[str, str]:
|
def _headers(self) -> Dict[str, str]:
|
||||||
|
Loading…
Reference in New Issue
Block a user