Skip to main content

GraphRAG Cache

This package contains a collection of utilities to handle GraphRAG caching implementation.

Basic

This example shows how to create a JSON cache with file storage using the GraphRAG cache package's configuration system.

Open the notebook to explore the basic example code

Custom Cache

This example demonstrates how to create a custom cache implementation by extending the base Cache class and registering it with the GraphRAG cache system. Once registered, the custom cache can be instantiated through the factory pattern using either CacheConfig or directly via cache_factory, allowing for extensible caching solutions tailored to specific needs.

Open the notebook to explore the basic custom example code

Details

By default, the create_cache comes with the following cache providers registered that correspond to the entries in the CacheType enum.

  • JsonCache
  • MemoryCache
  • NoopCache
  • SQLiteCache

SQLiteCache stores JSON-serializable values in a local SQLite database. It uses WAL mode and short-lived connections so multiple workers can safely share the same database. Configure it with:

cache:
  type: sqlite
  storage:
    type: file
    base_dir: cache
  database_name: cache.db

The database is created within the configured file storage. SQLite requires local random-access file operations, so blob and Cosmos storage are not supported. Child caches use isolated namespaces within the same database.

All cache providers expose await cache.get_many(keys) for bulk reads. The result maps each existing, valid key to the same decoded value returned by get(). Missing and malformed entries are omitted, duplicate input keys appear at most once, and an empty input returns an empty dictionary. The default implementation remains compatible with custom Cache subclasses, while MemoryCache, NoopCache, and SQLiteCache provide backend-specific implementations. SQLite bulk reads use one worker dispatch and one connection, splitting large key sets into bounded SQL batches.

An opt-in warm-cache benchmark compares bulk reads across the memory, JSON, and SQLite providers without enforcing a machine-dependent performance threshold:

uv run pytest -s tests/unit/cache/test_cache_benchmark.py \
  --run-cache-benchmark

The benchmark reports median latency, entries per second, and time relative to SQLite for 1,000 entries. Setup time is excluded from the measurements.

The preregistration happens dynamically, e.g., JsonCache is only imported and registered if you request a JsonCache with create_cache(CacheType.Json, ...). There is no need to manually import and register builtin cache providers when using create_cache.

If you want a clean factory with no preregistered cache providers then directly import cache_factory and bypass using create_cache. The downside is that cache_factory.create uses a dict for init args instead of the strongly typed CacheConfig used with create_cache.

from graphrag_cache.cache_factory import cache_factory
from graphrag_cache.json_cache import JsonCache

# cache_factory has no preregistered providers so you must register any
# providers you plan on using.
# May also register a custom implementation, see above for example.
cache_factory.register("my_cache_impl", JsonCache)

cache = cache_factory.create(
    strategy="my_cache_impl", init_args={"some_setting": "..."}
)

...

Metadata

Release files for graphrag-cache 3.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphrag-cache 3.3.0
File Size Uploaded
graphrag_cache-3.3.0.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for graphrag-cache 3.3.0
File Interpreter ABI Platform
graphrag_cache-3.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.6 kB

Release files / graphrag_cache-3.3.0.tar.gz

Download URL graphrag_cache-3.3.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
35f9c2ddabf96cb9366bbf9a301242a09be4079127f6419e1a8ae20b0bf911a1
BLAKE2b-256 checksum
How to use checksums
0fc7309f2ca09e71a8a87029b13eb55bd94928ea3f467b7497bb5d0dc2e77c91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.17

Release files / graphrag_cache-3.3.0-py3-none-any.whl

Download URL graphrag_cache-3.3.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
440fe7cc9460d18ae72379da90b1af82812b19db826f3f3b9fde4eaafc048980
BLAKE2b-256 checksum
How to use checksums
d67a05fd20b32eba898a1cf67a1d13576ff494fd8345b7548863734dd9595383
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.17

Release history Release notifications | RSS feed

This release

3.3.0 This release

2 release files

3.2.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page