-
Notifications
You must be signed in to change notification settings - Fork 324
Adding Agentic Retrieval as a new retrieveral mode #2018
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
Open
mahikaw
wants to merge
6
commits into
main
Choose a base branch
from
dev/mahikaw/agentic_retrieval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
59a1c59
agentic retrieval init
mahikaw b915c46
param defaults updated
mahikaw bf7fd58
adding Beir evaluation wiring and pinning down defaults
mahikaw 9aaca6a
cleanup
mahikaw 9e12581
cleanup
mahikaw 8c0af28
added review fixes
mahikaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| # Agentic Retrieval Mode | ||
|
|
||
| Agentic retrieval mode is a retrieval strategy for the main NeMo Retriever | ||
| pipeline. It is not a separate evaluation benchmark. The evaluation mode still | ||
| answers "how do we score results?", while retrieval mode answers "how do we | ||
| produce ranked results?". | ||
|
|
||
| The first integration supports: | ||
|
|
||
| ```bash | ||
| --evaluation-mode recall --retrieval-mode agentic | ||
| ``` | ||
|
|
||
| In this mode, the pipeline ingests documents and uploads them to the configured | ||
| vector database exactly as it does today. The difference starts at evaluation | ||
| time: instead of one standard dense retrieval pass, an LLM-driven graph | ||
| retrieval pipeline searches the same vector database and produces ranked | ||
| results that are scored with recall-style metrics. | ||
|
|
||
| ## Graph Pipeline | ||
|
|
||
| The agentic retriever composes the existing graph operators: | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| QueryCsv[Query CSV] --> Normalize[Normalize Queries] | ||
| Normalize --> ReactAgent[ReActAgentOperator] | ||
| ReactAgent --> RetrieverTool[Retriever Tool] | ||
| RetrieverTool --> VDB[Vector DB] | ||
| ReactAgent --> RRFAggregator[RRFAggregatorOperator] | ||
| RRFAggregator --> SelectionAgent[SelectionAgentOperator] | ||
| SelectionAgent --> RankedResults[Ranked Results] | ||
| RankedResults --> Metrics[Recall Metrics] | ||
| ``` | ||
|
|
||
| `ReActAgentOperator` runs an LLM-driven ReAct loop per query. The agent can | ||
| think, issue retrieval subqueries, inspect retrieved candidates, and decide | ||
| when it has enough evidence. | ||
|
|
||
| `RRFAggregatorOperator` combines candidates from multiple retrieval steps using | ||
| reciprocal rank fusion. This gives more weight to documents that appear near | ||
| the top across multiple search attempts. | ||
|
|
||
| `SelectionAgentOperator` runs a final LLM-based selection pass over the fused | ||
| candidate set and emits the ranked document IDs used for scoring. | ||
|
|
||
| ## CLI Integration | ||
|
|
||
| The main CLI adds a retrieval strategy option: | ||
|
|
||
| ```bash | ||
| --retrieval-mode standard|agentic | ||
| ``` | ||
|
|
||
| `--evaluation-mode` remains evaluation-focused: | ||
|
|
||
| ```bash | ||
| --evaluation-mode recall|beir|qa | ||
| ``` | ||
|
|
||
| Supported combinations in the first integration: | ||
|
|
||
| - `--evaluation-mode=recall --retrieval-mode=standard` | ||
| - `--evaluation-mode=recall --retrieval-mode=agentic` | ||
| - `--evaluation-mode=qa --retrieval-mode=standard` | ||
|
|
||
| Unsupported initially: | ||
|
|
||
| - `--evaluation-mode=qa --retrieval-mode=agentic` | ||
| - BEIR through the generic pipeline path remains unchanged and unavailable, as | ||
| it is in the existing pipeline. | ||
|
|
||
| ## Agentic Options | ||
|
|
||
| `--agentic-llm-model` sets the chat model used by both `ReActAgentOperator` and | ||
| `SelectionAgentOperator`. It is required when `--retrieval-mode=agentic`. | ||
|
|
||
| `--agentic-invoke-url` optionally sets the OpenAI-compatible chat completions | ||
| endpoint used by the agent operators. If omitted, the operators use their | ||
| default endpoint. | ||
|
|
||
| `--agentic-react-max-steps` controls the maximum ReAct loop iterations per | ||
| query. The default is `10`. | ||
|
|
||
| ## Wrapped Standard Retrieval | ||
|
|
||
| Every agent `retrieve` tool call delegates to the existing | ||
| `nemo_retriever.retriever.Retriever`. That means agentic mode searches the same | ||
| vector database populated by ingestion and reuses the same retrieval settings | ||
| where possible. | ||
|
|
||
| Existing options reused by the wrapped retriever: | ||
|
|
||
| - `--api-key`: authentication for agentic LLM calls and remote services unless | ||
| a more specific key is provided. | ||
| - `--embed-model-name`, `--embed-invoke-url`, `--local-query-embed-backend`, | ||
| `--local-hf-batch-size`: query embedding configuration. | ||
| - `--reranker`, `--reranker-model-name`, `--reranker-invoke-url`, | ||
| `--reranker-api-key`, `--local-reranker-backend`: optional reranking inside | ||
| the wrapped retriever. | ||
|
|
||
| The first integration intentionally keeps the lower-level agentic retrieval | ||
| parameters fixed: | ||
|
|
||
| - retriever top-k: `10` | ||
| - target top-k: `10` | ||
| - selection top-k: `10` | ||
| - query concurrency: `1` | ||
| - text truncation: `500` | ||
| - max tokens: provider default | ||
| - parallel tool calls: disabled | ||
|
|
||
| ## Examples | ||
|
|
||
| Local in-process run: | ||
|
|
||
| ```bash | ||
| retriever pipeline run ./data/bo767 \ | ||
| --run-mode inprocess \ | ||
| --evaluation-mode recall \ | ||
| --retrieval-mode agentic \ | ||
| --query-csv ./data/bo767_query_gt.csv \ | ||
| --agentic-llm-model meta/llama-3.3-70b-instruct \ | ||
| --api-key os.environ/NVIDIA_API_KEY | ||
| ``` | ||
|
|
||
| Batch run with remote embedding and agent endpoints: | ||
|
|
||
| ```bash | ||
| retriever pipeline run ./data/bo767 \ | ||
| --run-mode batch \ | ||
| --evaluation-mode recall \ | ||
| --retrieval-mode agentic \ | ||
| --query-csv ./data/bo767_query_gt.csv \ | ||
| --embed-invoke-url http://localhost:8000/v1 \ | ||
| --agentic-invoke-url http://localhost:9000/v1/chat/completions \ | ||
| --agentic-llm-model meta/llama-3.3-70b-instruct \ | ||
| --agentic-react-max-steps 5 \ | ||
| --api-key os.environ/NVIDIA_API_KEY | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024-25, NVIDIA CORPORATION & AFFILIATES. | ||
| # All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Agentic retrieval utilities.""" | ||
|
|
||
| from nemo_retriever.agentic.retrieval import ( | ||
| AgenticRetrievalConfig, | ||
| AgenticRetriever, | ||
| build_beir_run_from_agentic_result, | ||
| build_qrels, | ||
| run_agentic_beir_evaluation, | ||
| run_agentic_recall_evaluation, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "AgenticRetrievalConfig", | ||
| "AgenticRetriever", | ||
| "build_beir_run_from_agentic_result", | ||
| "build_qrels", | ||
| "run_agentic_beir_evaluation", | ||
| "run_agentic_recall_evaluation", | ||
| ] | ||
|
mahikaw marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.