Skip to main content
The GraphRAG CLI provides a comprehensive set of commands for initializing projects, building knowledge graph indexes, and querying your data. All commands are accessible through the graphrag command.

Installation

Ensure GraphRAG is installed before using the CLI:
pip install graphrag

Available commands

The GraphRAG CLI includes five main commands:

init

Generate a default configuration file

index

Build a knowledge graph index

update

Update an existing index

prompt-tune

Generate custom prompts from your data

query

Query a knowledge graph index

Initialize a project

The init command creates a new GraphRAG project with default configuration files.
1

Run initialization

graphrag init --root ./my-project
This creates:
  • settings.yaml - Configuration file
  • .env - Environment variables for API keys
  • prompts/ - Directory with default prompt templates
  • input/ - Directory for source documents
2

Configure models

Specify custom models during initialization:
graphrag init \
  --root ./my-project \
  --model gpt-4o \
  --embedding text-embedding-3-large
3

Force overwrite (optional)

Use --force to overwrite existing configuration:
graphrag init --root ./my-project --force
The --force flag will overwrite your existing settings.yaml and prompts. Back up your customizations first.

Init command options

OptionShortDescriptionDefault
--root-rProject root directoryCurrent directory
--model-mDefault chat model to usegpt-4-turbo-preview
--embedding-eDefault embedding modeltext-embedding-3-small
--force-fForce initialization even if project existsfalse

Build an index

The index command processes your documents and builds a knowledge graph.
graphrag index --root ./my-project

Indexing methods

graphrag index --root ./my-project --method standard

Index command options

OptionShortDescriptionDefault
--root-rProject root directoryCurrent directory
--method-mIndexing method to usestandard
--verbose-vEnable verbose loggingfalse
--dry-runValidate config without executingfalse
--cache/--no-cacheEnable/disable LLM cachetrue
--skip-validationSkip preflight validationfalse
Use --dry-run to validate your configuration before running a full index. This helps catch configuration errors early.

Update an existing index

The update command incrementally updates an existing index with new documents.
graphrag update --root ./my-project
The update process:
  1. Detects new or modified documents in the input directory
  2. Processes only the changed documents
  3. Merges results with the existing index
  4. Outputs to update_output/ folder by default
Always run graphrag init --force between minor version bumps to ensure you have the latest config format before updating.

Update command options

OptionShortDescriptionDefault
--root-rProject root directoryCurrent directory
--method-mIndexing method to usestandard
--verbose-vEnable verbose loggingfalse
--cache/--no-cacheEnable/disable LLM cachetrue
--skip-validationSkip preflight validationfalse

Prompt tuning

The prompt-tune command generates custom prompts tailored to your data domain.
graphrag prompt-tune --root ./my-project

Advanced prompt tuning

graphrag prompt-tune \
  --root ./my-project \
  --domain "medical research"

Prompt-tune command options

OptionDescriptionDefault
--rootProject root directoryCurrent directory
--domainDomain of your input dataAuto-detected
--selection-methodText chunk selection method (random, top, auto)random
--n-subset-maxNumber of chunks to embed (auto mode)300
--kMax documents per centroid (auto mode)15
--limitNumber of documents to load (random/top)15
--max-tokensMax token count for prompt generation2000
--chunk-sizeSize of each text chunk200
--languagePrimary language for promptsAuto-detected
--outputDirectory to save promptsprompts
Use --selection-method auto for large datasets. It uses k-means clustering to select representative documents.

Query your index

The query command searches your knowledge graph index.
graphrag query "What are the main themes in the dataset?" \
  --root ./my-project \
  --method global

Query methods

GraphRAG supports four search methods:
Global search uses the entire knowledge graph to answer questions about the dataset as a whole.
graphrag query "What are the main themes?" \
  --method global \
  --community-level 2
Best for: High-level questions, dataset summaries, theme identification

Query command options

OptionShortDescriptionDefault
queryThe query string (required)-
--root-rProject root directoryCurrent directory
--method-mQuery algorithm (global, local, drift, basic)global
--data-dIndex output directoryAuto-detected
--community-levelLeiden hierarchy level2
--dynamic-community-selectionUse dynamic community selectionfalse
--response-typeDesired response formatMultiple Paragraphs
--streamingStream the responsefalse
--verbose-vEnable verbose loggingfalse

Custom response types

You can specify different response formats:
graphrag query "What is this about?" \
  --response-type "Single Sentence"

Streaming responses

Enable streaming for real-time output:
graphrag query "Complex research question" \
  --method global \
  --streaming
Use --streaming for long-form responses to see results as they’re generated.

Common workflows

Complete project setup

1

Initialize project

graphrag init --root ./my-research
2

Add your documents

cp ~/documents/*.txt ./my-research/input/
3

Configure API keys

Edit .env and add your API key:
GRAPHRAG_API_KEY=sk-your-key-here
4

Tune prompts (recommended)

graphrag prompt-tune --root ./my-research --domain "your domain"
5

Build the index

graphrag index --root ./my-research --verbose
6

Query your data

graphrag query "What are the main findings?" \
  --root ./my-research \
  --method global

Incremental updates

1

Add new documents

cp ~/new-documents/*.txt ./my-research/input/
2

Update the index

graphrag update --root ./my-research --verbose
3

Query updated index

Point queries to the update output:
graphrag query "What's new?" \
  --root ./my-research \
  --data ./my-research/update_output

Troubleshooting

Check configuration without indexing

graphrag index --root ./my-project --dry-run --verbose

Skip validation for non-LLM steps

graphrag index --root ./my-project --skip-validation

Specify custom data directory

graphrag query "my question" \
  --data ./custom/output/path

Next steps

Python API

Learn how to use GraphRAG programmatically

Configuration

Customize your GraphRAG settings

Prompt tuning

Optimize prompts for your domain

Azure setup

Configure Azure OpenAI integration

Build docs developers (and LLMs) love