Installation
API overview
GraphRAG provides three main API modules:Indexing API
Build knowledge graph indexes from your data
Query API
Search and query your knowledge graphs
Prompt tuning API
Generate custom prompts for your domain
Indexing API
The indexing API allows you to build knowledge graph indexes programmatically.Import the API
Basic indexing
Create a simple indexing pipeline:Advanced indexing options
build_index parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
config | GraphRagConfig | The GraphRAG configuration | Required |
method | IndexingMethod | str | Indexing method to use | IndexingMethod.Standard |
is_update_run | bool | Whether this is an incremental update | False |
callbacks | list[WorkflowCallbacks] | Callbacks for pipeline events | None |
additional_context | dict[str, Any] | Custom context for the pipeline | None |
verbose | bool | Enable verbose logging | False |
input_documents | pd.DataFrame | Override document loading with custom dataframe | None |
Query API
The query API provides four search methods for querying your knowledge graph.Import the API
Loading index data
Before querying, load the required parquet files:Global search
Use global search for high-level questions about the entire dataset:Local search
Use local search for specific entity-focused queries:DRIFT search
DRIFT combines local and global approaches:Basic search
Basic text similarity search without the knowledge graph:Search API parameters
Global search parameters
| Parameter | Type | Description |
|---|---|---|
config | GraphRagConfig | GraphRAG configuration |
entities | pd.DataFrame | Entities dataframe |
communities | pd.DataFrame | Communities dataframe |
community_reports | pd.DataFrame | Community reports dataframe |
community_level | int | None | Leiden hierarchy level (higher = smaller communities) |
dynamic_community_selection | bool | Enable dynamic community selection |
response_type | str | Response format description |
query | str | The query string |
callbacks | list[QueryCallbacks] | Optional callbacks |
verbose | bool | Enable verbose logging |
Local search parameters
| Parameter | Type | Description |
|---|---|---|
config | GraphRagConfig | GraphRAG configuration |
entities | pd.DataFrame | Entities dataframe |
communities | pd.DataFrame | Communities dataframe |
community_reports | pd.DataFrame | Community reports dataframe |
text_units | pd.DataFrame | Text units dataframe |
relationships | pd.DataFrame | Relationships dataframe |
covariates | pd.DataFrame | None | Covariates/claims dataframe |
community_level | int | Leiden hierarchy level |
response_type | str | Response format description |
query | str | The query string |
callbacks | list[QueryCallbacks] | Optional callbacks |
verbose | bool | Enable verbose logging |
Prompt tuning API
Generate custom prompts tailored to your data domain:Selection methods
- Random
- Top
- Auto (K-means)
Randomly select documents:
Query callbacks
Implement custom callbacks to track query execution:Complete example
Here’s a complete example combining indexing and querying:Error handling
Always handle potential errors in your pipeline:Next steps
CLI usage
Learn the command-line interface
Configuration
Understand configuration options
Best practices
Optimize your GraphRAG implementation
API reference
Detailed API documentation