Prompt Engineering Guide
πŸ˜ƒ Basics
πŸ’Ό Applications
πŸ§™β€β™‚οΈ Intermediate
🧠 Advanced
Special Topics
🌱 New Techniques
πŸ€– Agents
βš–οΈ Reliability
πŸ–ΌοΈ Image Prompting
πŸ”“ Prompt Hacking
πŸ” Language Model Inversion
πŸ”¨ Tooling
πŸ’ͺ Prompt Tuning
πŸ—‚οΈ RAG
πŸ”§ Models
🎲 Miscellaneous
πŸ“™ Vocabulary Resource
πŸ“š Bibliography
πŸ“¦ Prompted Products
πŸ›Έ Additional Resources
πŸ”₯ Hot Topics
✨ Credits
πŸ—‚οΈ RAG🟦 GraphRAG

GraphRAG

🟦 This article is rated medium
Reading Time: 3 minutes
Last updated on March 2, 2025

Valeriia Kuka

GraphRAG is a technique that enhances retrieval-augmented generation (RAG) by integrating graph-structured data into the retrieval and generation process. Unlike conventional RAG, which primarily retrieves and generates information from text or images, GraphRAG leverages graph-based relationships to improve information retrieval and reasoning.

Why Use GraphRAG?

  • Graphs naturally represent relationships between entities, such as knowledge graphs, social networks, and molecular structures.
  • Better retrieval mechanisms by leveraging graph structures instead of simple text similarity search.
  • Improved reasoning and multi-hop retrieval, essential for complex tasks like question answering and scientific discovery.

How GraphRAG Works

GraphRAG enhances traditional RAG by introducing five key components:

  1. Query processor: Prepares user queries by extracting entities, relationships, and structures from the text.
  2. Retriever: Fetches relevant information from graph-based data sources using entity linking, graph traversal, or deep learning embeddings.
  3. Organizer: Processes retrieved graph data by pruning irrelevant nodes, re-ranking results, and augmenting missing information.
  4. Generator: Uses models like Large Language Models (LLMs) or Graph Neural Networks (GNNs) to generate responses.
  5. Graph data source: Stores information in graph format, such as knowledge graphs, social networks, or citation networks.

How GraphRAG Differs from Traditional RAG

FeatureTraditional RAGGraphRAG
Data typeText, imagesGraph-structured data
RetrieverSemantic/lexical similarity searchGraph traversal, graph embeddings, entity linking
Context handlingIndependent text chunksInterconnected graph nodes and relations
ReasoningMostly single-hop or sequentialMulti-hop, structured, relational reasoning
ApplicationsGeneral knowledge tasksKnowledge graphs, drug discovery, scientific reasoning

Example of GraphRAG vs. RAG

Query: "What drugs treat epithelioid sarcoma and target the EZH2 gene?"

  • RAG approach: Retrieves documents mentioning "epithelioid sarcoma" and "EZH2 gene."

  • GraphRAG approach: Follows the graph structure:

    • Find the disease node ("Epithelioid Sarcoma").
    • Traverse the relation [indication] β†’ find drugs.
    • Traverse the relation [target] β†’ find genes.
    • Identify drugs at the intersection.

GraphRAG ensures structural reasoning instead of relying solely on text similarity.

How GraphRAG Works

1. Query processor

Transforms raw user queries into structured formats suitable for graph retrieval.

  • Named Entity Recognition (NER): Identifies graph-relevant entities (e.g., "Epithelioid Sarcoma" β†’ Disease node).
  • Relational extraction: Identifies query relationships (e.g., "What drugs treat this disease?" β†’ Find edges labeled [indication]).
  • Graph query structuring: Converts natural language to graph query languages (SPARQL, Cypher).

2. Retriever

Finds relevant graph elements (nodes, edges, subgraphs) for augmentation.

  • Entity linking: Maps entities in the query to nodes in the graph.
  • Relational matching: Identifies edges that match query relations.
  • Graph traversal: Expands from initial nodes to fetch multi-hop relations.
  • Deep learning embeddings: Uses Graph Neural Networks (GNNs) or transformers for retrieval.

3. Organizer

Refines retrieved information to improve relevance.

  • Graph pruning: Removes irrelevant nodes to reduce noise.
  • Re-ranking: Prioritizes important nodes or paths.
  • Graph augmentation: Complements missing data using external sources.
  • Verbalization: Converts structured graph data into natural language for LLM input.

4. Generator

Produces final responses using one of the following:

  • LLM-based generation: Converts structured graph data into text responses.
  • GNN-based classification: If the task requires a classification label (e.g., fraud detection).
  • Graph-based generation: Uses generative models (e.g., molecular design).

5. Graph data sources

  • Explicit graphs: Directly constructed from structured sources (e.g., Knowledge Graphs, citation networks).
  • Implicit graphs: Derived from unstructured data (e.g., co-occurrence in documents).
Note

You can find the GraphRAG code on GitHub.

Conclusion

GraphRAG significantly enhances retrieval-augmented generation (RAG) by integrating graph-based reasoning, enabling better accuracy, multi-hop retrieval, and structured reasoning for complex tasks.

Valeriia Kuka

Valeriia Kuka, Head of Content at Learn Prompting, is passionate about making AI and ML accessible. Valeriia previously grew a 60K+ follower AI-focused social media account, earning reposts from Stanford NLP, Amazon Research, Hugging Face, and AI researchers. She has also worked with AI/ML newsletters and global communities with 100K+ members and authored clear and concise explainers and historical articles.

Footnotes

  1. Sarmah, B., Hall, B., Rao, R., Patel, S., Pasquali, S., & Mehta, D. (2024). HybridRAG: Integrating Knowledge Graphs and Vector Retrieval Augmented Generation for Efficient Information Extraction. ↩