feat(rag): LRU/TTL rerank cache (key-tight + persistence) + MMR - #1329
Merged
Conversation
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
No reviewable files after applying ignore patterns. |
IgorGanapolsky
force-pushed
the
feat/rerank-cache-20260731
branch
from
August 1, 2026 15:41
7c01dae to
eb2882b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c01dae765
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
IgorGanapolsky
force-pushed
the
feat/rerank-cache-20260731
branch
from
August 1, 2026 16:18
b457fad to
39cb4cb
Compare
IgorGanapolsky
force-pushed
the
feat/rerank-cache-20260731
branch
from
August 1, 2026 16:35
39cb4cb to
e0ed7c0
Compare
added 3 commits
August 1, 2026 13:55
…lift) Adds an LRU+TTL cache over the expensive CE/ColBERT/LLM rerank (scoreCandidates) inside rerank(). Production-safe & hermetic: - Keyed on query + strategy + limit + llm-flag + canonical (order-insensitive) candidate-set fingerprint; a changed upstream set / index refresh misses. - Write-disabled when an embedder/chat is injected (test fakes) so fake vectors never poison the prod cache; production path caches by default, no flag needed. - HERMES_RERANK_NO_CACHE=1 / --no-cache / options.disableCache force off (fail-open: cache faults never change matches, only latency). - TTL default 5min, LRU cap 256; cacheHit/cacheKey surfaced on result; matches cloned on hit (no cross-call mutation). Latency/cost lift: skips CE/ColBERT/LLM embeddings on repeated queries on the always-running Hermes process. Does NOT touch retrieval-dual-path.js / rag-stack-scorecard.js (owned by in-flight #1314/#1301). Single-file change to post-#1317 retrieval-rerank.js. Verified non-ownership: plan.md §2 grep + open-PR file-scan both NONE for tools/retrieval-rerank.js + tests/test-retrieval-rerank.js. Base origin/main@cacfc79a9.
Maximal Marginal Relevance greedy re-rank: (1-λ)*rerankScore - λ*max_overlap. λ = options.diversityLambda (default 0 => no-op, so A+ nDCG@K scores/rankings unchanged). Lexical-overlap redundancy penalty => zero extra model calls; opt-in (CLI --rerank-diversity, env HERMES_RERANK_DIVERSITY). Pure mmrReorder + 3 hermetic tests (determinism, no-op, redundancy-demotion).
Address both P1 review comments on #1329: - Comment #1 (key collision): canonicalCandidates now hashes the full snippet (slice 0,2000 - covers CE 1200 / ColBERT 2000 windows) and start/end line, so snippets differing beyond char 800 or shifted source coords are natural misses, never stale hits. - Comment #2 (dead cache): implement the suggested cross-process persistence -- RerankCache(persistPath) loads on construction and write-throughs (atomic temp+rename, fail-open). The module singleton opts in via HERMES_RERANK_CACHE_PATH env (default null => in-memory, hermetic for tests). Doc corrected: rerank is spawnSync-per-query; cache hits in-process same-(query,strategy) reranks and, with the env set, across CLI/eval invocations.
IgorGanapolsky
force-pushed
the
feat/rerank-cache-20260731
branch
from
August 1, 2026 17:55
e0ed7c0 to
891c06f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rerun: LRU/TTL rerank cache (key-tightened + cross-process persistence) + MMR
Two rerank-layer lifts for the retrieval/eval stack:
tools/retrieval-rerank.js) — skips theexpensive CE/ColBERT/LLM scoring stage on repeat queries (in-process, and
across CLI/eval invocations when
HERMES_RERANK_CACHE_PATHis set).--rerank-diversity <0-1>; lambda=0 is a no-op)— de-duplicates near-duplicate candidates so a single snippet stops crowding the
top of the ranked list.
Review Comment #1 (cache key collision) - FIXED
canonicalCandidatesnow hashes the full snippet (0,2000 — covers CE's 1200 andColBERT's 2000 char consumption) plus
start_line/end_line. Snippets matching forthe first 800 chars but diverging after (or shifted source coords forwarded by
dualPathRetrieve) are now natural misses, never stale hits. Regression test added.Review Comment #2 (cache never hits) - FIXED
rerankis reached viaspawnSyncper query for CLI/eval, so a plain moduleMapis process-local. Added opt-in cross-process persistence:
RerankCacheacceptspersistPath, loads on construction, and write-throughs (atomic temp+rename,fail-open) on each
set. The module singleton enables it viaHERMES_RERANK_CACHE_PATH(default null => in-memory, hermetic for tests). In-process repeated reranks (same
query + strategy + candidate-set) hit automatically; CLI/eval repeats hit when the env
is set. Doc corrected to drop the false "always-on LaunchAgent hits it" claim.
Verification
node --check tools/retrieval-rerank.js tests/test-retrieval-rerank.js- OKnode tools/retrieval-rerank.js --self-test- OKnode --test tests/test-retrieval-rerank.js- 22/22 hermetic pass (env scrubbed)Analyze (javascript-typescript)PASS;Analyze (swift)is non-requiredand pre-existing (this PR touches no Swift code).