Skip to main content
The GraphRAG Python API provides programmatic access to indexing, querying, and prompt tuning functionality. This API allows you to integrate GraphRAG capabilities directly into your Python applications.

Warning

This API is under development and may undergo changes in future releases. Backwards compatibility is not guaranteed at this time.

Installation

The Python API is included with the GraphRAG package:

Core modules

The API is organized into three main modules:

Indexing API

Build knowledge graph indexes from your documents:
The indexing API enables you to create and update knowledge graph indexes programmatically. See the index API reference for details.

Query API

Perform searches over your indexed knowledge graph:
The query API provides four search methods with both standard and streaming variants. See the query API reference for details.

Prompt tuning API

Generate domain-specific prompts from your data:
The prompt tuning API automatically generates optimized prompts tailored to your specific domain and documents. See the prompt tune API reference for details.

Quick start

Here’s a basic workflow using the Python API:

Configuration

All API functions require a GraphRagConfig object. You can create this from a YAML file:
Or construct it programmatically:

Data formats

The API uses pandas DataFrames for data exchange. Indexed data is stored in Parquet format:
  • entities.parquet - Entity information
  • communities.parquet - Community structure
  • community_reports.parquet - Community summaries
  • text_units.parquet - Text chunks
  • relationships.parquet - Entity relationships
  • covariates.parquet - Claims and covariates (optional)

Error handling

API functions may raise exceptions. Use try-except blocks for proper error handling:

Next steps