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:

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

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:
3

Force overwrite (optional)

Use --force to overwrite existing configuration:
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.

Indexing methods

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.
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.

Advanced prompt tuning

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.

Query methods

GraphRAG supports four search methods:
Global search uses the entire knowledge graph to answer questions about the dataset as a whole.
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:

Streaming responses

Enable streaming for real-time output:
Use --streaming for long-form responses to see results as they’re generated.

Common workflows

Complete project setup

1

Initialize project

2

Add your documents

3

Configure API keys

Edit .env and add your API key:
4

Tune prompts (recommended)

5

Build the index

6

Query your data

Incremental updates

1

Add new documents

2

Update the index

3

Query updated index

Point queries to the update output:

Troubleshooting

Check configuration without indexing

Skip validation for non-LLM steps

Specify custom data directory

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