-
Notifications
You must be signed in to change notification settings - Fork 376
Rag library integration #857
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
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests
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.
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. Comment |
There was a problem hiding this 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 unusedbuilder
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 theIPython.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
📒 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 uselogger.error()
(notlogger.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 theci/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 apyproject.toml
file. Optionally, it might also contain scripts in ascripts/
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 nameddata/
, 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.
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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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:
Summary by CodeRabbit
New Features
Documentation
Chores