Skip to content

Expose agentic retrieval via MCP and HTTP service endpoints - #2416

Open
mahikaw wants to merge 1 commit into
mainfrom
dev/mahikaw/mcp-agentic-query
Open

Expose agentic retrieval via MCP and HTTP service endpoints#2416
mahikaw wants to merge 1 commit into
mainfrom
dev/mahikaw/mcp-agentic-query

Conversation

@mahikaw

@mahikaw mahikaw commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Add server-owned AgenticConfig and thin service adapters so existing agentic_query_documents() can run in service mode without changing AgenticRetriever internals.

  • Expose POST /v1/agentic/query on the VectorDB app (execution) and gateway proxy; add config-gated MCP tool agentic_query alongside unchanged plain query.

  • Wire Helm/retriever-service.yaml so gateway gets enablement + timeout from ConfigMap, and the VectorDB deployment gets --agentic* CLI flags + API key when a remote LLM URL is set.

  • Service mode requires remote invoke_url + llm_model (and remote embed); request body stays {query, top_k} with server-owned ReAct knobs. Hits remain slim (rank / doc_id / result_source).

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mahikaw
mahikaw requested review from a team as code owners July 30, 2026 23:11
@mahikaw
mahikaw requested a review from charlesbluca July 30, 2026 23:11
@copy-pr-bot

