DEV Community

Cover image for Supercharging Retrieval-Augmented Generation with NodeRAG: A Graph-Centric Approach
Bjorn-Donald Bassey
Bjorn-Donald Bassey

Posted on

Supercharging Retrieval-Augmented Generation with NodeRAG: A Graph-Centric Approach

Large Language Models (LLMs) continue to break new ground in complex reasoning tasks. It often feels like a new frontier model tops the leaderboard for reasoning benchmarks every other week. A major contributor to these advancements is the evolution of retrieval mechanisms—particularly those powered by Retrieval-Augmented Generation (RAG).

First introduced by the Meta AI team (Lewis et al., 2020), RAG was designed to improve factual consistency in language model outputs by accessing external corpora during inference. This allows models to deliver more domain-specific, up-to-date, and grounded responses.

Today, tech giants like Google and OpenAI implement RAG differently:

  • Google’s Vertex AI Search combines semantic and keyword (hybrid) search with a re-ranking mechanism to serve the most relevant results.
  • OpenAI, on the other hand, embeds RAG directly into the model's runtime when tools and file uploads are enabled. Additionally, OpenAI orchestrates tool usage intelligently with its Responses API.

However, for independent developers and smaller teams, replicating this level of RAG infrastructure is costly. That’s why it’s crucial to explore open-source innovations that democratize access to advanced RAG capabilities.

Enter NodeRAG: a powerful, graph-based RAG framework designed to optimize retrieval by leveraging heterogeneous graph structures. The key contributions of this method can be summarized into three key aspects

Image description

Image description

Image description


What Is NodeRAG?

NodeRAG is a graph-centric RAG framework designed to address limitations in traditional RAG systems, especially when dealing with multi-hop reasoning and summary-level queries.

While earlier graph-based RAG methods showed promise, they often overlooked the design of the graph structure itself. NodeRAG changes that by deeply integrating graph methodologies throughout the indexing and searching process.

Illustration for NaiveRAG, GraphRAG, HippoRAG, LightRAG, NodeRAG

At its core, NodeRAG builds a heterograph—a graph made up of different node types, including:

  • Entities (N)
  • Relationships (R)
  • Semantic Units (S)
  • Attributes (A)
  • High-level Elements (H)
  • Overviews (O)
  • Text Chunks (T)

These nodes form a richly connected structure that encapsulates, summarizes, and enhances the original corpus—leading to fine-grained, context-aware, and explainable retrieval.


NodeRAG Pipeline: From Corpus to Graph

The NodeRAG pipeline is split into two main phases: graph indexing and graph searching.

1. Graph Indexing

This phase constructs the heterograph and enriches it with multiple layers of semantic information.

a. Graph Decomposition

Text is broken down using an LLM into:

  • Semantic Units (S): Paraphrased summaries of local events or ideas.
  • Entities (N): Named objects or people.
  • Relationships (R): Links connecting entities to semantic units.

b. Graph Augmentation

Next, graph algorithms identify key nodes and communities:

  • Attributes (A) are extracted via LLM summarization of entities and relationships.
  • High-level Elements (H) are distilled summaries of community-level meaning.
  • Overviews (O) serve as keyword-based titles for high-level elements.

This step also segments the graph into communities using the Leiden algorithm (Traag et al., 2019), preserving structural coherence.

c. Graph Enrichment

Original text chunks are embedded to retain full context and improve relevance. Only a subset is embedded to optimize for storage and efficiency.


2. Graph Searching

When a query is made, NodeRAG performs a dual-layered retrieval process:

a. Dual Search

  • Title-based exact match
  • Vector-based semantic match

b. Personalized PageRank (PPR)

Starting from entry nodes, a shallow PPR algorithm conducts a localized random walk to surface multi-hop reasoning paths, without excessive noise.

c. Final Filtering

Irrelevant or low-value nodes (e.g., keyword-only nodes) are excluded, ensuring a refined and targeted retrieval set.


Evaluation & Benchmarks

NodeRAG has been benchmarked against NaiveRAG, GraphRAG, and LightRAG using datasets like HotpotQA, MuSiQue, and RAG-QA Arena.

Part I Table shows evaluations of NaiveRAG, HyDE, LightRAG, GraphRAG, and NodeRAG on<br>
HotpotQA and MuSiQue (accuracy and average tokens).<br>
Part II Table shows the fraction of “wins when comparing one RAG method against another
"/>

Key Results:

  • MuSiQue: NodeRAG achieved 46.29% accuracy, outperforming GraphRAG (41.71%) and LightRAG (36.00%).
  • HotpotQA: NodeRAG delivered comparable accuracy to GraphRAG (89.5% vs 89.0%) with 1.6k fewer retrieved tokens.
  • RAG-QA Arena (Lifestyle domain): NodeRAG achieved a 94.9% retrieval ratio, compared to GraphRAG’s 86.3% and LightRAG’s 81.7%, with fewer tokens.

These results highlight NodeRAG’s superior efficiency and accuracy, especially in multi-hop and summary-based QA.


Getting Started with NodeRAG

🔧 Requirements

  • Python
  • Sample .txt, .md, or .doc files
  • Anaconda or uv for dependency management
  • OpenAI API key (GPT-4o-mini recommended)

🧪 Setup & Installation

1. Clone the repository

git clone https://github.com/Terry-Xu-666/NodeRAG.git
cd NodeRAG
Enter fullscreen mode Exit fullscreen mode

2. Create a virtual environment

With Conda:

conda create -n NodeRAG python=3.10
conda activate NodeRAG
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

With uv (faster):

pip install uv
uv sync
uv pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

3. Prepare your files

Create a project folder with an input/ directory. Add your documents there.

4. Configure NodeRAG

python -m NodeRAG.build -f path/to/project_folder
Enter fullscreen mode Exit fullscreen mode

Edit the Node_config.yaml file:

model_config:
  model_name: gpt-4o-mini
  api_keys: YOUR_API_KEY

embedding_config:
  api_keys: YOUR_API_KEY
Enter fullscreen mode Exit fullscreen mode

5. Build the graph

python -m NodeRAG.build -f path/to/project_folder
Enter fullscreen mode Exit fullscreen mode

The first part of the process. Select y here.

Process of building the graph has finished

6. Run Queries

Create a main.py file:

from NodeRAG import NodeConfig, NodeSearch

config = NodeConfig.from_main_folder("/path/to/project")
search = NodeSearch(config)

ans = search.answer("Create a multiple choice question based on my resume.")
print(ans)
Enter fullscreen mode Exit fullscreen mode

🔍 Visualizing the Graph

Visualization of graph

Generate an HTML graph with:

python -m NodeRAG.Vis.html -f path/to/project_folder -n 600
Enter fullscreen mode Exit fullscreen mode

This will produce an index.html file you can open in a browser to view a compact visual of your heterograph.


Conclusion

NodeRAG brings a fresh, graph-driven perspective to RAG by integrating semantic, structural, and contextual layers into a single heterograph. Its fine-grained decomposition, explainability, and retrieval efficiency make it a compelling tool for anyone building advanced AI systems without enterprise-level infrastructure.

Whether you're building a personal assistant, a document search engine, or an AI tutor, NodeRAG allows you to create a domain-aware, multi-hop capable retrieval engine—without breaking the bank.


Resources


If you have questions while setting it up, feel free to reach out—I’d love to help.

Top comments (0)