Skip to content

Conversation

NarimaneH
Copy link

@NarimaneH NarimaneH commented Sep 26, 2025

Description

Integrates NVIDIA RAG python native library as a NAT agent tool. The integration supports multimodal RAG extraction and uses Milvus as the default database but it can be changed following the original NVIDIA RAG repo.

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • New Features

    • Introduces an example RAG library package with a configurable tool and agent workflow (Milvus-backed search, reranking, and NIM LLM), enabled via a ready-to-use configuration.
  • Documentation

    • Adds a comprehensive usage guide covering installation options, configuration, server setup, and running the workflow, with example outputs and references to sample assets.
  • Chores

    • Updates ignore rules for generated volumes.
    • Adds a CUDA-related asset via Git LFS.
    • Provides project configuration to enable installing and discovering the example package.

@NarimaneH NarimaneH requested a review from a team as a code owner September 26, 2025 16:23
Copy link

copy-pr-bot bot commented Sep 26, 2025

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.

Copy link

coderabbitai bot commented Sep 26, 2025

Walkthrough

Adds a new example package "rag_lib" with packaging config, a RAG tool function, registration hook, and a sample agent workflow configuration. Introduces documentation and a data LFS pointer. Updates .gitignore to exclude example deployment volumes. No changes to existing runtime logic outside the new example package.

Changes

