Skip to main content

Content-addressable LLM response cache + replay layer. redb + RFC 8785 JCS + BLAKE3. Drop-in for f3dx, openai, anthropic.

Project description

f3dx-cache

LLM testing burns money. A 200-test suite re-running the same prompts against gpt-4o costs $4-20/run; a 2000-test suite costs more than a junior dev hour. Salesforce published a $500k/year saving from a mock-LLM CI rig in 2024. Every team running evals pays this tax.

f3dx-cache is the Rust + redb cache that makes the tax go to zero. Identical (model, messages, tools, temp) requests fingerprint identically via RFC 8785 JCS + BLAKE3 and the cached response returns at <100µs. First test run records; every subsequent run replays. The model never gets called twice for the same input.

pip install f3dx-cache
import pytest
from f3dx_cache import Cache

@pytest.mark.f3dx_cache
def test_extract_invoice_total(f3dx_cache_obj: Cache):
    req = {"model": "gpt-4o", "messages": [{"role": "user", "content": "..."}]}
    cached = f3dx_cache_obj.get(req)
    if cached is None:
        resp = call_openai(req)            # only on cold-cache; happens once
        f3dx_cache_obj.put(req, resp.body, model=resp.model)
        cached = resp.body
    assert b'"total":42' in cached

pytest -p f3dx_cache autoloads the plugin. Cold run: real OpenAI calls + records. Warm run: zero token cost, ~5ms total runtime.

Why redb + JCS + BLAKE3

redb is the only embedded ACID store in pure Rust with PyO3-friendly abi3 wheels (no C toolchain in the wheel). RocksDB and LMDB carry C dependencies that break the cross-platform wheel story.

RFC 8785 JSON Canonicalization Scheme sorts object keys + normalizes numeric forms so semantically identical requests collide. Without canonicalization, {"model":"gpt-4","temp":0} and {"temp":0,"model":"gpt-4"} would fingerprint differently and the cache would miss.

BLAKE3 is faster than SHA-256 by 10-30x and the gold standard for content addressing in 2026.

Architecture

f3dx-cache/
  crates/
    f3dx-cache/      core: redb tables, JCS canonicalize, BLAKE3 fingerprint
    f3dx-replay/     read JSONL/parquet trace bundles, diff outputs
    f3dx-cache-py/   PyO3 bridge cdylib (the only crate with #[pymodule])
  python/
    f3dx_cache/
      __init__.py        Cache class wrapping the native PyO3 surface
      pytest_plugin.py   pytest11 entry point: @pytest.mark.f3dx_cache

Three redb tables in one file:

  • requests fingerprint -> canonicalized request bytes
  • responses fingerprint -> response bytes
  • meta fingerprint -> {created_at_ms, hit_count, model, system_fingerprint, response_duration_ms}

Replay layer

f3dx-replay reads a JSONL trace bundle (the same shape f3dx_trace::emit_trace_row writes) and diffs outputs against a target config. Layered determinism modes:

Mode What it compares Cost Use case
bytes exact byte equality <1µs structured-output tests where canonical JSON is expected
structured parsed JSON post-canonicalization ~10µs tool-call extraction, agent step output
embedding embedding-cosine under threshold ~10ms natural-language responses (V0.1)
judge LLM-as-judge call ~500ms semantic correctness checks (V0.1)
from f3dx_cache import diff, read_jsonl

rows = read_jsonl("traces.jsonl")
for row in rows:
    new_output = replay_against(row["model"], row["prompt"])
    ok, note = diff(row["output"], new_output, mode="structured")
    if not ok:
        print(f"regression on {row['trace_id']}: {note}")

Layout

f3dx-cache/
  crates/                 cargo workspace (3 crates)
  python/f3dx_cache/      Python wrapper + pytest plugin
  pyproject.toml          maturin build, pytest11 entry-point
  Cargo.toml              cargo workspace root + workspace lints
  rust-toolchain.toml     pinned to 1.90.0
  tests/                  integration tests
  bench/                  reproducible benches
  examples/               drop-in patterns for f3dx, openai, anthropic SDKs

What this is not

f3dx-cache is a TEST-MODE primitive. Production traffic does not point at it. The headline win is $0 + 2sec CI runs, not $0 + 2sec for end users.

f3dx-cache is not a semantic cache. GPTCache does embedding-similarity matching for production cache hits — wrong abstraction for testing, where false positives mask regressions.

f3dx-cache is not tied to f3dx. Any LLM SDK that emits JSON-shaped requests works (openai, anthropic, instructor, litellm, langchain, ai-sdk).

Sibling project

f3dxpip install f3dx. Rust runtime your Python imports. Drop-in for openai + anthropic SDKs. The trace sink that f3dx-cache and f3dx-replay consume is f3dx_trace::emit_trace_row from this package.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

f3dx_cache-0.0.2-cp310-abi3-win_amd64.whl (597.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

f3dx_cache-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl (875.6 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

f3dx_cache-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (663.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

f3dx_cache-0.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (607.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

f3dx_cache-0.0.2-cp310-abi3-macosx_11_0_arm64.whl (581.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

f3dx_cache-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl (648.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file f3dx_cache-0.0.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: f3dx_cache-0.0.2-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 597.3 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for f3dx_cache-0.0.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f794322bfd4c1b72cc649ff1d86d36bc516b121e94c837b84be3cf7b00d79c58
MD5 630d9d5f0fdaf77bed3d0e03927200b3
BLAKE2b-256 5140aea9d21eb950233ecc4d921406f6003a503d400fe68e621ac79bd153ada6

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.2-cp310-abi3-win_amd64.whl:

Publisher: release.yml on smigolsmigol/f3dx-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx_cache-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 25ce46ae22153f556c094fdcfdbbc9d607285a2e454e71ed60dbcc94bca5615c
MD5 a49bb451ebbb73e3cd3124e8830f8574
BLAKE2b-256 0797c50d70de87f418dae00d925274c23fbf5f5e1626ff1734d273fcccb8fb40

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx_cache-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 48e5fb520c3e9787e7b980442cf300d8da2ab4b5e62cdc1642c159365b2675ab
MD5 9e520d88b43cc63165f076a25001ccd8
BLAKE2b-256 0353bd4cdcb95ba2bd02d17230c71d3ea943d8292caf653abb78dcb0d57583e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx_cache-0.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 af0cde629cd239bc7bb4a219272f9bd3e17709fb3beceae16a127af378598c3c
MD5 222c1eb7fcacd033a8dfd0255ea61c2a
BLAKE2b-256 c0634caf598bbc8d71cd0d55988e6d78611ae17b5c471ac077b95537871f233f

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on smigolsmigol/f3dx-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx_cache-0.0.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e6ec9a5abfda40477f595c40ca4c490200110032521e5ce7d77595255e4c40e
MD5 b5acf27bfe33e13aac0a2ff63d3123f0
BLAKE2b-256 d27b93476b97eb67e1643f257aca2d5a4ea6b9a22f72515acc64164e3f07f05d

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.2-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on smigolsmigol/f3dx-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file f3dx_cache-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 62617fd5c258d51c59114941746463f618fc9f67a822de8943c09df19e6a43db
MD5 50318f9082708d3c8bff278e24582678
BLAKE2b-256 676be4a7e9c7b05994c2c00f8be7982a45cfae0ef84c5c247c82041c6ba6e07d

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on smigolsmigol/f3dx-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page