Skip to content

Add filtering argument to Search Mode#91

Merged
CShorten merged 9 commits into
mainfrom
add-search-strategy
May 29, 2026
Merged

Add filtering argument to Search Mode#91
CShorten merged 9 commits into
mainfrom
add-search-strategy

Conversation

@CShorten

@CShorten CShorten commented May 20, 2026

Copy link
Copy Markdown
Member

Description

Adds a filtering parameter to the Query Agent's Search Mode. This allows users to control the trade-off between recall and precision.

The parameter accepts two values: "recall" to optimize for finding all relevant results, or "precision" to optimize for the accuracy of returned results.

Usage example:

agent = QueryAgent(
  client=client, 
  collections=["FinancialContracts"]
)
                                                                                
# Default behavior (recall) 
results = agent.search("Find all NDAs signed by Jane Doe in 2024.")           
                                                                                
# Optimize for precision
results = agent.search(
  "Find all NDAs signed by Jane Doe in 2024.",
  filtering="precision"
)

Pagination Fix

Empty search lists are cached from precision mode's ability to output no searches, ensuring pagination requests are consistent.

@orca-security-eu orca-security-eu Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@CShorten CShorten changed the title Add search_strategy argument to Search Mode Add retrieval_strategy argument to Search Mode May 21, 2026
@CShorten CShorten self-assigned this May 21, 2026
@CShorten CShorten requested a review from a team May 21, 2026 11:03
@CShorten CShorten changed the title Add retrieval_strategy argument to Search Mode Add filtering argument to Search Mode May 26, 2026
collections: list[Union[str, QueryAgentCollectionConfig]]
limit: int
offset: int
filtering: Literal["recall", "precision"] = "recall"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove defaulting it to recall.

@cdpierse cdpierse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the desired behaviour we would like if a user does not pass filtering? If the server handles filtering=None then we should make it a optional Literal where when the value is None it defaults to server side values.

Right now if we were to make the decision for any reason to make precision the default for search mode server side for any customer they would have to update the client in order for this to take effect.

This might not be the actual desired behaviour but I wanted to flag that this what the state would be if we ship as is. Happy to hear thoughts from @augustas1 @danmichaeljones @dannyjameswilliams also here

@dannyjameswilliams

Copy link
Copy Markdown
Contributor

What's the desired behaviour we would like if a user does not pass filtering? If the server handles filtering=None then we should make it a optional Literal where when the value is None it defaults to server side values.

Right now if we were to make the decision for any reason to make precision the default for search mode server side for any customer they would have to update the client in order for this to take effect.

I think this is probably a sensible solution, as long as it's kept up to date in the docs (or probably at least the docstring of the method) what the server-side default is.

Then we may also want to update result_evaluation to be the same, as it is a similar setting.

@CShorten CShorten requested a review from cdpierse May 28, 2026 20:16

parsed_response = SearchModeResponse(**response.json())
if parsed_response.searches:
if parsed_response.searches is not None:

Copy link
Copy Markdown
Collaborator

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 None check isn't the parsed_respond.searches model the same ?

@CShorten CShorten May 29, 2026

Copy link
Copy Markdown
Member Author

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.


parsed_response = AsyncSearchModeResponse(**response.json())
if parsed_response.searches:
if parsed_response.searches is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@CShorten CShorten May 29, 2026

Copy link
Copy Markdown
Member Author

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.

@CShorten CShorten merged commit 48bb770 into main May 29, 2026
13 checks passed
@CShorten CShorten deleted the add-search-strategy branch May 29, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants