Microsoft GraphRAG: A Graph-Based Retrieval-Augmented Generation System

Jun 12, 2026

Introduction

Traditional Retrieval-Augmented Generation (RAG) systems often struggle with “global” questions that require a holistic understanding of a dataset. While standard vector search is excellent at finding specific needles in haystacks, it frequently fails to describe the haystack itself. Microsoft GraphRAG, an open-source project with over 20,000 GitHub stars, addresses this limitation by using knowledge graphs to structure unstructured data. By combining Large Language Models (LLMs) with graph-based indexing, GraphRAG enables developers to build search systems that can both answer specific queries and provide high-level thematic summaries of massive document collections.

What Is GraphRAG?

GraphRAG is a modular, graph-based Retrieval-Augmented Generation system developed by Microsoft Research. It is designed to extract structured knowledge from unstructured text files, such as PDFs, logs, or research papers. Unlike standard RAG, which relies solely on vector similarity to retrieve relevant text chunks, GraphRAG builds a multi-layered knowledge graph of entities and relationships. It uses the Leiden algorithm for community detection to group related entities into hierarchical clusters. This allows the system to generate “community summaries” that provide a top-down view of the data, making it uniquely capable of answering complex, aggregate questions that traditional RAG systems typically ignore or hallucinate.

Why GraphRAG Matters

The primary value proposition of GraphRAG lies in its ability to solve the “lost in the middle” and “global context” problems inherent in baseline RAG. In a baseline system, if you ask “What are the main themes in this 500-page document?”, the system might retrieve the top 10 most relevant chunks based on vector math, but those chunks cannot represent the entire document. GraphRAG matters because it pre-summarizes the entire dataset into a graph structure. When a global query is made, the engine queries these summaries rather than the raw text, resulting in a significantly higher retrieval accuracy for thematic and high-level questions.

Furthermore, GraphRAG provides a modular architecture. Developers can customize the indexing pipeline, swap out different LLMs, and tune the community detection parameters to fit specific domain requirements. This level of control is essential for enterprise applications where data relationships are as important as the data points themselves. By leveraging graph technology, Microsoft has provided a path toward more reliable, explainable, and comprehensive AI-driven search experiences.

Key Features

  • Graph-Based Indexing: Automatically extracts entities, relationships, and claims from unstructured text to build a comprehensive knowledge graph.
  • Community Detection: Uses the Leiden algorithm to cluster related entities into hierarchical groups, enabling multi-scale analysis of the dataset.
  • Global Search: A specialized query engine that aggregates community summaries to provide holistic answers to broad questions across the entire corpus.
  • Local Search: Combines traditional vector search with graph data to provide precise, context-aware answers for specific entities and their immediate neighbors.
  • Prompt Tuning: Includes built-in tools to automatically generate and optimize prompts for entity extraction and summarization based on the specific dataset.
  • Modular Pipeline: Allows for deep customization of the data ingestion process, including support for various storage backends and LLM providers.
  • Incremental Updates: Designed to handle large-scale data with workflows that support indexing and querying efficiently as new data is added.

How GraphRAG Compares

Understanding where GraphRAG fits in the current AI landscape requires comparing it against traditional search methods and standard RAG implementations. While more computationally expensive during the indexing phase, its retrieval capabilities for complex queries are significantly superior.

Feature Baseline RAG Microsoft GraphRAG Standard Search
Retrieval Method Vector Similarity Graph-Based + Vector Keyword Match
Global Summarization Poor / None Excellent None
Complex Queries Limited High Accuracy Ineffective
Indexing Speed Fast Slower (LLM-Heavy) Instant
Operational Cost Low High (Token usage) Minimal

Baseline RAG excels at retrieving specific snippets (e.g., “What is the price of product X in the 2023 catalog?”). However, it fails when the context is distributed across many pages (e.g., “What are the recurring themes across all 2023 product reviews?”). GraphRAG bridges this gap by creating a synthetic structure that summarizes relationships ahead of time. While it requires more LLM tokens during the indexing phase, it drastically reduces hallucinations by providing the LLM with a structured summary rather than a disorganized collection of text chunks.

Getting Started: Installation

GraphRAG is distributed as a Python package. It requires Python 3.10 or higher. The installation process involves setting up the core library and then initializing a workspace folder for your data.

Standard Pip Installation

pip install graphrag

Setting Up Your Workspace

After installation, you need to initialize a folder where your input data and configuration files will reside. This command creates a settings.yaml file and an .env file for your API keys.

python -m graphrag.index --init --root ./rag-test

Prerequisites

  • An OpenAI API Key or access to Azure OpenAI Service.
  • A directory containing your raw text files (e.g., ./rag-test/input).

How to Use GraphRAG

