-
Notifications
You must be signed in to change notification settings - Fork 4
Add filtering argument to Search Mode
#91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3e2a163
05bab20
8f70a45
2be3dd2
bf2ec17
e12cb43
e304497
0150f09
5acc664
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Optional, Union | ||
| from typing import Any, Literal, Optional, Union | ||
|
|
||
| import httpx | ||
|
|
||
|
|
@@ -35,6 +35,7 @@ def __init__( | |
| query: Union[str, list[ChatMessage]], | ||
| collections: list[Union[str, QueryAgentCollectionConfig]], | ||
| system_prompt: Optional[str], | ||
| filtering: Optional[Literal["recall", "precision"]] = None, | ||
| diversity_weight: Optional[float] = None, | ||
| ): | ||
| self.headers = headers | ||
|
|
@@ -44,6 +45,7 @@ def __init__( | |
| self.query = query | ||
| self.collections = collections | ||
| self.system_prompt = system_prompt | ||
| self.filtering = filtering | ||
| self.diversity_weight = diversity_weight | ||
| self._cached_searches: Optional[list[QueryResultWithCollectionNormalized]] = ( | ||
| None | ||
|
|
@@ -63,6 +65,7 @@ def _get_request_body(self, limit: int, offset: int) -> dict[str, Any]: | |
| limit=limit, | ||
| offset=offset, | ||
| system_prompt=self.system_prompt, | ||
| filtering=self.filtering, | ||
| diversity_weight=self.diversity_weight, | ||
| ).model_dump(mode="json") | ||
| else: | ||
|
|
@@ -73,6 +76,7 @@ def _get_request_body(self, limit: int, offset: int) -> dict[str, Any]: | |
| limit=limit, | ||
| offset=offset, | ||
| searches=self._cached_searches, | ||
| filtering=self.filtering, | ||
| diversity_weight=self.diversity_weight, | ||
| ).model_dump(mode="json") | ||
|
|
||
|
|
@@ -93,7 +97,7 @@ def _handle_response(self, response: httpx.Response) -> SearchModeResponse: | |
| raise Exception(response.text) | ||
|
|
||
| parsed_response = SearchModeResponse(**response.json()) | ||
| if parsed_response.searches: | ||
| if parsed_response.searches is not None: | ||
| self._cached_searches = parsed_response.searches | ||
| parsed_response._searcher = self | ||
| return parsed_response | ||
|
|
@@ -138,7 +142,7 @@ def _handle_response(self, response: httpx.Response) -> AsyncSearchModeResponse: | |
| raise Exception(response.text) | ||
|
|
||
| parsed_response = AsyncSearchModeResponse(**response.json()) | ||
| if parsed_response.searches: | ||
| if parsed_response.searches is not None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In precision mode we are allowing Search Mode to return no searches, so we need to check that here in order to avoid re-generating searches instead of re-executing the cached one with pagination. |
||
| self._cached_searches = parsed_response.searches | ||
| parsed_response._searcher = self | ||
| return parsed_response | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the need for this additional
is not Nonecheck isn't theparsed_respond.searchesmodel the same ?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In precision mode we are allowing Search Mode to return no searches, so we need to check that here in order to avoid re-generating searches instead of re-executing the cached one with pagination.