perf(passageRetrieval): cache the context-sidecar digest instead of re-hashing per query

↗ view on GitHub · Eli Ziff · 2026-07-31 · 0cadfd44

`paramsKey` re-read and re-hashed the whole contextJsonl enrichment file
every time it ran, and it runs twice per searchPassages call - once to
derive the sidecar path, once to compare against the stored params. On
the 2.5 MB Stage 18R headers file that is 3.12 ms per pass, 6.2 ms per
query, to recompute a value that is constant for the entire run.

Cached per (path, mtimeMs, size). The key stays content-addressed: a
headers file rewritten between calls changes size or mtime and is
re-hashed, and the cache only ever short-circuits a file that has not
moved.

Measured on 200 LegalBench mini queries at the crowned config with
contextWeight 2: 70.80 -> 62.82 ms/query (11%). Unchanged-output proof:
sha256 of every returned PassageHit array is byte-identical over all 200
(digest of digests
48cfdcb3367f7091329a2702bf715c84526ce0520abe07f0baf7677613d651a1), and
the sidecar selected is the same file. Plain (no-context) queries are
unaffected - that branch never hashed anything.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H9ToHYJVDxfeJcJwdzrP2H
Repository eliziff/Beaver
Author Eli Ziff <eliasziff@gmail.com>
Authored
Parents 53d3bed8
Stats 1 file changed , +30 , -7
Part of Legal grounding and retrieval research

Capture this commit into my fork

Download a Markdown prompt that tells Claude how to port this exact commit into your working tree. Run it via claude -p < capture-commit-0cadfd44.md from inside the repo you want the change in.

⬇ Download capture-commit-0cadfd44.md