copy-pr-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Comment on lines +513 to +516
async with _query_semaphore:
return await asyncio.to_thread(
run_agentic_query,
req,

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 Timed-out work retains query slots

When an agentic request times out or disconnects before the ReAct workflow finishes, asyncio.to_thread leaves the synchronous work running while it retains the semaphore shared with plain queries, causing subsequent queries to block after all four slots are occupied.

Rule Used: Models and stateful components accessed from Ray a... (source)

Knowledge Base Used: Service: HTTP/MCP API surface

Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/src/nemo_retriever/service/vectordb_app.py
Line: 513-516

Comment:
**Timed-out work retains query slots**

When an agentic request times out or disconnects before the ReAct workflow finishes, `asyncio.to_thread` leaves the synchronous work running while it retains the semaphore shared with plain queries, causing subsequent queries to block after all four slots are occupied.

**Rule Used:** Models and stateful components accessed from Ray a... ([source](nemo_retriever/.greptile))

**Knowledge Base Used:** [Service: HTTP/MCP API surface](https://app.greptile.com/nvidia-public-github/-/custom-context/knowledge-base/nvidia/nemo-retriever/-/docs/service-api.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

class AgenticQueryRequest(BaseModel):
"""One query for the server-configured agentic retrieval pipeline."""

query: str = Field(min_length=1)

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.

P2 Agentic query length is unbounded

The public request schema accepts arbitrarily large query strings and forwards them into the multi-step LLM workflow, allowing disproportionate prompt size, inference cost, and latency; add a defensible max_length constraint.

Knowledge Base Used: Service: HTTP/MCP API surface

Prompt To Fix With AI
This is a comment left during a code review.
Path: nemo_retriever/src/nemo_retriever/service/query_schema.py
Line: 42

Comment:
**Agentic query length is unbounded**

The public request schema accepts arbitrarily large query strings and forwards them into the multi-step LLM workflow, allowing disproportionate prompt size, inference cost, and latency; add a defensible `max_length` constraint.

**Knowledge Base Used:** [Service: HTTP/MCP API surface](https://app.greptile.com/nvidia-public-github/-/custom-context/knowledge-base/nvidia/nemo-retriever/-/docs/service-api.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds config-gated agentic retrieval across the VectorDB HTTP API, gateway proxy, MCP facade, and Helm deployment.

  • Introduces server-owned ReAct configuration and request/response schemas.
  • Executes the existing agentic workflow in the VectorDB process through a new /v1/agentic/query endpoint.
  • Adds gateway and MCP forwarding with independent agentic request timeouts.
  • Wires agentic model settings, credentials, and CLI flags through Helm.
  • Adds unit coverage for configuration, request mapping, HTTP proxying, and MCP registration.

Confidence Score: 4/5

The PR should not merge until timed-out agentic work releases shared query capacity and remote embedding and LLM endpoints can use the correct credentials.

Agentic calls can outlive their HTTP callers while retaining the semaphore used by all VectorDB queries, and the new service path assigns one embedding credential to two independently configured upstream services.

Files Needing Attention: nemo_retriever/src/nemo_retriever/service/vectordb_app.py, nemo_retriever/src/nemo_retriever/query/workflow.py, nemo_retriever/src/nemo_retriever/service/agentic_query.py

Important Files Changed

Filename Overview
nemo_retriever/src/nemo_retriever/service/vectordb_app.py Adds the execution endpoint and CLI configuration, but non-cancellable threaded workflows can retain shared query capacity after callers time out.
nemo_retriever/src/nemo_retriever/query/workflow.py Adds explicit embedding-key resolution for service mode but reuses that credential for the independently configured LLM endpoint.
nemo_retriever/src/nemo_retriever/service/agentic_query.py Provides a thin request adapter but exposes no separate credential path for the remote agentic LLM.
nemo_retriever/src/nemo_retriever/service/query_schema.py Defines slim agentic request and response models, with the query text lacking an upper size bound.
nemo_retriever/src/nemo_retriever/service/routers/ingest.py Adds a config-gated gateway proxy with the configured agentic HTTP timeout.
nemo_retriever/src/nemo_retriever/service/mcp_server.py Adds a config-gated MCP tool and dedicated client timeout without changing existing tools.
nemo_retriever/src/nemo_retriever/service/config.py Adds validated server-owned agentic settings requiring a remote model and invoke URL when enabled.
nemo_retriever/helm/templates/deployment-vectordb.yaml Wires agentic CLI arguments and the shared NVIDIA credential into the VectorDB deployment.
nemo_retriever/helm/templates/configmap.yaml Renders the agentic configuration for the gateway service.
nemo_retriever/tests/test_service_agentic_query.py Covers configuration, mapping, endpoint execution, top-k validation, and proxying but not timeout/disconnect lifecycle behavior.
nemo_retriever/tests/test_service_mcp.py Covers the dedicated MCP request path, additive tool registration, and config-derived timeout.

Sequence Diagram

sequenceDiagram
    participant C as REST/MCP Client
    participant G as Gateway Service
    participant V as VectorDB App
    participant E as Embedding Endpoint
    participant L as Agentic LLM
    C->>G: POST /v1/agentic/query
    G->>V: Proxy query + top_k
    V->>V: Acquire shared query semaphore
    V->>E: Multi-hop retrieval embeddings
    V->>L: ReAct and selection calls
    L-->>V: Selected document IDs
    V-->>G: rank/doc_id/result_source
    G-->>C: AgenticQueryResponse
Loading

Comments Outside Diff (1)

  1. nemo_retriever/src/nemo_retriever/query/workflow.py, line 166-184 (link)

    P1 Embedding key overwrites LLM credential

    When the remote embedding service and OpenAI-compatible LLM require different credentials, this code assigns the embedding API key to both clients, causing one upstream request path to fail authentication.

    Knowledge Base Used:

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: nemo_retriever/src/nemo_retriever/query/workflow.py
    Line: 166-184
    
    Comment:
    **Embedding key overwrites LLM credential**
    
    When the remote embedding service and OpenAI-compatible LLM require different credentials, this code assigns the embedding API key to both clients, causing one upstream request path to fail authentication.
    
    **Knowledge Base Used:**
    - [Query Pipeline](https://app.greptile.com/nvidia-public-github/-/custom-context/knowledge-base/nvidia/nemo-retriever/-/docs/query-pipeline.md)
    - [Repo Overview and Deployment](https://app.greptile.com/nvidia-public-github/-/custom-context/knowledge-base/nvidia/nemo-retriever/-/docs/repo-overview-and-deployment.md)
    
    ---
    
    For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Prompt To Fix All With AI
### Issue 1
nemo_retriever/src/nemo_retriever/service/vectordb_app.py:513-516
**Timed-out work retains query slots**

When an agentic request times out or disconnects before the ReAct workflow finishes, `asyncio.to_thread` leaves the synchronous work running while it retains the semaphore shared with plain queries, causing subsequent queries to block after all four slots are occupied.

### Issue 2
nemo_retriever/src/nemo_retriever/query/workflow.py:166-184
**Embedding key overwrites LLM credential**

When the remote embedding service and OpenAI-compatible LLM require different credentials, this code assigns the embedding API key to both clients, causing one upstream request path to fail authentication.

### Issue 3
nemo_retriever/src/nemo_retriever/service/query_schema.py:42
**Agentic query length is unbounded**

The public request schema accepts arbitrarily large query strings and forwards them into the multi-step LLM workflow, allowing disproportionate prompt size, inference cost, and latency; add a defensible `max_length` constraint.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Expose agentic retrieval via MCP and HTT..." | Re-trigger Greptile

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.

1 participant