Skip to content

Add ranking_instructions to Search Mode - #96

Closed
CShorten wants to merge 2 commits into
mainfrom
add-ranking-instructions
Closed

Add ranking_instructions to Search Mode#96
CShorten wants to merge 2 commits into
mainfrom
add-ranking-instructions

Conversation

@CShorten

@CShorten CShorten commented Jul 8, 2026

Copy link
Copy Markdown
Member

Add ranking_instructions argument to Search Mode

What's changed

Adds a new optional ranking_instructions argument to the Query Agent's search-only mode, on both QueryAgent.search() and AsyncQueryAgent.search().

response = agent.search(
    "Find NDAs signed in 2024",
    collections=["FinancialContracts"],
    ranking_instructions="Prioritize recently signed documents over older ones.",
)

How it works

  • The instructions are passed to the instruction-following reranker to guide relevance prioritization. They only affect the ordering of results, not which results are retrieved.
  • The field is added to SearchModeRequestBase, so it applies to both the initial request (server-side query generation) and paginated requests via response.next(...) (direct search execution), and persists across pages — consistent with filtering and diversity_weight.
  • Defaults to None and serializes as JSON null when not provided.

Tests

  • Sync + async tests asserting that omitting the argument sends null in the request payload.
  • Sync + async tests asserting that a provided string is sent verbatim and persists across pagination.

@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 self-assigned this Jul 9, 2026
@CShorten
CShorten requested a review from a team July 16, 2026 13:22
Comment thread weaviate_agents/query/search.py Outdated
self.collections = collections
self.system_prompt = system_prompt
self.filtering = filtering
self.filtering: Optional[Literal["recall", "precision"]] = filtering

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.

seems like a duplicate type definition, it's already defined above?

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.

Ah whoops, sorry not sure how this got in there. Fixing now.

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.

Thanks for catching this @augustas1 🙏 , I have just pushed the change removing this duplicate type definition on filtering.

@CShorten
CShorten requested a review from augustas1 July 23, 2026 12:24
@CShorten CShorten closed this Jul 28, 2026
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.

2 participants