RAG & Retrieval

A Gentle Introduction to Graph RAG

Why retrieving over a graph of entities and relationships beats flat document search for complex questions.

Key takeaways

  • Traditional LLMs like GPT-3/GPT-4 are static and cannot access new or domain-specific information without costly fine-tuning; RAG solves this with a Retriever (fetches relevant external knowledge) and a Generator (produces context-rich responses).
  • Graph RAG extends RAG by retrieving from a graph-based knowledge repository of nodes (entities) and edges (relationships), using those relationships to surface more relevant and nuanced information.
  • Graph RAG excels at global search (breadth traversal) for high-order, topic-level questions via community detection and hierarchical summaries, and at multi-hop questions that require linking distinct pieces of context.
  • It also suits local search (depth traversal) for hierarchical datasets (e.g., API docs, SEC 10-K reports) and for "connecting the dots" across chunks where naive similarity-based RAG treats chunks independently and fails to link related information.
  • A Graph RAG pipeline has two parts: an Indexer that turns raw documents into structured knowledge graphs, and a Retriever (an active research area) — one effective approach uses an LLM as a classifier to identify the query type before retrieval.
On this pagesections

    A Beginner’s Guide to Retrieval-Augmented Generation with Graphs

    By integrating external knowledge into AI models, RAG allows for more accurate and context-aware outputs. One of the latest innovations in this space is Graph RAG, which leverages graph structures to supercharge retrieval and reasoning processes. But what exactly is Graph RAG, and why is it a game-changer? Let’s break it down.

    What is Retrieval-Augmented Generation (RAG)?

    Before diving into Graph RAG, it’s important to understand the foundational concept of RAG. Traditional LLMs like GPT-3 or GPT-4 are trained on vast amounts of data but are inherently static. They cannot access new or domain-specific information unless fine-tuned, which can be costly and time-consuming.

    RAG solves this problem by integrating two key components:

    1. Retriever: Retrieves relevant external knowledge (e.g., from a document store, database, or API) based on the input query.
    2. Generator: Uses the retrieved knowledge to generate a more accurate and context-rich response.

    This approach makes LLMs more dynamic and capable of adapting to specialized or up-to-date knowledge without retraining.

    What is Graph RAG?

    Graph RAG takes the concept of RAG a step further by incorporating graph structures into the retrieval process. Graphs, consisting of nodes (entities) and edges (relationships), are a natural way to represent complex relationships and interconnections within data.

    In Graph RAG:

    • The retriever accesses information not just from a flat collection of documents but from a graph-based knowledge repository.
    • Relationships between nodes in the graph help guide the retrieval process, enabling more relevant and nuanced information to be surfaced.
    • The generator uses this enriched, structured knowledge to produce contextually aware and semantically richer outputs.

    When do we need Graph RAG?

    Graphs excel in scenarios where relationships and structure matter. Here’s why they’re a perfect fit for RAG:

    Global Search aka Breadth traversal in a KG

    • High-order thinking: Graph RAG with community detection, allows us to summarize closely associated networks of nodes based on modularity. This allows generating community level summaries, which represent a group of nodes. Technically, allowing us to create a hierarchy of summaries, allowing us to generate better responses for High-order questions, which require topic level understanding of the data.
    • Multi Hop Questions: Multi-hop questions consist of multiple sub-questions that need to be answered to address the overall query. For example, the question “What is graph RAG, and what are the key benefits of using graph RAG over regular RAG?” has two components: understanding graph RAG and comparing it to regular RAG. Answering multi-hop questions often requires pulling context from different and distinct sections, making them challenging to address using simple semantic similarity. This is particularly true for chain-type questions, where one part of the question depends on the answer to another. For instance, consider the question: “Who are the top 10 football players in the world, and what is the maximum number of goals scored in a season by the top two?” Here, the first step is to identify the top 10 players, and the second step requires using that information to determine the maximum goals scored by the top two players. This dependency highlights the complexity of multi-hop questions. In a traditional graph setup, insufficient contextual overlap often leads to irrelevant answers. However, using a knowledge graph enables us to represent each of the 10 players as individual nodes, with attributes such as their highest goals stored as node properties.

    Local Search aka Depth traversal in a KG (when we need to drill down)

    • Hierarchical datasets: Datasets that are inherently hierarchical are not well-suited for a simple RAG pipeline. For instance, API documentation is typically structured with a high-level topic, followed by subtopics, and further organized by REST methods. This makes it a perfect fit for Graph RAG, as graphs are well-suited to modeling hierarchical structures, capturing intricate details through nodes and relationships. Another example is financial documents, such as SEC 10-K reports. These reports are divided into sections, with Section 8 (Financial Overview) breaking down into subsections like Revenue, further categorized by segments. Using Graph RAG effectively captures these complex relationships within the hierarchy.
    • Connecting the dots: This is a scenario where traditional RAG often falls short. Naive RAG retrieves relevant information chunks based on similarity measures (e.g., vector embeddings or BM25) but treats each chunk as an independent unit, without understanding how they relate to one another. This limitation becomes evident in cases where answering a question requires identifying relationships between different chunks. For example, consider the query: “How does the profitability of a parent company depend on its subsidiaries?” A naive RAG might retrieve documents discussing the parent company’s profitability and others about its subsidiaries, but it lacks the ability to link this information. In contrast, Graph RAG excels in such scenarios by clearly defining relationships between nodes, enabling it to connect these pieces of information and provide a more coherent and insightful response.

    GraphRAG is better understood with an Example

    Let’s take an example, to understand this in detail. We will index a snippet from Paul Graham’s Essays using both a naive RAG and GraphRAG, and observe the difference in the response.

    Question: 

    Conventional RAG: 

    GraphRAG: 

    Comparing both outputs, we get how Graph RAG improves the answer quality over traditional RAG systems. Graph RAG achieves this, by pulling in context across different chunks, coupled with the community summaries (which will be analyzed in depth in upcoming blogs) allows us to fetch summarised information over multiple nodes. This allows the Graph RAG to give a comprehensive answer, while the traditional rag relies on the contextual similarity, which fails when a user asks a global question.

    What does it take to build a Graph RAG pipeline?

    GraphRag consists of two parts

    • Indexer

    Indexing Pipeline takes in raw documents and outputs structured knowledge graphs, which can then be leveraged by the Retriever to query and augment user query with retrieved information to generate better responses.

    • Retriever 

    The Retriever Pipeline is highly dependent on the specific architecture used and remains an active area of research. A particularly effective approach involves using a large language model (LLM) as a classifier, to identify the query type prior to performing the retrieval.

    In subsequent blogs as a part of the Graph RAG series, we will go into details of creating an end-to-end GraphRAG retrieval with a publicly available dataset.

    Frequently asked questions

    What is Retrieval-Augmented Generation (RAG)?

    RAG integrates two components: a Retriever that fetches relevant external knowledge (e.g., from a document store, database, or API) based on the input query, and a Generator that uses that retrieved knowledge to produce a more accurate, context-rich response — making static LLMs more dynamic without retraining.

    What is Graph RAG and how does it differ from regular RAG?

    Graph RAG incorporates graph structures into retrieval. Instead of pulling from a flat collection of documents, the retriever accesses a graph-based knowledge repository where nodes represent entities and edges represent relationships. Those relationships guide retrieval, enabling more relevant, nuanced, and semantically richer outputs than naive RAG.

    When should you use Graph RAG?

    When relationships and structure matter — for global/high-order questions needing topic-level understanding, multi-hop questions that span distinct sections, hierarchical datasets (such as API documentation or SEC 10-K reports), and "connecting the dots" scenarios where answers depend on links between separate chunks that naive RAG cannot make.

    What are the components of a Graph RAG pipeline?

    Two parts: an Indexer that takes raw documents and outputs structured knowledge graphs, and a Retriever that queries those graphs to augment the user query. The retriever's architecture is an active research area; one effective approach uses an LLM as a classifier to identify the query type before retrieval.

    See what your engineers can ship in production

    Dataworkz is the agentic AI platform enterprises trust to put AI agents into production. Teams build production-ready agents in days, every decision stays traceable, and every agent has ROI attached.

    Explore the platform