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

OpenSSF Scorecard

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 projects

The f3d1 ecosystem:

  • f3dx - Rust runtime your Python imports. Drop-in for openai + anthropic SDKs with native SSE streaming, agent loop with concurrent tool dispatch, OTel emission. pip install f3dx.
  • tracewright - Trace-replay adapter for pydantic-evals. Read an f3dx or pydantic-ai logfire JSONL trace, get a pydantic_evals.Dataset. pip install tracewright.
  • pydantic-cal - Calibration metrics for pydantic-evals: ECE, MCE, ACE, Brier, reliability diagrams, Fisher-Rao geometry kernel. pip install pydantic-cal.
  • f3dx-router - In-process Rust router for LLM providers. Hedged-parallel + 429/5xx hot-swap. pip install f3dx-router.
  • f3dx-bench - Public real-prod-traffic LLM benchmark dashboard. CF Worker + R2 + duckdb-wasm. Live.
  • llmkit - Hosted API gateway with budget enforcement, session tracking, cost dashboards, MCP server. llmkit.sh.
  • keyguard - Security linter for open source projects. Finds and fixes what others only report.

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.3-cp310-abi3-win_amd64.whl (601.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

f3dx_cache-0.0.3-cp310-abi3-musllinux_1_2_x86_64.whl (879.1 kB view details)

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

f3dx_cache-0.0.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (667.3 kB view details)

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

f3dx_cache-0.0.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (609.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

f3dx_cache-0.0.3-cp310-abi3-macosx_11_0_arm64.whl (584.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

f3dx_cache-0.0.3-cp310-abi3-macosx_10_12_x86_64.whl (652.6 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for f3dx_cache-0.0.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7e4b7bdce545e4637894fad6d0112a35d0d24cbca43059a09de80577e78c7489
MD5 d83f552a21943af3ddc6aa3d306a2d0b
BLAKE2b-256 a0eb2abce866df08ca39a733516fd2ad8e719254c8569010a777cd13c5361e9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.3-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.3-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9aa4a1ff452f73b2378222291c0666c9980d82c6dfaf8cdc203c51c4f1250274
MD5 53cb01e4415095cf9f84876225e72c1d
BLAKE2b-256 3d12b390538939b12194bc62a5e0d85b4c7a41e8d52daaac46c480d06d2f6480

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.3-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.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fe78f35292145fc106ca7a891c8d4a711b5bb5a6f491627cb91acbddde5c9a2b
MD5 11e926dcd14acf6f47a998c502886199
BLAKE2b-256 d7f7aeac587fbb4079e8ed45732edb619dde31c3ce0c6b94303e60f851c37cf3

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.3-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.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6fa2edf46e8108ff01c89e1b7118acf7d155e36f214ebab619d1fc2c83a67387
MD5 bc735c69f7ac9515ec40e7be61b110b8
BLAKE2b-256 c92b18885dd7e87b54240fb28830aa3495923035a7e1cc4fc5192ac4d7a747c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.3-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.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f0f422bf3682cc75849be05ee2feda27364589ed30c90f691f4c527b10f0343
MD5 155f570ec2688a9077abd01e52d65843
BLAKE2b-256 a9dd2bb2ce70400e17d4ab8d779c381f573766363de4beeb9c3c59568be8b2b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.3-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.3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for f3dx_cache-0.0.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d55d7a174e89ffdaf7166e654c202ca985fe90081e8b5650fa2c8d79387ac54c
MD5 7aa71e78602c9338066e34336ddbeee0
BLAKE2b-256 a8bb255b1785d6c1c2ccc5efd3596f5982d8b968bb8dfdf40d61e41e293e68a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for f3dx_cache-0.0.3-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