[PR #1261] [MERGED] fix(long-term-memory): 1.4.13 — calibrate recall lanes and retune presets (#1258) #1372

Closed
opened 2026-10-21 05:09:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Agents/pull/1261
Author: @Promansis
Created: 10/7/2026
Status: ✅ Merged
Merged: 10/7/2026
Merged by: @Promansis

Base: staging ← Head: fix(ltm)/recall-calibration-1258


📝 Commits (2)

  • f4dc06a fix(long-term-memory): 1.5.0 — calibrate recall lanes and retune presets (#1258)
  • 7e574bb fix(long-term-memory): 1.4.13 — scope keyword frequency and let broad keyword hits pass (#1258)

📊 Changes

23 files changed (+302 additions, -135 deletions)

View changed files

➕ artifacts/long-term-memory-1.4.13.zip (+0 -0)
📝 catalog/catalog.json (+8 -8)
📝 catalog/notes.json (+6 -6)
📝 catalog/v2/catalog.json (+8 -8)
📝 catalog/v2/notes.json (+6 -6)
📝 catalog/v3/catalog.json (+8 -8)
📝 catalog/v3/notes.json (+6 -6)
📝 packages/long-term-memory/CHANGELOG.md (+6 -0)
📝 packages/long-term-memory/client.js (+2 -2)
📝 packages/long-term-memory/manifest.json (+5 -5)
📝 packages/long-term-memory/server.mjs (+44 -44)
📝 packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/locales/en.json (+1 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/bm25.ts (+18 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/keyword-index.ts (+30 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/ranking.ts (+8 -1)
📝 packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts (+6 -1)
📝 packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/constants.ts (+27 -24)
📝 packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/runtime-settings.ts (+6 -5)
📝 packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema.ts (+2 -2)
📝 scripts/build-feature-packages.mjs (+1 -1)

...and 3 more files

📄 Description

Linked issue

Closes #1258

Why this change

  • Recall lanes were not on a comparable scale. BM25 normalized almost every hit to ~0.95 (x/(x+1) of an unbounded idf sum), keyword relevance summed matches until two generic names reached 1.0, and the presets kept every lane weight well below 1. The score threshold therefore behaved as a cliff: on the labelled fixture, balanced went from 16.8 memories at 0.25 to 2.8 at 0.30, and exact ignored any threshold up to 0.5.
  • The per-mode recall style map (roleplay → story, game → exact) never applied, because resolved global settings always carry a style.

What changed

 bm25 lane      normalized = score / (score + 1)
-                saturates near 1 for every hit
+ normalized = min(1, score / Σidf(query terms))   // query coverage
 keyword lane   score = Σ exact + fuzzy matches, clamp 4
+ score = max match × idf-like weight, counted within the recall scope
 presets        balanced .6/.3/.1/.2  story .55/.35/.5/.3  …
+ strongest lane = 1 per style (same fused order, full 0–1 threshold range)
+ balanced 1/.85/.15/.65  exact .15/1/0/.8  broad 1/.4/.3/.5  story 1/.75/.6/.65
 defaults       maxChunks 20, threshold 0
+ maxChunks 12, threshold 0.35
-DEFAULT_LTM_RECALL_STYLE_BY_MODE, dead `custom` preset weights
  • bm25.ts, ranking.ts, retrieval.ts: BM25 hits carry an explicit normalizedScore; fusion prefers it over rawScore/(rawScore+1); raw scores stay in rawLaneScores. A ponytail: note records that the coverage reference is not an upper bound (a short chunk with repeated terms can clamp at 1 beside a full match) and why the true ceiling Σidf·(K1+1) was rejected: it compresses real hits below ~0.3, so no lexical-only memory could pass a threshold.
  • keyword-index.ts: best match per chunk instead of a sum, scaled by log(1 + N/df) / log(1 + N). Like the #1251 caps, N and df count only the chunks the search may return, so a keyword common in other chats keeps its weight where it is distinctive; counts are computed once per query and keyword.
  • constants.ts, schema.ts, runtime-settings.ts: retuned presets and defaults; balanced is the single fallback style. Graph weights stay at or below 0.6 (graph-only neighbours top out at 0.3, under the default threshold) and keyword weights at or above 0.5 (an exact keyword term, 0.75 × weight, clears it without the semantic lane).
  • locales/en.json: threshold help describes the shared 0–1 scale and the graph lane's half-weight ceiling.
  • Tests: index-keys gains the lane-calibration case, a scoped keyword-frequency case, and a guard that every preset's strongest weight is 1, its graph-only floor stays under the default threshold, and an exact keyword term clears it; the runtime threshold-equality case now pins custom weights below 1, and the strongest-lane threshold case moves from 0.75 to 0.4 because keyword no longer saturates.
  • Rebuilt long-term-memory 1.4.13: manifest, client.js, server.mjs, artifacts/long-term-memory-1.4.13.zip and catalog lane entries; CHANGELOG 1.4.13 entry on top of staging's unchanged 1.4.12.

Evidence

Labelled 45-note fixture with real all-MiniLM-L6-v2 embeddings, measured against this branch's own retrieval code (168/168 identical selections with retrieveLongTermMemory), 12 relevant queries.

Lane separation (normalized score before weighting, median relevant / non-relevant):

Lane 1.4.11 this PR
BM25 0.904 / 0.799 0.144 / 0.067
Keyword 1.000 / 0.982 0.538 / 0.385

Threshold behaviour, maxChunks 12, both on this PR's lanes:

1.4.11 presets this PR presets
balanced injected per query at 0.35 (queries left empty) 1.0 (7 of 12) 11.3 (0)
balanced, semantic lane unavailable 0 (12 of 12) 4.3 (0)
balanced injected per query, threshold 0.35 → 0.55 1.0 → 0.1 → 0 → 0 → 0 11.3 → 9.0 → 6.3 → 2.8 → 1.6
broad, semantic lane unavailable, at 0.35 0 (12 of 12) 2.8 (0)

Regression proof: index-keys fails on the pre-fix lane sources (a long query must not normalize every BM25 hit above 0.9), on the 1.4.11 presets (balanced: the strongest lane must carry weight 1), on vault-wide keyword frequency (a keyword common only outside the recall scope must keep full weight inside it) and on broad keyword 0.3 (broad: an exact keyword term must clear the default threshold), and passes on this branch.

Merge danger

Door: two-way. Weights and defaults are constants; reverting restores the old scale. No storage, index or migration change.

Blast radius: recall.

  • A score threshold a user saved under the old scale (for example 0.25) now filters differently; the CHANGELOG says so.
  • With the semantic lane unavailable, broad now recalls exact keyword matches only; BM25-only matches stay under 0.35 (lexical 0.4 × BM25 tops out near 0.28). The semantic lane is raw cosine, so a configured embedder other than MiniLM shifts where the threshold bites.
  • The fixture is synthetic and small; its best-F1 thresholds are single-point optima, so these presets avoid the measured failures rather than being finely tuned. Issue step 4 (a real vault export) is still unmet.

Package and security impact

  • Affected package IDs: long-term-memory
  • Engine compatibility impact: none (min 2.4.1 / maxExclusive 4.0.0 unchanged; no capability API change)
  • New or changed permissions/entrypoints: none
  • Restart, storage, update, or uninstall impact: none; recall scoring and settings defaults only. Preset styles pick up the new weights everywhere; a maxChunks or threshold value already saved in the vault settings file is kept, and only unsaved fields take the new 12 / 0.35 defaults.

Validation

  • node scripts/validate-catalog.mjs passes locally
  • git diff --check passes locally
  • Rebuilt every affected manifest, payload, artifact, and catalog entry
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup
  • Read and followed CONTRIBUTING.md

Manual verification notes

On 7e574bb6fae704735274997d43ce90719de33e04 (pushed SHA), with MARINARA_AGENTS_ROOT set to the worktree and MARINARA_ENGINE_ROOT to an independent Engine checkout at c5a545857:

  • test-ltm.sh for index-keys, runtime, storage, extraction-graph, extraction-reliability, routes, source-task, browser, debug-activity: pass. candidate-reconciliation and reconciliation-recall run directly with tsx: pass.
  • test-ltm.sh installation: pass ("Long-Term Memory 1.4.13 installation: install, offline restart, backup inclusion, uninstall, reinstall, and durable-byte preservation ok") against the committed ZIP.
  • test-fast.sh, npm run typecheck:packages, npm run test:security, node scripts/test-catalog-lanes.mjs, node scripts/validate-package-locales.mjs, node scripts/validate-catalog.mjs, node scripts/tests/catalog-release-notes.regression.mjs, git diff --check: pass.
  • Regression proof, run on this branch's content by swapping in the old file and restoring it: each of the four index-keys assertions listed under Evidence fails on the old code and passes on this branch.
  • The 1.4.12 CHANGELOG entry and artifacts/long-term-memory-1.4.12.zip are byte-identical to staging.
  • Publish proof: repository and Engine inputs captured before the checks and verified unchanged on the final HEAD immediately before push.
  • Not performed: manual install/update through the Engine UI, manual mode/restart/uninstall click-through beyond the installation regression, and a real-vault calibration run.

Documentation impact

  • No documentation changes needed: package docs describe recall generically and name no preset values; the threshold help text in en.json is updated with the code.
  • Updated this README catalog and package guidance
  • Updated linked Marinara Engine documentation

UI evidence (if applicable)

None. The settings form reads the preset table, so it shows the new weights; no layout change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Long-Term Memory 1.4.13 calibrates recall scores to a shared 0–1 scale, making results more comparable across recall lanes.
    • Recall presets have been retuned to reduce the influence of common keyword matches.
  • Changes
    • Defaults are now 12 memories and a 0.35 score threshold. Thresholds saved under the previous scoring scale may behave differently.
    • Recall style now uses a shared default instead of mode-specific defaults.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Agents/pull/1261 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 10/7/2026 **Status:** ✅ Merged **Merged:** 10/7/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix(ltm)/recall-calibration-1258` --- ### 📝 Commits (2) - [`f4dc06a`](https://github.com/Pasta-Devs/Marinara-Agents/commit/f4dc06a14a3485a17a1770fea66e751b2151cabc) fix(long-term-memory): 1.5.0 — calibrate recall lanes and retune presets (#1258) - [`7e574bb`](https://github.com/Pasta-Devs/Marinara-Agents/commit/7e574bb6fae704735274997d43ce90719de33e04) fix(long-term-memory): 1.4.13 — scope keyword frequency and let broad keyword hits pass (#1258) ### 📊 Changes **23 files changed** (+302 additions, -135 deletions) <details> <summary>View changed files</summary> ➕ `artifacts/long-term-memory-1.4.13.zip` (+0 -0) 📝 `catalog/catalog.json` (+8 -8) 📝 `catalog/notes.json` (+6 -6) 📝 `catalog/v2/catalog.json` (+8 -8) 📝 `catalog/v2/notes.json` (+6 -6) 📝 `catalog/v3/catalog.json` (+8 -8) 📝 `catalog/v3/notes.json` (+6 -6) 📝 `packages/long-term-memory/CHANGELOG.md` (+6 -0) 📝 `packages/long-term-memory/client.js` (+2 -2) 📝 `packages/long-term-memory/manifest.json` (+5 -5) 📝 `packages/long-term-memory/server.mjs` (+44 -44) 📝 `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/locales/en.json` (+1 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/bm25.ts` (+18 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/keyword-index.ts` (+30 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/ranking.ts` (+8 -1) 📝 `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/retrieval.ts` (+6 -1) 📝 `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/constants.ts` (+27 -24) 📝 `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/runtime-settings.ts` (+6 -5) 📝 `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/schema.ts` (+2 -2) 📝 `scripts/build-feature-packages.mjs` (+1 -1) _...and 3 more files_ </details> ### 📄 Description ## Linked issue Closes #1258 ## Why this change - Recall lanes were not on a comparable scale. BM25 normalized almost every hit to ~0.95 (`x/(x+1)` of an unbounded idf sum), keyword relevance summed matches until two generic names reached 1.0, and the presets kept every lane weight well below 1. The score threshold therefore behaved as a cliff: on the labelled fixture, `balanced` went from 16.8 memories at 0.25 to 2.8 at 0.30, and `exact` ignored any threshold up to 0.5. - The per-mode recall style map (`roleplay → story`, `game → exact`) never applied, because resolved global settings always carry a style. ## What changed ```diff bm25 lane normalized = score / (score + 1) - saturates near 1 for every hit + normalized = min(1, score / Σidf(query terms)) // query coverage keyword lane score = Σ exact + fuzzy matches, clamp 4 + score = max match × idf-like weight, counted within the recall scope presets balanced .6/.3/.1/.2 story .55/.35/.5/.3 … + strongest lane = 1 per style (same fused order, full 0–1 threshold range) + balanced 1/.85/.15/.65 exact .15/1/0/.8 broad 1/.4/.3/.5 story 1/.75/.6/.65 defaults maxChunks 20, threshold 0 + maxChunks 12, threshold 0.35 -DEFAULT_LTM_RECALL_STYLE_BY_MODE, dead `custom` preset weights ``` - `bm25.ts`, `ranking.ts`, `retrieval.ts`: BM25 hits carry an explicit `normalizedScore`; fusion prefers it over `rawScore/(rawScore+1)`; raw scores stay in `rawLaneScores`. A `ponytail:` note records that the coverage reference is not an upper bound (a short chunk with repeated terms can clamp at 1 beside a full match) and why the true ceiling `Σidf·(K1+1)` was rejected: it compresses real hits below ~0.3, so no lexical-only memory could pass a threshold. - `keyword-index.ts`: best match per chunk instead of a sum, scaled by `log(1 + N/df) / log(1 + N)`. Like the #1251 caps, `N` and `df` count only the chunks the search may return, so a keyword common in other chats keeps its weight where it is distinctive; counts are computed once per query and keyword. - `constants.ts`, `schema.ts`, `runtime-settings.ts`: retuned presets and defaults; balanced is the single fallback style. Graph weights stay at or below 0.6 (graph-only neighbours top out at 0.3, under the default threshold) and keyword weights at or above 0.5 (an exact keyword term, 0.75 × weight, clears it without the semantic lane). - `locales/en.json`: threshold help describes the shared 0–1 scale and the graph lane's half-weight ceiling. - Tests: `index-keys` gains the lane-calibration case, a scoped keyword-frequency case, and a guard that every preset's strongest weight is 1, its graph-only floor stays under the default threshold, and an exact keyword term clears it; the `runtime` threshold-equality case now pins custom weights below 1, and the strongest-lane threshold case moves from 0.75 to 0.4 because keyword no longer saturates. - Rebuilt `long-term-memory` 1.4.13: manifest, `client.js`, `server.mjs`, `artifacts/long-term-memory-1.4.13.zip` and catalog lane entries; CHANGELOG 1.4.13 entry on top of staging's unchanged 1.4.12. ## Evidence Labelled 45-note fixture with real all-MiniLM-L6-v2 embeddings, measured against this branch's own retrieval code (168/168 identical selections with `retrieveLongTermMemory`), 12 relevant queries. Lane separation (normalized score before weighting, median relevant / non-relevant): | Lane | 1.4.11 | this PR | |---|---|---| | BM25 | 0.904 / 0.799 | 0.144 / 0.067 | | Keyword | 1.000 / 0.982 | 0.538 / 0.385 | Threshold behaviour, maxChunks 12, both on this PR's lanes: | | 1.4.11 presets | this PR presets | |---|---|---| | `balanced` injected per query at 0.35 (queries left empty) | 1.0 (7 of 12) | 11.3 (0) | | `balanced`, semantic lane unavailable | 0 (12 of 12) | 4.3 (0) | | `balanced` injected per query, threshold 0.35 → 0.55 | 1.0 → 0.1 → 0 → 0 → 0 | 11.3 → 9.0 → 6.3 → 2.8 → 1.6 | | `broad`, semantic lane unavailable, at 0.35 | 0 (12 of 12) | 2.8 (0) | Regression proof: `index-keys` fails on the pre-fix lane sources (`a long query must not normalize every BM25 hit above 0.9`), on the 1.4.11 presets (`balanced: the strongest lane must carry weight 1`), on vault-wide keyword frequency (`a keyword common only outside the recall scope must keep full weight inside it`) and on `broad` keyword 0.3 (`broad: an exact keyword term must clear the default threshold`), and passes on this branch. ## Merge danger **Door:** two-way. Weights and defaults are constants; reverting restores the old scale. No storage, index or migration change. **Blast radius:** recall. - A score threshold a user saved under the old scale (for example 0.25) now filters differently; the CHANGELOG says so. - With the semantic lane unavailable, `broad` now recalls exact keyword matches only; BM25-only matches stay under 0.35 (lexical 0.4 × BM25 tops out near 0.28). The semantic lane is raw cosine, so a configured embedder other than MiniLM shifts where the threshold bites. - The fixture is synthetic and small; its best-F1 thresholds are single-point optima, so these presets avoid the measured failures rather than being finely tuned. Issue step 4 (a real vault export) is still unmet. ## Package and security impact - Affected package IDs: `long-term-memory` - Engine compatibility impact: none (min 2.4.1 / maxExclusive 4.0.0 unchanged; no capability API change) - New or changed permissions/entrypoints: none - Restart, storage, update, or uninstall impact: none; recall scoring and settings defaults only. Preset styles pick up the new weights everywhere; a maxChunks or threshold value already saved in the vault settings file is kept, and only unsaved fields take the new 12 / 0.35 defaults. ## Validation - [ ] `node scripts/validate-catalog.mjs` passes locally - [ ] `git diff --check` passes locally - [ ] Rebuilt every affected manifest, payload, artifact, and catalog entry - [ ] Installed or updated the affected package through Marinara Engine - [ ] Checked supported modes, restart behavior, and uninstall cleanup - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes On `7e574bb6fae704735274997d43ce90719de33e04` (pushed SHA), with `MARINARA_AGENTS_ROOT` set to the worktree and `MARINARA_ENGINE_ROOT` to an independent Engine checkout at `c5a545857`: - `test-ltm.sh` for `index-keys`, `runtime`, `storage`, `extraction-graph`, `extraction-reliability`, `routes`, `source-task`, `browser`, `debug-activity`: pass. `candidate-reconciliation` and `reconciliation-recall` run directly with `tsx`: pass. - `test-ltm.sh installation`: pass ("Long-Term Memory 1.4.13 installation: install, offline restart, backup inclusion, uninstall, reinstall, and durable-byte preservation ok") against the committed ZIP. - `test-fast.sh`, `npm run typecheck:packages`, `npm run test:security`, `node scripts/test-catalog-lanes.mjs`, `node scripts/validate-package-locales.mjs`, `node scripts/validate-catalog.mjs`, `node scripts/tests/catalog-release-notes.regression.mjs`, `git diff --check`: pass. - Regression proof, run on this branch's content by swapping in the old file and restoring it: each of the four `index-keys` assertions listed under Evidence fails on the old code and passes on this branch. - The 1.4.12 CHANGELOG entry and `artifacts/long-term-memory-1.4.12.zip` are byte-identical to `staging`. - Publish proof: repository and Engine inputs captured before the checks and verified unchanged on the final HEAD immediately before push. - Not performed: manual install/update through the Engine UI, manual mode/restart/uninstall click-through beyond the installation regression, and a real-vault calibration run. ## Documentation impact - [x] No documentation changes needed: package docs describe recall generically and name no preset values; the threshold help text in `en.json` is updated with the code. - [ ] Updated this README catalog and package guidance - [ ] Updated linked Marinara Engine documentation ## UI evidence (if applicable) None. The settings form reads the preset table, so it shows the new weights; no layout change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Long-Term Memory 1.4.13 calibrates recall scores to a shared 0–1 scale, making results more comparable across recall lanes. * Recall presets have been retuned to reduce the influence of common keyword matches. * **Changes** * Defaults are now 12 memories and a 0.35 score threshold. Thresholds saved under the previous scoring scale may behave differently. * Recall style now uses a shared default instead of mode-specific defaults. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-21 05:09:58 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#1372
No description provided.