Cohort / File(s) Summary
Git ignore updates
\.gitignore
Added ignore rule for examples/rag_library_mode/rag_library_mode/src/rag_library_mode/deploy/volumes/*.
RAG lib packaging
examples/rag_lib/pyproject.toml
New project config for rag_lib: setuptools + setuptools-scm, Python >=3.11,<3.13, dependency on nvidia-nat[langchain]~=0.1, entry point nat.components: rag_lib = "rag_lib.register", SCM settings, local source mapping.
RAG lib docs & data
examples/rag_lib/README.md, examples/rag_lib/data/cuda.txt
Added README guiding install/usage and agent configuration; added Git LFS pointer file cuda.txt.
RAG lib workflow config
examples/rag_lib/src/rag_lib/configs/config.yml
New YAML defining rag_tool function config, NIM LLM settings, and a tool_calling_agent workflow with verbose logging.
RAG lib function implementation
examples/rag_lib/src/rag_lib/rag_lib_function.py
Added RagLibFunctionConfig (base_url, reranker_top_k, vdb_top_k, collection_names) and rag_lib_function registered via @register_function; performs NvidiaRAG search and formats citations.
RAG lib registration hook
examples/rag_lib/src/rag_lib/register.py
Added import-side registration (from rag_lib import rag_lib_function) to expose the tool via entry point.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Agent as ToolCallingAgent
  participant RagTool as rag_lib_function
  participant RAG as NvidiaRAG
  participant VDB as Milvus/Vector DB

  User->>Agent: Query
  Agent->>RagTool: Invoke with query
  RagTool->>RAG: search(query, vdb_top_k, reranker_top_k, collection_names, base_url)
  RAG->>VDB: Vector search
  VDB-->>RAG: Hits
  RAG-->>RagTool: Citations
  RagTool-->>Agent: Formatted citations (XML-like snippets)
  Agent-->>User: Final response with citations

  rect rgba(230,240,255,0.5)
  note over RagTool,RAG: New integration and formatting flow
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

feature request, non-breaking

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The pull request title “Rag library integration” is descriptive but written as a noun phrase rather than in the imperative mood required by the guidelines, so it does not adhere to the specified style requirements. Please rephrase the title in imperative mood, for example “Integrate Rag library,” while keeping it concise and descriptive within the 72-character limit.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added feature request New feature or request non-breaking Non-breaking change labels Sep 26, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Nitpick comments (2)
examples/rag_lib/src/rag_lib/rag_lib_function.py (2)

35-36: Rename the unused builder argument.

Ruff flags builder as unused. Rename it to _builder (or use it) to satisfy the linter and make the intent clear.

-async def rag_lib_function(
-    config: RagLibFunctionConfig, builder: Builder
-):
+async def rag_lib_function(
+    config: RagLibFunctionConfig, _builder: Builder
+):

10-15: Drop unused imports.

NvidiaRAGIngestor, json, base64, and the IPython.display symbols are never referenced. Removing them keeps the module clean and avoids lint noise.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74a2ca8 and 6f49eff.

📒 Files selected for processing (7)
  • .gitignore (1 hunks)
  • examples/rag_lib/README.md (1 hunks)
  • examples/rag_lib/data/cuda.txt (1 hunks)
  • examples/rag_lib/pyproject.toml (1 hunks)
  • examples/rag_lib/src/rag_lib/configs/config.yml (1 hunks)
  • examples/rag_lib/src/rag_lib/rag_lib_function.py (1 hunks)
  • examples/rag_lib/src/rag_lib/register.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
**/*.{yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

In workflow/config YAML, set llms.._type: nat_test_llm to stub responses.

Files:

  • examples/rag_lib/src/rag_lib/configs/config.yml
**/*.{py,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.{py,yaml,yml}: Configure response_seq as a list of strings; values cycle per call, and [] yields an empty string.
Configure delay_ms to inject per-call artificial latency in milliseconds for nat_test_llm.

Files:

  • examples/rag_lib/src/rag_lib/configs/config.yml
  • examples/rag_lib/src/rag_lib/register.py
  • examples/rag_lib/src/rag_lib/rag_lib_function.py
examples/*/src/**

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Example Python code must be placed in an examples//src/ subdirectory and include a pyproject.toml at example root

Files:

  • examples/rag_lib/src/rag_lib/configs/config.yml
  • examples/rag_lib/src/rag_lib/register.py
  • examples/rag_lib/src/rag_lib/rag_lib_function.py
**/configs/**

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Configuration files consumed by code must be stored next to that code in a configs/ folder

Files:

  • examples/rag_lib/src/rag_lib/configs/config.yml
**/*

⚙️ CodeRabbit configuration file

**/*: # Code Review Instructions

  • Ensure the code follows best practices and coding standards. - For Python code, follow
    PEP 20 and
    PEP 8 for style guidelines.
  • Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values.
    Example:
    def my_function(param1: int, param2: str) -> bool:
        pass
  • For Python exception handling, ensure proper stack trace preservation:
    • When re-raising exceptions: use bare raise statements to maintain the original stack trace,
      and use logger.error() (not logger.exception()) to avoid duplicate stack trace output.
    • When catching and logging exceptions without re-raising: always use logger.exception()
      to capture the full stack trace information.

Documentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any

words listed in the ci/vale/styles/config/vocabularies/nat/reject.txt file, words that might appear to be
spelling mistakes but are listed in the ci/vale/styles/config/vocabularies/nat/accept.txt file are OK.

Misc. - All code (except .mdc files that contain Cursor rules) should be licensed under the Apache License 2.0,

and should contain an Apache License 2.0 header comment at the top of each file.

  • Confirm that copyright years are up-to date whenever a file is changed.

Files:

  • examples/rag_lib/src/rag_lib/configs/config.yml
  • examples/rag_lib/data/cuda.txt
  • examples/rag_lib/src/rag_lib/register.py
  • examples/rag_lib/pyproject.toml
  • examples/rag_lib/README.md
  • examples/rag_lib/src/rag_lib/rag_lib_function.py
examples/**/*

⚙️ CodeRabbit configuration file

examples/**/*: - This directory contains example code and usage scenarios for the toolkit, at a minimum an example should
contain a README.md or file README.ipynb.

  • If an example contains Python code, it should be placed in a subdirectory named src/ and should
    contain a pyproject.toml file. Optionally, it might also contain scripts in a scripts/ directory.
  • If an example contains YAML files, they should be placed in a subdirectory named configs/. - If an example contains sample data files, they should be placed in a subdirectory named data/, and should
    be checked into git-lfs.

Files:

  • examples/rag_lib/src/rag_lib/configs/config.yml
  • examples/rag_lib/data/cuda.txt
  • examples/rag_lib/src/rag_lib/register.py
  • examples/rag_lib/pyproject.toml
  • examples/rag_lib/README.md
  • examples/rag_lib/src/rag_lib/rag_lib_function.py
examples/*/data/**

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Sample data for examples must be in examples//data/ and committed via Git-LFS

Files:

  • examples/rag_lib/data/cuda.txt
**/data/**

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Large/binary assets must be committed with Git-LFS and placed in a neighbouring data/ folder

Files:

  • examples/rag_lib/data/cuda.txt
**/*.py

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.py: Programmatic use: create TestLLMConfig(response_seq=[...], delay_ms=...), add with builder.add_llm("", cfg).
When retrieving the test LLM wrapper, use builder.get_llm(name, wrapper_type=LLMFrameworkEnum.) and call the framework’s method (e.g., ainvoke, achat, call).

**/*.py: In code comments/identifiers use NAT abbreviations as specified: nat for API namespace/CLI, nvidia-nat for package name, NAT for env var prefixes; do not use these abbreviations in documentation
Follow PEP 20 and PEP 8; run yapf with column_limit=120; use 4-space indentation; end files with a single trailing newline
Run ruff check --fix as linter (not formatter) using pyproject.toml config; fix warnings unless explicitly ignored
Respect naming: snake_case for functions/variables, PascalCase for classes, UPPER_CASE for constants
Treat pyright warnings as errors during development
Exception handling: use bare raise to re-raise; log with logger.error() when re-raising to avoid duplicate stack traces; use logger.exception() when catching without re-raising
Provide Google-style docstrings for every public module, class, function, and CLI command; first line concise and ending with a period; surround code entities with backticks
Validate and sanitize all user input, especially in web or CLI interfaces
Prefer httpx with SSL verification enabled by default and follow OWASP Top-10 recommendations
Use async/await for I/O-bound work; profile CPU-heavy paths with cProfile or mprof before optimizing; cache expensive computations with functools.lru_cache or external cache; leverage NumPy vectorized operations when beneficial

Files:

  • examples/rag_lib/src/rag_lib/register.py
  • examples/rag_lib/src/rag_lib/rag_lib_function.py
examples/*/pyproject.toml

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Each example must have a pyproject.toml

Files:

  • examples/rag_lib/pyproject.toml
**/README.@(md|ipynb)

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Ensure READMEs follow the naming convention; avoid deprecated names; use “NeMo Agent Toolkit” (capital T) in headings

Files:

  • examples/rag_lib/README.md
examples/*/README.@(md|ipynb)

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Each example must include a README.md or README.ipynb

Files:

  • examples/rag_lib/README.md
🧠 Learnings (1)
📚 Learning: 2025-09-23T18:39:15.023Z
Learnt from: CR
PR: NVIDIA/NeMo-Agent-Toolkit#0
File: .cursor/rules/general.mdc:0-0
Timestamp: 2025-09-23T18:39:15.023Z
Learning: Applies to packages/*/pyproject.toml : In packages, declare a dependency on nvidia-nat or packages starting with nvidia-nat-

Applied to files:

  • examples/rag_lib/pyproject.toml
🧬 Code graph analysis (2)
examples/rag_lib/src/rag_lib/register.py (1)
examples/rag_lib/src/rag_lib/rag_lib_function.py (1)
  • rag_lib_function (34-70)
examples/rag_lib/src/rag_lib/rag_lib_function.py (1)
src/nat/cli/type_registry.py (1)
  • register_function (459-467)
🪛 markdownlint-cli2 (0.18.1)
examples/rag_lib/README.md

6-6: Bare URL used

(MD034, no-bare-urls)


20-20: Bare URL used

(MD034, no-bare-urls)


24-24: Heading levels should only increment by one level at a time
Expected: h2; Actual: h4

(MD001, heading-increment)


65-65: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


71-71: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)


