Skip to content

Add reranked_search tool#201

Open
Jack-Yu-815 wants to merge 3 commits into
NVIDIA-AI-Blueprints:developfrom
Jack-Yu-815:source_reranking
Open

Add reranked_search tool#201
Jack-Yu-815 wants to merge 3 commits into
NVIDIA-AI-Blueprints:developfrom
Jack-Yu-815:source_reranking

Conversation

@Jack-Yu-815
Copy link
Copy Markdown

changes

  1. added reranked_search as a new source package

    • the tool takes in sub-tools (other search tools), triggers them in parallel, and rerank based on returned content's relevance to query.
    • this reranker tool's input schema is dynamically created based on the input schemas of its sub-tools. Therefore, it can use sub-tools with different number of parameters, so long as they return some kind of search results. Usage is quite flexible.
    • sub-tool must utilize air_agent.common.SOURCE_DELIMITER to separate result strings.
  2. small changes to other built-in tools in sources/

    • switched to using air_agent.common.SOURCE_DELIMITER to separate result strings.
  3. updated dependency-related files and setup script.

…rerank their results by query relevance

Signed-off-by: Jack Yu <jacyu@nvidia.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 22, 2026

Greptile Summary

This PR introduces a reranked_search tool that fans out a query to multiple configured search tools in parallel and uses an NVIDIA cross-encoder (NVIDIARerank) to rerank the merged results, returning the top-k. It also standardises result separators across existing sources (tavily_web_search, knowledge_layer, paper_search) by introducing a shared SOURCE_DELIMITER constant.

  • P1 — missing package dependency: sources/reranker/pyproject.toml imports from aiq_agent.common but does not declare aiq-agent as a dependency; standalone installs will fail with ModuleNotFoundError.
  • P1 — header string is a rerank candidate: knowledge_layer._format_results prepends "Found N relevant document(s):\n" to the lines list that is later SOURCE_DELIMITER.join-ed, so the reranker treats this metadata header as a scoreable document, potentially displacing a real result.

Confidence Score: 3/5

Not safe to merge until the missing aiq-agent dependency and the header-as-rerank-candidate issues are resolved.

Two P1 defects remain: standalone installs of reranked-search will fail due to an undeclared aiq-agent dependency, and the knowledge_layer header string is incorrectly fed to the reranker as a scoreable candidate, silently degrading result quality.

sources/reranker/pyproject.toml (missing dependency) and sources/knowledge_layer/src/register.py (header in rerank pool)

Important Files Changed

Filename Overview
sources/reranker/pyproject.toml Missing aiq-agent dependency; package imports SOURCE_DELIMITER from aiq_agent.common but that package is not declared in dependencies.
sources/reranker/src/register.py Core reranker implementation: fans out to sub-tools in parallel, reranks via NVIDIARerank; missing aiq-agent dep in pyproject.toml, empty strings passed to reranker, and dunder getattribute nit.
sources/knowledge_layer/src/register.py Fixed SOURCE_DELIMITER chunking (per previous review), but the "Found N relevant document(s)" header is still included as the first rerank candidate via SOURCE_DELIMITER.join.
sources/tavily_web_search/src/register.py Switched result separator to SOURCE_DELIMITER constant; change is clean and correct.
sources/google_scholar_paper_search/src/paper_search.py Switched paper join separator to SOURCE_DELIMITER constant; straightforward and correct.
src/aiq_agent/common/prompt_utils.py Added SOURCE_DELIMITER constant ("\n\n---\n\n") and exported it from common/init.py; clean change.
sources/reranker/README.md New documentation for the reranked_search tool; describes configuration, environment variables, and compatibility requirements.
sources/reranker/example_cli_config.yml Full working example config; prior llm field issue was flagged and acknowledged; config is otherwise representative.

Sequence Diagram

sequenceDiagram
    participant Agent
    participant RerankedSearch
    participant ToolA as search_tool_A
    participant ToolB as search_tool_B
    participant NVIDIARerank

    Agent->>RerankedSearch: _reranked_search(RerankedSearchInput)
    par Fan-out
        RerankedSearch->>ToolA: ainvoke(input.tool_a)
        ToolA-->>RerankedSearch: "result1\n\n---\n\nresult2"
    and
        RerankedSearch->>ToolB: ainvoke(input.tool_b)
        ToolB-->>RerankedSearch: "result3\n\n---\n\nresult4"
    end
    Note over RerankedSearch: split each by SOURCE_DELIMITER → all_results[]
    RerankedSearch->>NVIDIARerank: acompress_documents(query=overall_query, docs=all_results)
    NVIDIARerank-->>RerankedSearch: reranked_docs (scored)
    RerankedSearch-->>Agent: "Top k results ranked by relevance:\n..." 
Loading

Reviews (3): Last reviewed commit: "address greptile review comments, remove..." | Re-trigger Greptile

Comment thread sources/knowledge_layer/src/register.py
Comment thread sources/reranker/src/cross_encoder.py Outdated
Comment thread sources/reranker/src/cross_encoder.py Outdated
Comment thread sources/reranker/src/register.py
Comment thread sources/reranker/src/cross_encoder.py Outdated
Signed-off-by: Jack Yu <jacyu@nvidia.com>
Comment thread sources/reranker/src/register.py Outdated
Comment thread sources/reranker/example_cli_config.yml
Signed-off-by: Jack Yu <jacyu@nvidia.com>
Comment on lines +28 to +35
readme = "README.md"
requires-python = ">=3.11,<3.14"
license = {text = "Apache-2.0"}
dependencies = [
"nvidia-nat==1.5.0",
"pydantic>=2.0.0",
"langchain-core>=1.1.0",
"langchain-nvidia-ai-endpoints>=1.1.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Missing aiq-agent dependency

sources/reranker/src/register.py imports from aiq_agent.common import SOURCE_DELIMITER, but aiq-agent is not listed in dependencies. This works in the uv workspace because every member can see the others, but running pip install reranked-search in any other environment will raise ModuleNotFoundError: No module named 'aiq_agent'. Add the internal package as a dependency:

dependencies = [
    "aiq-agent",
    "nvidia-nat==1.5.0",
    "pydantic>=2.0.0",
    "langchain-core>=1.1.0",
    "langchain-nvidia-ai-endpoints>=1.1.0"
]

@AjayThorve AjayThorve added AIQ2.2 enhancement New feature or request labels May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIQ2.2 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants