Skip to main content
GraphRAG’s caching system stores language model responses to avoid redundant API calls. This significantly improves performance and reduces costs when re-indexing or iterating on your pipeline.

Why caching matters

LLM API calls are typically:
  • Expensive (per-token pricing)
  • Slow (network latency + generation time)
  • Rate-limited (requests per minute)
Caching helps by:
  • Reducing API costs by 90%+ on re-runs
  • Speeding up development iterations
  • Avoiding rate limit issues
  • Enabling incremental workflow development
During prompt tuning and development, caching can save hours of processing time and hundreds of dollars in API costs.

How caching works

GraphRAG caches LLM responses based on:
  1. Model instance name - Different workflows use different cache partitions
  2. Input prompt - Exact prompt text including all parameters
  3. Model configuration - Model name and generation parameters
When a request is made:
  1. GraphRAG checks the cache for a matching entry
  2. If found, returns the cached response immediately
  3. If not found, calls the LLM and stores the response

Cache types

Stores responses in JSON files, persisted across runs:
Cache directory structure:

Memory cache

Stores responses in memory, lost when process ends:
Memory cache is only useful for:
  • Testing cache behavior
  • Single-run pipelines where persistence isn’t needed
All cached data is lost when the process terminates.

No cache

Disable caching entirely:
Only disable caching if you need guaranteed fresh responses or are running in a stateless environment.

Cache storage backends

File storage (default)

Best for local development:
Advantages:
  • Simple and fast
  • Easy to inspect and debug
  • No external dependencies
  • Works offline
Disadvantages:
  • Not shareable across machines
  • Requires disk space

Azure Blob Storage

Best for team collaboration:
Advantages:
  • Share cache across team members
  • Persist cache in cloud
  • Automatic backup and versioning
  • Scale to large datasets
Disadvantages:
  • Requires Azure subscription
  • Network latency for cache lookups
  • Storage costs

Azure Cosmos DB

Best for high-scale production:
Advantages:
  • Global distribution
  • High availability
  • Advanced query capabilities
  • Automatic indexing
Disadvantages:
  • Higher costs than Blob Storage
  • More complex setup
  • Overkill for most use cases

Cache partitioning

GraphRAG partitions cache by model_instance_name to keep different workflow steps separate:
Each model_instance_name creates a separate cache partition, allowing you to clear or preserve specific workflow caches independently.

Managing the cache

When cache is used

Cache hits occur when:
  • Re-running indexing with same data and prompts
  • Testing different downstream workflows
  • Iterating on post-extraction processing
  • Resuming interrupted indexing runs

When cache is bypassed

Cache misses occur when:
  • Input data changes
  • Prompts are modified
  • Model configuration changes
  • New documents are added
  • model_instance_name changes

Clearing the cache

Clear cache when you need fresh results:
Or selectively clear specific workflows:
Clearing cache means re-running all LLM calls, which can be expensive and time-consuming. Only clear when necessary.

Cache optimization strategies

Strategy 1: Persistent cache for development

Use file-based JSON cache during development:
Benefits:
  • Fast local access
  • Survive process restarts
  • Easy to inspect and debug

Strategy 2: Shared cache for teams

Use Azure Blob Storage for team collaboration:
Benefits:
  • Share cache across team members
  • Reduce duplicate API calls
  • Save collective API costs

Strategy 3: Separate caches per experiment

Use different cache directories for different experiments:
Benefits:
  • Compare different approaches
  • Preserve baseline results
  • Easy rollback to previous configs

Strategy 4: Disable cache for production

Disable caching in production if you need guaranteed fresh results:
Benefits:
  • No stale data
  • Predictable behavior
  • No cache management overhead

Cost considerations

Cache effectiveness varies by workflow:
High cache value - Most expensive operation
  • Processes every text chunk through LLM
  • Multiple gleaning passes increase costs
  • Cache saves 80-95% of extraction costs on re-runs
Medium cache value - Moderate costs
  • Summarizes entity descriptions
  • Fewer calls than extraction
  • Cache saves 70-90% on re-runs
Medium cache value - Report generation costs
  • Generates one report per community
  • Can be expensive for large graphs
  • Cache saves 80-95% on re-runs
High cache value - If enabled
  • Similar to entity extraction
  • Disabled by default
  • Cache essential when tuning claim prompts

Example: Development workflow

Optimal caching strategy for development:
1

Initial run with cache

Run full indexing - cache fills with LLM responses
2

Iterate on prompts

Modify prompts in prompts/ directoryClear specific cache partition:
Re-run indexing - only re-extracts, reuses downstream cache
3

Tune downstream workflows

Modify chunking, clustering, or other settingsKeep extraction cache intact:
Re-run indexing - reuses expensive extraction cache
4

Final production run

Optionally disable cache for clean run:
Or keep cache for faster production updates

Troubleshooting

Cache not being used

Even small prompt modifications invalidate cache. Ensure prompts are identical for cache hits.
Changing model, temperature, or other parameters bypasses cache.
Modified source documents generate different prompts, missing cache.
Verify cache directory exists and has write permissions.

Cache growing too large

Remove cache directories for completed experiments:
Only cache expensive operations:
Archive and compress inactive cache:

Best practices

1

Always enable caching during development

Use JSON file cache to speed up iterations
2

Back up cache before major changes

Copy cache directory before clearing or modifying prompts
3

Use blob cache for team projects

Share cache across team to reduce collective API costs
4

Clear cache selectively

Only clear partitions that need refresh, preserve others
5

Monitor cache effectiveness

Check logs to verify cache hit rates

Next steps

Storage

Learn about other storage configurations

Settings reference

Complete configuration options

LLM models

Configure language models

Prompt tuning

Optimize prompts with caching