76-76: Code block style
Expected: indented; Actual: fenced

(MD046, code-block-style)

🪛 Ruff (0.13.1)
examples/rag_lib/src/rag_lib/rag_lib_function.py

35-35: Unused function argument: builder

(ARG001)

🔇 Additional comments (2)
examples/rag_lib/data/cuda.txt (1)

1-3: Git-LFS pointer is correctly added.

The asset is tracked via Git-LFS under the expected examples/rag_lib/data/ location, matching the repository data policy.

.gitignore (1)

2-2: Ignore rule placement looks good.

The new pattern is scoped to the rag library example and sits in the intended “add entries here” section, so it won’t interfere with generated rules.

Comment on lines +26 to +63
Configure your Agent to use the Milvus collections for RAG. We have pre-configured a configuration file for you in `examples/RAG/simple_rag/configs/milvus_rag_config.yml`. You can modify this file to point to your Milvus instance and collections or add tools to your agent. The agent, by default, is a `tool_calling` agent that can be used to interact with the retriever component. The configuration file is shown below. You can also modify your agent to be another one of the NeMo Agent toolkit pre-built agent implementations such as the `react_agent`

```yaml
general:
use_uvloop: true


functions:
rag_tool:
_type: rag_lib
base_url: "http://localhost:19530"
vdb_top_k: 20
reranker_top_k: 10
collection_names: ["test_library"]
topic: Retrieve relevant documents from the database relevant to the query


llms:
nim_llm:
_type: nim
model_name: meta/llama-3.3-70b-instruct
temperature: 0
max_tokens: 4096
top_p: 1


workflow:
_type: tool_calling_agent
tool_names:
- rag_tool
verbose: true
llm_name: nim_llm
```

