# GraphRAG

> Build a knowledge graph from your documents and query it with an LLM

- Category: Retrieval & Knowledge (RAG) / RAG Frameworks & Platforms
- Language: Python
- Licence: MIT
- Repository: https://github.com/microsoft/graphrag
- Website: https://microsoft.github.io/graphrag/
- Canonical page: https://ai-tldr.dev/tools/graphrag/

## In short

GraphRAG is Build a knowledge graph from your documents and query it with an LLM. It sits in the RAG Frameworks & Platforms category of the Retrieval & Knowledge (RAG) tools and is open-source, written in Python and licensed MIT. To get started: install GraphRAG.

## Overview

GraphRAG is a data pipeline from Microsoft Research that turns unstructured text into a structured knowledge graph using an LLM. Instead of only retrieving similar text chunks, it extracts entities and the relationships between them, then groups them into communities so the system can reason across a whole document set rather than one passage at a time.

It is aimed at developers and teams who want to ask broad, sense-making questions over a private collection of documents — for example summarizing the main themes across many files — where plain vector search tends to miss connections that span multiple sources.

As a RAG framework, GraphRAG runs as a command-line workflow: you point it at a folder of text, it indexes that text into graph and Parquet outputs, and then you query it with either a global search (over the whole corpus) or a local search (focused on specific entities). The project is a research demonstration, not an officially supported Microsoft product.

## What it does

- Extracts a knowledge graph of entities and relationships from raw text using an LLM
- Global search answers broad questions across the entire document set
- Local search focuses on specific entities and their direct relationships
- Command-line workflow: init, index, and query a project folder
- Writes indexed results to Parquet files in an output directory for reuse
- Prompt Tuning Guide to adapt extraction prompts to your own data

## Getting started

Install the package, initialize a project, add your text, index it, then query. GraphRAG needs an OpenAI or Azure API key and can use significant LLM resources, so start with a small dataset.

1. Install GraphRAG

   Install from PyPI. GraphRAG supports Python 3.10–3.12.

```bash
python -m pip install graphrag
```

2. Initialize a project

   Create the workspace files. This generates a .env file, a settings.yaml, and an input/ directory. Add your OpenAI or Azure key as GRAPHRAG_API_KEY in the .env file, and drop text files into input/.

```bash
graphrag init --root ./ragtest
```

3. Index your documents

   Run the indexing pipeline to build the knowledge graph. Results are written as Parquet files under the output directory. Indexing makes many LLM calls, so begin small.

```bash
graphrag index --root ./ragtest
```

4. Query the graph

   Ask a broad question over the whole corpus, or use --method local to focus on a specific entity and its relationships.

```bash
graphrag query --root ./ragtest "What are the top themes in this story?"
```

## When to use it

- Summarize the main themes across a large private document collection where vector search alone misses cross-document links
- Answer questions that require connecting facts spread over many separate files
- Explore entities and their relationships in a corpus, such as people, organizations, and how they connect
- Prototype a graph-based RAG approach over narrative or domain text before building a production system