The workflow for using GraphRAG is divided into two primary stages: Indexing and Querying. The indexing phase is the most critical as it is where the knowledge graph is constructed and communities are identified.

1. The Indexing Phase

Run the indexer on your root directory. During this step, GraphRAG will call the LLM to extract entities, generate relationship descriptions, and create community summaries. Depending on the size of your dataset, this can take several minutes to several hours.

python -m graphrag.index --root ./rag-test

2. The Querying Phase

Once the index is built, you can use the query engine. GraphRAG offers two main search modes: global for broad summary questions and local for specific entity-based questions.

# Global Search Example
python -m graphrag.query --root ./rag-test --method global "What are the core themes of this dataset?"

Code Examples

Developers often want to interact with GraphRAG programmatically rather than just through the CLI. Below is a conceptual example of how the query engine integrates with your application logic.

Local Search Query

from graphrag.query.context_builder.entity_extraction import EntityExtractor
from graphrag.query.structured_search.local_search.search import LocalSearch

# Configure the search engine with your context and LLM
search_engine = LocalSearch(
    context_builder=my_context_builder,
    token_encoder=my_encoder,
    llm=my_llm_client,
)

# Execute a local search
result = await search_engine.asearch("How does the protagonist relate to the antagonist?")
print(result.response)

Custom Prompt Tuning

GraphRAG allows you to tune prompts for your specific domain (e.g., medical, legal). Using the built-in prompt tuner helps the indexer identify the right entities.

python -m graphrag.prompt_tune --root ./rag-test --domain "legal contracts" --output ./rag-test/prompts

Real-World Use Cases

  • Scientific Research Analysis: Summarizing hundreds of research papers to find connections between different studies that are not explicitly cited together.
  • Customer Support Intelligence: Analyzing thousands of support tickets to identify common underlying technical issues that may not be apparent in individual tickets.
  • Legal Discovery: Mapping relationships between entities in complex legal cases involving large volumes of email correspondence and document trails.
  • Cybersecurity Threat Intelligence: Connecting disparate indicators of compromise across multiple logs to visualize the broader scope of a persistent threat.

Contributing to GraphRAG

Microsoft welcomes community contributions to the GraphRAG repository. Since the project is in a state of rapid development, contributors should first read the CONTRIBUTING.md file in the repo. Common areas for contribution include adding support for local LLMs (like Ollama or vLLM), improving the community detection algorithms, and adding new data connectors. The project follows the Microsoft Open Source Code of Conduct, ensuring a respectful and welcoming environment for all developers.

Conclusion

GraphRAG represents a significant leap forward in how we interact with large datasets using Large Language Models. By moving beyond simple vector similarity and embracing knowledge graphs, Microsoft has provided a robust framework for systems that actually understand the structure of the data they retrieve. While it requires more upfront computation and token usage, the trade-off is a system that can answer the most difficult questions developers face when building AI search: “What is this data actually about?”

If you are building an application that needs to synthesize information across thousands of documents, GraphRAG is likely the right choice. Start by testing it on a small subset of your data, explore the prompt tuning capabilities, and join the growing community of developers moving from baseline RAG to more sophisticated, graph-aware architectures.

What is GraphRAG and how is it different from normal RAG?

GraphRAG is a graph-based Retrieval-Augmented Generation system. Unlike normal RAG which uses vector similarity to find individual text chunks, GraphRAG builds a knowledge graph of entities and relationships, allowing it to provide global summaries and thematic analysis across an entire dataset.

How do I install GraphRAG?

You can install GraphRAG using pip by running ‘pip install graphrag’. After installation, you must initialize your workspace using ‘python -m graphrag.index –init’ and configure your API keys in the generated .env file.

Does GraphRAG require a specific LLM?

GraphRAG is optimized for OpenAI and Azure OpenAI models like GPT-4. However, it is designed with a modular architecture, and the community is actively working on integrations for local LLMs via tools like Ollama or LiteLLM.

What is the Leiden algorithm in GraphRAG?

The Leiden algorithm is used during the indexing phase to perform community detection. It identifies clusters of related entities in the knowledge graph, which GraphRAG then uses to create hierarchical summaries of the data.

Can I use GraphRAG for real-time data?

GraphRAG is currently best suited for static or slowly changing datasets because the graph indexing process is computationally expensive. While it supports incremental updates, it is not yet designed for high-frequency real-time data ingestion.

Is GraphRAG free to use?

Yes, GraphRAG is open-source under the MIT License. However, running the indexer and query engine requires making calls to LLM providers (like OpenAI), which will incur costs based on your token usage.

How does GraphRAG vs Baseline RAG compare for cost?

GraphRAG is generally more expensive than baseline RAG because it requires extensive LLM processing during the indexing phase to extract entities and summarize communities. However, it often reduces costs during the query phase for complex questions by providing more direct answers.