If you have a different Milvus instance or collection names, you can modify the `vdb_url` and the `collection_names` in the config file to point to your instance and collections.
You can also modify the retrieval parameters like `vdb_top_k`, ...
You can also add additional functions as tools for your agent in the `functions` section.

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix the configuration path and option names in the guide.

The README points users to examples/RAG/simple_rag/configs/milvus_rag_config.yml, but this PR ships examples/rag_lib/src/rag_lib/configs/config.yml. It also tells readers to edit vdb_url, while the config actually exposes base_url. Following the current instructions will fail because the referenced file/field don’t match what’s in the repo.

Please update the README to reference examples/rag_lib/src/rag_lib/configs/config.yml and call out base_url (plus any other renamed keys) so users can run the example successfully.

🤖 Prompt for AI Agents
In examples/rag_lib/README.md around lines 26 to 63, the guide references the
wrong config path and an incorrect option name; update the README to point to
examples/rag_lib/src/rag_lib/configs/config.yml (instead of examples/RAG/...)
and replace any mention of vdb_url with base_url (and audit and update any other
renamed keys to match the actual config file), and briefly note where to change
collection_names and retrieval params so the instructions match the shipped
config.

Comment on lines +1 to +4
# flake8: noqa

# Import any tools which need to be automatically registered here
from rag_lib import rag_lib_function No newline at end of file
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add the Apache 2.0 header.

This Python file also needs the standard Apache 2.0 license block at the top to comply with the repo’s licensing rule.

As per coding guidelines

🤖 Prompt for AI Agents
In examples/rag_lib/src/rag_lib/register.py around lines 1-4, the file is
missing the standard Apache 2.0 license header required by the repo; add the
standard Apache 2.0 license block used across the project at the very top of the
file (updating year/owner if applicable), then leave the existing "# flake8:
noqa" and import lines below the header so the file complies with licensing
guidelines.

Updating to the latest develop version
@ericevans-nv ericevans-nv self-assigned this Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants