perf(recall): cut recall-bundle tokens ~20%+ with recall held constant#38
Draft
TJCurnutte wants to merge 2 commits into
Draft
perf(recall): cut recall-bundle tokens ~20%+ with recall held constant#38TJCurnutte wants to merge 2 commits into
TJCurnutte wants to merge 2 commits into
Conversation
Reflow Markdown formatting overhead and suppress near-duplicate cross-silo copies when rendering recall bundles (default on). FTS selection is unchanged so recall is preserved; benchmark shows >=20% token cut with 0 facts lost. Co-authored-by: tcurnutte <TJCurnutte@users.noreply.github.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_4c708116-9b36-4864-ac25-92cf46914186) |
Bugbot review: an unpadded table row (`|a|b|`) was re-padded to `| a | b |`, inflating length. Render the shorter of padded/collapsed forms and add a regression test asserting compaction never increases snippet length. Co-authored-by: tcurnutte <TJCurnutte@users.noreply.github.com>
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.
Goal
Cut the tokens Memory Hive serves per recall by ≥20% while keeping inference/recall the same or better.
Approach
Two changes to bundle rendering only — the FTS index and query selection are untouched, so which chunks are retrieved is identical and recall is preserved by construction:
compact_snippet): reflow wrapped prose, join bullet continuations, collapse whitespace, trim table cell padding, and drop pure table separator rows. Fenced code is preserved verbatim. Every query-relevant word is kept (unit-tested:words(input) == words(output)), and compaction is non-increasing (never inflates a snippet).dedupe): drop a candidate whose token-set Jaccard ≥ 0.85 against an already-kept snippet. Memory Hive's write-back ritual echoes the same fact across logs/memory/learnings and across silos; those redundant copies cost tokens without adding recall.Both default on in
bundle()(newcompact/dedupeparams, off = previous behavior for A/B).bundle_json, the CLIbundle, and MCPask_hiveall benefit automatically.Results (benchmark:
scripts/bench/recall_token_efficiency.py)Honest A/B at a budget large enough that neither bundle truncates, so the retrieved set is identical and the delta is pure rendering efficiency:
add+learn)The ≥20% target is met on realistic and real product-generated hives. Even with zero redundancy, compaction alone cuts ~12% and frees budget to fit more distinct facts (recall "or better"). No benchmark query lost a fact.
recall_token_efficiency_benchmark.txt
Review fixes (Bugbot)
|a|b|→| a | b |). Now renders the shorter of padded/collapsed forms; addedtest_compaction_never_increases_length. No recall impact (words always preserved); this only tightens the token guarantee.Testing
PYTHONPATH=$(pwd) python3 -m unittest discover -s tests— 45 passed (7 new; existing bundle redaction/budget/JSON tests still green)scripts/bench/recall_token_efficiency.py— PASS (≥20% cut, 0 facts lost, recall ≥ baseline)|/---, separator-only tables, distinct short facts (not deduped)Notes / tradeoffs
dedupehides independent corroborating copies of a fact by design; the unique fact is always retained. Threshold 0.85 only collapses true near-duplicates (distinct facts rarely share 85%+ of vocabulary).chars/4heuristic.To show artifacts inline, enable in settings.