Skip to content

feat(retrieval): write-time keywords + recency tie-break + per-char accuracy (#40) - #97

Merged
abogartz merged 3 commits into
mainfrom
feat/ranking-recency-kw
Oct 25, 2026
Merged

abogartz merged 3 commits into
mainfrom
feat/ranking-recency-kw

Conversation

@abogartz

Copy link
Copy Markdown
Owner

What

Implements #40 (epic #84, item 2): remaining ranking scope — recency tie-break, write-time kw= keywords (the vocabulary-wall attack), and accuracy-per-1k-injected-chars reporting.

Stacked: PR 2 of 5 for epic #84 (#43 → #40 → #42 → #44 → #45). Base branch is PR #96, so this diff is only #40's work.

Headline (published bench, store 200, k=3)

Query class share prod R@1 prod R@3 with kw R@1 with kw R@3
lexical 46% 98% 98% 98% 98%
near 17% 28% 28% 67% 72%
strict (zero shared words) 37% 0% 0% 26% 26%
all 50% 50% 66% 67%

Top-1 wrong-memory noise: 6% → 6% (unchanged). Abstentions: 47 → 30. The one changed variable is the index, so this is the bridge and nothing else.

How

1. Write-time keywords (kw) — the vocabulary bridge.

  • Memory.kw / AppendMemoryInput / WriteCandidate, stored as a kw= logfmt field, normalised at the write choke point (normalizeKeywords: trim, lowercase, de-dupe, ≤8 × ≤48 chars, total — junk shortens the list, it never fails a write the prose deserved).
  • Indexed into the scoring haystack (scope + type + content + kw) in scoreMemories and into memory_recall's scorer. Never rendered: formatMemory is untouched, so injection bytes, the content cap and the epoch fingerprint are exactly what the prose says. Pinned by test: a keyword never appears in an injected block and never changes a row's rendered length.
  • memory_remember / memory_update gained a kw argument (wire contract moves — recorded, not silent: test/boundaries.test.ts documents the change and pins the new capture); malformed kw is rejected at the boundary like tags, credential-shaped kw is rejected by gate and store.
  • Auto-capture asks the mining model for 3-5 aliases and cleans them on the way in; a bad list costs the keywords, never the row. Tested end-to-end: capture reply → gate → stored row carrying kw.
  • Keywords ride export → import, and they deliberately do not take part in GATE-3 dedup: restating the same prose with different aliases still collapses.

2. Recency tie-break. The cascade is now score → open threads → newest row. A real score difference is never overridden by recency (pinned); an open thread still outranks a newer settled row, because that is what pinning means; epoch-freeze-safe since a row's ts never changes. Published prod numbers are byte-identical to main, which is exactly what a pure tie-break should do.

3. Accuracy per 1k injected characters. New bench table computed with the real formatMemory renderer over the real k=3 window, abstention counted as a miss that costs zero characters — with a "how to read it" line, because a ratio computed over abstentions flatters the abstainer.

The control (why the +16 points is not authorship)

The kw arm is the only place in this benchmark where a human wrote extra text that helps the gold row win, so it carries a permutation control: every row is given another memory's keyword set (fixed rotation, deterministic).

Arm R@1 R@3
prod (shipped) 50% 50%
prod + authored kw 66% 67%
prod + shuffled kw (same token volume, wrong meanings) 29% 35%

Pinned in test/negative-eval.test.ts: if plausible-but-wrong aliases ever caught up, the bridge would be measuring extra tokens and the test goes red. test/recall-dataset.test.ts also pins the authoring shape (every gold has 3-5 keywords, ≤48 chars, lowercase, variants inherit their base's set so the bridge competes with equals) and states, in the file, the rule it cannot enforce mechanically — keywords are written from each memory's own content, never from the query list.

Evidence

  • bun test ./test/: 417 pass / 5 skip / 0 fail (branch base was 395/5/0), tsc --noEmit clean, biome lint error-free.
  • Bench is deterministic: two runs byte-identical, committed bench/recall-results.md matches.
  • New tests: test/keywords.test.ts (12: store round-trip, normalisation caps, control-char and credential floors, gate rejection, export/import carry, dedup neutrality, the bridge isolated on one row, never-rendered, recall-by-keyword, three recency-cascade cases), plus capture parser/prompt tests, wire-capture updates and the dataset gates.

Also

README updated: its "nothing keyword-side crosses it" claim was a promise the shipped code now keeps differently — rewritten with the numbers and what is still unsolved (26% is a third of the wall; embeddings remain the only general crossing).

Closes #40. Part of #84.

@WhollyMindless

Copy link
Copy Markdown
Contributor

Ran a fresh-eyes review of this branch against a scratch merge of main + #89 (the Windows store-semantics branch, not yet merged) — the first time these two write-path changes have coexisted. No blockers found; verdict: merge-OK. Evidence, for the record:

  • Suite on the combined tree (Windows, both embedded-Bun pins): 417 pass / 0 fail under Bun 1.3.10 (×2) and 1.4.4 — 3 consecutive runs, zero race flakes. tsc --noEmit and biome lint clean.
  • Coexistence with fix(store): make the store's file semantics hold on Windows (+ a windows-latest CI leg) #89 specifically: every write path in this PR routes through appendMemory → withStoreLock (gate promotion passes the candidate including kw; import lands via the same gate); kw serializes as a scalar comma-joined string, not a logfmt array, so fix(store): make the store's file semantics hold on Windows (+ a windows-latest CI leg) #89's rename-handover/atomic-write semantics never see a new shape. Legacy rows without kw parse cleanly (typeof guard). Line growth is bounded (~400 B) and the 1 MB write-gate test is untouched. No new regexes, so the super-linear-scanning incident class stays guarded.
  • Determinism: tie-break assertions use fixed timestamps; keywords never render into injected text (proven in keywords.test.ts and confirmed by probe), so injectBudget accounting and the epoch-hash are unaffected.
  • Bench claims are real: bun run bench/recall-quality.ts reproduces the published recall-results.md byte-identically, negative controls hold.
  • Red-check: 9 of the new tests fail against plain main src (8 against this branch's base), so they're genuine regression tests, not tautologies.

Two LOW notes, neither blocking:

  1. Commas inside a keyword round-trip fragmented. normalizeKeywords/schema allow commas, storage joins on , and splits back without trim — ["build, test"] reads back as ["build", " test"]. Scoring impact is nil (words() tokenizes on non-word chars) and this mirrors existing tags behavior — but unlike tags, no test covers it. A comma-rejection in normalizeKeywords or one round-trip test would close it.
  2. cmpTs string-compare edge: for the same instant, legacy second-precision timestamps (…:01Z) compare "newer" than …:01.000Z. Only reachable with mixed-format equal instants (current writes always emit millis), so effectively theoretical.

One merge-order note: #96's head is a strict ancestor of this branch — worth landing #96 first so #97 stays a clean stack (see comment there).

review added 2 commits October 25, 2026 12:24
…ccuracy (#40)

The strict-paraphrase wall is a vocabulary problem, not a ranking problem: the
user's words are not the memory's words. Ranking alone cannot cross it, so this
moves the effort to write time and keeps the read path deterministic.

- kw (retrieval keywords): a row carries 3-5 aliases (other names, other verb
  forms, the literal command), stored as one logfmt field and normalised at the
  write choke point. Indexed into the same haystack as scope/type/content by
  scoreMemories and memory_recall; NEVER rendered — formatMemory is untouched,
  so injection bytes, the content cap and the epoch fingerprint stay what the
  prose says. memory_remember/memory_update take kw (wire contract move,
  recorded in boundaries.test); malformed/credential-shaped kw is rejected like
  tags; capture asks the mining model for them and cleans them; they ride
  export/import and stay out of GATE-3 dedup (restating prose with new aliases
  still collapses).
- recency tie-break: score -> open threads -> newest row.
- bench: prod+kw arm, accuracy per 1k injected characters (real renderer, real
  k=3 window, abstention = a miss costing zero characters), and a permutation
  control (every row gets another memory's aliases) so the +16 points is proven
  to come from meaning rather than token volume.

Store 200: strict R@1 0% -> 26%, near 28% -> 67%, all 50% -> 66%; top-1 noise
unchanged at 6%; abstentions 47 -> 30. Shipped-arm numbers are byte-identical
to main, which is what a pure tie-break must do.
…#40)

Two LOW notes from the fresh-eyes review of #97, both pinned red-first:

- kw items carrying the storage comma used to round-trip fragmented
  ("build, test" -> ["build", " test"]). normalizeKeywords now splits on
  the delimiter, so aliases never store it; the read path trims, which
  also heals rows already on disk written before the fix.
- the recency tie-break compared ISO stamps as strings, so for one and
  the same instant a legacy second-precision row outranked a
  millisecond row. Date.parse first with a string fallback (the ledger
  hands "" for never-used rows); the three other raw ts comparisons in
  inject.ts go through the same comparator, so "recency is numeric"
  holds in one place.
@abogartz
abogartz force-pushed the feat/negative-eval-suite branch from 3f03fe9 to c022bfc Compare October 25, 2026 19:43
@abogartz
abogartz force-pushed the feat/ranking-recency-kw branch from 5a525b9 to 3a91bfd Compare October 25, 2026 19:44
abogartz pushed a commit that referenced this pull request Oct 25, 2026
Same class as the #97 review note, one layer up: the pool sort, the
cluster-order sort and the survivor tie-break in survivorFor all compared
ISO stamps as strings, so a legacy second-precision row could be called
newer than a millisecond row from the same second plus change. cmpTs is
now exported from inject.ts and is the single comparator for recency.
abogartz pushed a commit that referenced this pull request Oct 25, 2026
Same class as the #97 review note, one layer up: the pool sort, the
cluster-order sort and the survivor tie-break in survivorFor all compared
ISO stamps as strings, so a legacy second-precision row could be called
newer than a millisecond row from the same second plus change. cmpTs is
now exported from inject.ts and is the single comparator for recency.
@abogartz

Copy link
Copy Markdown
Owner Author

Both LOW notes fixed in 3a91bfd fix(retrieval): delimiters and stamps compare honestly in the ranking (#40), each pinned by a test that is red on the pre-fix code and green after:

  1. Comma fragmentation. normalizeKeywords now treats the storage comma as the delimiter it is — ["build, test"] normalizes to two aliases rather than one that reads back fragmented — and the read path trims, which also heals rows already on disk written before the fix. Round-trip and legacy-row tests in test/keywords.test.ts.
  2. cmpTs glyph compare. Date.parse-first with the string compare as fallback (the ledger hands "" for never-used rows). The tie-break test seeds one instant in both formats and demands insertion order; it fails on string compare. The three other raw ts comparisons in inject.ts now share the comparator, and the same bug class one layer up — cluster pool ordering, cluster-order sort, and the survivor tie-break in consolidate.ts (P3: Consolidation promotion pass (dry-run via memory_merge_review) — gated on #42 usage data #45) — routes through the now-exported cmpTs, with its own discriminating test (a …:00Z row no longer outranks a strictly-newer …:00.500Z row).

Thanks for running the combined-tree check against #89 — the kw-scalar observation made the comma-as-delimiter fix safe to do on the write side.

@abogartz
abogartz changed the base branch from feat/negative-eval-suite to main October 25, 2026 20:04
@abogartz
abogartz merged commit 0ede1ae into main Oct 25, 2026
3 checks passed
abogartz-opencode-self-improvement Bot pushed a commit that referenced this pull request Oct 25, 2026
# [0.10.0](v0.9.2...v0.10.0) (2026-10-25)

### Bug Fixes

* **retrieval:** delimiters and stamps compare honestly in the ranking ([#40](#40)) ([3a91bfd](3a91bfd)), closes [#97](#97)

### Features

* **retrieval:** write-time keywords + recency tie-break + per-char accuracy ([#40](#40)) ([fdbabf2](fdbabf2))
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

abogartz-opencode-self-improvement Bot pushed a commit that referenced this pull request Oct 25, 2026
# [0.13.0](v0.12.0...v0.13.0) (2026-10-25)

### Bug Fixes

* **#45:** cluster ordering compares instants, not glyphs ([8610b45](8610b45)), closes [#45](#45) [#97](#97)

### Features

* **#45:** consolidation that has to earn its merge — deterministic, read-proven, proposal-only ([2751d3e](2751d3e)), closes [#45](#45) [#40](#40) [#45](#45)
@abogartz
abogartz deleted the feat/ranking-recency-kw branch October 25, 2026 20:19
abogartz pushed a commit to WhollyMindless/opencode-self-improvement that referenced this pull request Oct 25, 2026
Same class as the abogartz#97 review note, one layer up: the pool sort, the
cluster-order sort and the survivor tie-break in survivorFor all compared
ISO stamps as strings, so a legacy second-precision row could be called
newer than a millisecond row from the same second plus change. cmpTs is
now exported from inject.ts and is the single comparator for recency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P2: Retrieval ranking — IDF/BM25-lite, recency tie-break, write-time keywords

2 participants