Skip to content

Commit e253fd3

Browse files
authored
Adding GTC 2025 DLIT71491 GraphRAG notebooks (#288)
* Adding GTC 2025 DLIT71491 GraphRAG notebooks with secure configuration * Adding GTC 2025 DLIT71491 GraphRAG notebooks with secure configuration
1 parent 37e183a commit e253fd3

24 files changed

+54659
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
**/.ipynb_checkpoints
3+
# **/data
4+
**/dask-worker-space
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
COMPOSE_PROJECT_NAME=gtc25_kgrag_dli
2+
DEV_NGINX_PORT=9999
3+
NGC_API_KEY=#
4+
NVIDIA_API_KEY=#
5+
HUGGINGFACE_TOKEN=#
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/.ipynb_checkpoints
2+
# **/data
3+
**/dask-worker-space
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file defines paths that should not be included in the
2+
# launch tarball.
3+
# This includes any paths in the docker container.
4+
# If a dataset loader is used, this file should also include
5+
# the paths to any datasets.
6+
Dockerfile
7+
.launchignore
8+
.dockerignore
9+
.gitignore
10+
vm_properties.json
11+
entrypoint.sh
12+
assessment/*
13+
.git
14+
**/.ipynb_checkpoints
15+
# **/data
16+
**/dask-worker-space
17+
**/mydask*
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Use NVIDIA's AI Workbench base image
2+
FROM nvcr.io/nvidia/ai-workbench/python-cuda120:1.0.3
3+
4+
# Set the working directory in the container
5+
WORKDIR ./
6+
7+
# Copy the application code into the container (optional)
8+
# COPY ./app_code ./app
9+
10+
# Update and install additional system dependencies (if needed)
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
build-essential \
13+
curl \
14+
wget \
15+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
16+
17+
# Install Python dependencies
18+
COPY requirements.txt ./requirements.txt
19+
RUN pip install --no-cache-dir -r requirements.txt
20+
21+
EXPOSE 8888
22+
23+
# ADD entrypoint.sh /usr/local/bin
24+
# ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Knowledge Graph-based RAG System
2+
3+
This repository contains the materials for the NVIDIA GTC 2025 Deep Learning Institute course: "Structure From Chaos: Accelerate GraphRAG With cuGraph and NVIDIA NIM" [DLIT71491].
4+
5+
You can access the online course video at: [NVIDIA On-Demand](https://www.nvidia.com/en-us/on-demand/session/gtc25-dlit71491/)
6+
7+
## Overview
8+
9+
This course demonstrates how to build a Knowledge Graph-based RAG system for financial documents, specifically SEC 10-K filings. The system extracts structured knowledge triplets, builds a dynamic knowledge graph, and provides enhanced query capabilities.
10+
11+
You'll learn how to integrate large language models (LLMs) with NVIDIA Inference Microservices (NIM) and cuGraph to create cutting-edge, graph-based AI solutions for handling complex, interconnected data. The course covers fine-tuning techniques, Langchain agents, and GPU-accelerated graph analytics to enhance AI capabilities and retrieval-augmented generation (RAG) evaluation.
12+
13+
## Prerequisites
14+
15+
- Docker and docker-compose
16+
- 4x NVIDIA A100 GPUs required for the LLM fine-tuning workflow (Notebook 2)
17+
- NVIDIA API key (sign up at [NVIDIA AI portal](https://developer.nvidia.com/))
18+
19+
## Setup
20+
21+
1. Clone this repository
22+
2. Set your NVIDIA API key in the `.env` file:
23+
```
24+
NVIDIA_API_KEY=your-nvapi-key
25+
NGC_API_KEY=your-ngc-key # For some containerized models
26+
```
27+
3. Start the containers:
28+
```bash
29+
docker-compose up -d
30+
```
31+
4. Access the Jupyter Lab environment at: http://localhost:8888
32+
33+
## Notebooks
34+
35+
The course consists of five notebooks that build upon each other:
36+
37+
1. **01_Graph_Triplet_Extraction.ipynb**
38+
- Extract structured (subject, relation, object) triplets from SEC 10-K filings
39+
- Transform unstructured text into structured knowledge for a knowledge graph
40+
41+
2. **02_LLM_Finetuning.ipynb**
42+
- Fine-tune a smaller LLM (LLaMa-3 8B) for more accurate triplet prediction
43+
- Leverage NVIDIA NeMo and NVIDIA Inference Microservices (NIM)
44+
45+
3. **03_Dynamic_Database.ipynb**
46+
- Set up a persistent, dynamic backend (ArangoDB) for the knowledge graph
47+
- Handle triplets being added or deleted over time
48+
- Create a GraphRAG agent connected to a continuously updating database
49+
50+
4. **04_Evaluation.ipynb**
51+
- Evaluate the RAG system using Ragas and NVIDIA's Nemotron-340b-reward model
52+
- Assess metrics such as faithfulness, context precision, and answer relevancy
53+
54+
5. **05_Link_Prediction.ipynb**
55+
- Improve knowledge graph completeness through link prediction
56+
- Use techniques like TransE model and non-negative matrix factorization
57+
- Predict missing relationships within the knowledge graph
58+
59+
## Data
60+
61+
The notebooks use 2021 SEC documents (10-K filings) from the [Kaggle SEC EDGAR Annual Financial Filings 2021 dataset](https://www.kaggle.com/datasets/pranjalverma08/sec-edgar-annual-financial-filings-2021). The data preprocessing tools are included in the `data_prep` directory.
62+
63+
## Requirements
64+
65+
The key Python packages required for this project are listed in `requirements.txt` and include:
66+
- numpy, scipy, scikit-learn
67+
- torch, pykeen, fairscale
68+
- jupyterlab, networkx
69+
- ArangoDB libraries (nx_arangodb, arango)
70+
- NVIDIA GPU libraries (cugraph-cu12, nx_cugraph-cu12)
71+
- LLM frameworks (llama-index, langchain, transformers)
72+
- Evaluation tools (ragas, datasets)
73+
74+
## Docker Environment
75+
76+
The repository uses multiple containers:
77+
- A JupyterLab environment with CUDA support
78+
- NVIDIA NeMo container for model fine-tuning
79+
- NVIDIA NIM container for model serving
80+
- ArangoDB for graph database storage
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
version: '3'
2+
3+
services:
4+
nginx:
5+
image: nginx:latest
6+
ports:
7+
- "${DEV_NGINX_PORT}:8888"
8+
volumes:
9+
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
10+
- ./notebooks:/usr/share/nginx/html:ro
11+
networks:
12+
- gtc25_kgrag_dli
13+
14+
jupyter:
15+
build:
16+
context: .
17+
dockerfile: Dockerfile
18+
volumes:
19+
- ./notebooks:/workspace/notebooks
20+
- ./entrypoint.sh:/entrypoint.sh
21+
environment:
22+
- JUPYTER_TOKEN=nvidia
23+
entrypoint: /entrypoint.sh
24+
networks:
25+
- gtc25_kgrag_dli
26+
deploy:
27+
resources:
28+
reservations:
29+
devices:
30+
- driver: nvidia
31+
count: 1
32+
capabilities: [gpu]
33+
34+
nim:
35+
image: nvcr.io/nvidia/nemo-inference-microservice:23.12
36+
ports:
37+
- "8000:8000"
38+
environment:
39+
- NGC_API_KEY=$NGC_API_KEY
40+
- NIM_PEFT_SOURCE=/home/nvs/loras
41+
- NIM_PEFT_REFRESH_INTERVAL=3600
42+
- TRANSFORMERS_CACHE=#
43+
- CUDA_VISIBLE_DEVICES=2
44+
volumes:
45+
- ${PWD}/model/nim/:/opt/nim/.cache:rw
46+
- ${PWD}/model/loras/:/home/nvs/loras:rw
47+
networks:
48+
- gtc25_kgrag_dli
49+
deploy:
50+
resources:
51+
reservations:
52+
devices:
53+
- driver: nvidia
54+
count: 1
55+
capabilities: [gpu]
56+
57+
networks:
58+
gtc25_kgrag_dli:
59+
name: ${COMPOSE_PROJECT_NAME}
60+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# JUPYTER_TOKEN will empty in development, but set for
4+
# deployments. It will be applied from the environment
5+
# automatically when running `docker-compose up`.
6+
# For more details see `docker-compose.production.yml`,
7+
# `docker-compose.override.yml`, and
8+
# `nginx.conf`.
9+
10+
jupyter lab \
11+
--ip 0.0.0.0 `# Run on localhost` \
12+
--allow-root `# Enable the use of sudo commands in the notebook` \
13+
--no-browser `# Do not launch a browser by default` \
14+
--NotebookApp.base_url="/lab" `# Allow value to be passed in for production` \
15+
--NotebookApp.token="$JUPYTER_TOKEN" `# Do not require token to access notebook` \
16+
--NotebookApp.password="" `# Do not require password to run jupyter server` \
17+
--notebook-dir='/workspace'
18+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
worker_processes auto;
2+
pid /etc/nginx/.nginx.pid;
3+
4+
events {
5+
worker_connections 768;
6+
}
7+
8+
http {
9+
sendfile on;
10+
tcp_nopush on;
11+
tcp_nodelay on;
12+
client_max_body_size 0;
13+
keepalive_timeout 65;
14+
types_hash_max_size 2048;
15+
16+
default_type application/octet-stream;
17+
18+
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
19+
ssl_prefer_server_ciphers on;
20+
21+
access_log /var/log/access.log;
22+
error_log /var/log/error.log;
23+
24+
gzip on;
25+
gzip_disable "msie6";
26+
27+
server {
28+
29+
listen 80 default_server;
30+
listen [::]:80 default_server;
31+
32+
location / {
33+
proxy_pass http://localhost/lab;
34+
proxy_http_version 1.1;
35+
proxy_set_header Upgrade $http_upgrade;
36+
proxy_set_header Connection "Upgrade";
37+
proxy_set_header Host $http_host;
38+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
39+
proxy_buffering off;
40+
}
41+
42+
location /lab {
43+
proxy_pass http://lab:8888;
44+
proxy_http_version 1.1;
45+
proxy_set_header Upgrade $http_upgrade;
46+
proxy_set_header Connection "Upgrade";
47+
proxy_set_header Host $http_host;
48+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
49+
proxy_buffering off;
50+
}
51+
}
52+
}

community/knowledge_graph_rag/GTC25_DLI/notebooks/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)