[GH-ISSUE #1360] [Issue]: LTM recall: recall a near-miss memory through an explanatory link from a recalled memory #695

Closed
opened 2026-10-20 17:29:49 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Oct 13, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1360

Originally assigned to: @Promansis on GitHub.

Summary

The graph lane still cannot change which memories are recalled. A graph match scores at most half its lane weight, which is below the default 0.35 threshold in every preset. Turning the lane off changes no selection on the evaluation. #1272's proposal to let a linked memory borrow its seed's relevance was measured and rejected. Two further rounds tested narrower rules, the second on a blind holdout set. One rule raised F1 in every measured cell without raising off-topic injections. That rule follows only explanatory link types from memories that were actually recalled, and requires the linked memory's own relevance to be at least 0.2. This issue replaces the current graph lane with that rule.

Affected package

long-term-memory 1.4.29 (upstream/staging 9c2108fab):

  • graph.ts, retrieval.ts, budget.ts and ranking.ts under packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/
  • constants.ts under packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/
  • locales/en.json under packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/ (two help strings)
  • tests/long-term-memory-runtime.regression.ts and tests/long-term-memory-index-keys.regression.ts

Expected behavior

  • Suppose memory A is recalled and has an explanatory link to memory B. If B nearly matches the chat on its own, B is recalled as well. "Nearly matches" means B's own relevance is at least 0.2 but below the threshold.
  • Only these links are followed. A link is identified by its stored relation, the type of the note that stores it, and the type of its target. Each is followed from either end:
    • evidenced_by, whichever note stores it;
    • caused_by or triggered_by stored on a thread and pointing to a timeline_event;
    • caused_by stored on a relationship and pointing to a timeline_event.
  • Other links are not followed: world planted_in → event, character caused_by → event, extracted_from, and the rest.
  • Some links add nothing:
    • a link from a memory that was not recalled;
    • a link to a memory whose own relevance is below 0.2.
  • Memories recalled without links keep their places. The memory cap and the token budget still bound the total.
  • A memory reached only through a link, with no match of its own, is not recalled, even at a threshold of 0.
  • A graph weight of 0 turns linked recall off, and any positive graph weight turns it on. Preset graph weights are unchanged, so exact (graph weight 0) keeps linked recall off.
  • The recall explanation records the recalled memory and the relation each linked memory came through.

Actual behavior

At upstream/staging 9c2108fab:

  1. A graph match cannot clear the threshold. A graph hit scores 1 / (distance + 1) (graph.ts:92), and relevance is the lane score × the lane weight (ranking.ts:61).
    • That caps graph relevance at 0.053 in balanced, 0.105 in broad, 0.21 in story and 0 in exact.
    • constants.ts:280-293 documents this, and tests/long-term-memory-index-keys.regression.ts:354-370 pins it.
  2. Seeds ignore what was recalled. The graph starts from the top 5 BM25 notes and the top 5 keyword notes (retrieval.ts:188-190). This happens even when those hits failed the threshold or their lane weight is 0. Vector and direct hits never seed it.
  3. The walk ignores link type. It follows every link up to two hops (graph.ts:59), scored only by distance.
  4. The source of a graph hit is lost. viaNoteId is the note reached, not the seed it was reached from (graph.ts:95).
  5. The lane has no effect. On the evaluation below, turning the graph lane off changes 0 of 76 selections.

Steps to reproduce

  1. Create a thread memory A with a distinctive keyword phrase. Create a timeline_event memory B that A links to with caused_by, and that shares one ordinary word with the chat. B's own relevance must fall between 0.2 and 0.35.
  2. Use the default balanced style and threshold 0.35, with debug logging on. Send a turn that contains A's phrase and B's word.
  3. A is injected and B is not. B's graph relevance is at most 0.5 × 0.105 ≈ 0.053, and its own relevance is below the threshold.

Environment

  • Marinara Engine version: 2.5.0 line
  • Package version: long-term-memory 1.4.29 (upstream/staging 9c2108fab)
  • Install type: source (code reading plus a local evaluation running the package's real retrieval code)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

Evaluation setup:

  • Three memory sets from one real vault.
  • 34 hand-written 4-message windows, of which 6 are off-topic.
  • Each window was run short and with long, roleplay-length messages.
  • The balanced style at threshold 0.35, a cap of 12 memories, a 4096-token budget and MiniLM embeddings.
  • Additions entered through the real budget and serializer, with recalled memories kept first.
  • Labels and windows are hand-written, so treat the numbers as directional. No vault content is included here.

How the link types were chosen: in round 1, links from a recalled memory to a memory that was not recalled were tallied by type:

  • world planted_in → event: 0 relevant / 16 wrong;
  • event → character caused_by: 1 / 22;
  • evidenced_by: 4 / 0;
  • thread caused_by → event: 2 / 0;
  • relationship caused_by ↔ event: 4 / 6.

What predicts a useful link:

  • The linked memory's own relevance was the strongest filter:
    • below 0.20: 2 relevant / 43 wrong;
    • 0.20–0.25: 5 / 7;
    • 0.25 and above: 8 / 5.
  • No link from a wrongly recalled memory reached a relevant one: 0 relevant / 57 wrong, pooled over the three sets.

Results, typed links with floor 0.2 vs recall without links (measured on 1.4.18; the implementation reproduces the same numbers on 1.4.29):

Set Short F1 Short precision Long F1 Long precision
Set 1 .766 → .796 .900 → .833 .454 → .488 .483 → .500
Set 2 .600 → .628 .708 → .714 .667 → .713 .750 → .750
Holdout .443 → .458 .692 → .667 .321 → .351 .684 → .714
Pooled .573 → .597 .757 → .729 .465 → .506 .625 → .646
  • Added memories: short +9 relevant / +6 wrong; long +6 / +1.
  • Off-topic injections: unchanged in every cell.

The holdout test:

  • The link types and the floor were fixed from the first two sets.
  • The holdout set's labels were then frozen, written from note titles and text without looking at the links, before any run.
  • The test was pre-registered as strict: no precision loss on short or long windows. It failed on short windows (.692 → .667).
  • Two of the three wrong short-window additions were borderline, but the labels were not changed.

Gate for this issue: F1 up in every cell, no rise in off-topic injections, and long-window precision held or improved in every set. Long windows are the realistic case for roleplay-length messages. The cost is a small short-window precision loss in two of three sets (pooled .757 → .729).

Rejected alternatives:

  • Untyped links: lower long-window gains.
  • Floor 0.25: fewer long-window gains.
  • Relevance borrowing (#1272): adds more irrelevant memories than relevant ones at every decay that changes anything.
  • Entity specificity: raises off-topic injections on two sets.
  • Attaching linked titles without adding memories: under half relevant.

Additional context

Minimal fix:

  1. graph.ts. Replace expandLtmGraph with a one-hop typed lookup.
    • It takes the recall graph, the recalled seed note ids and a note-type lookup.
    • It returns { noteId, seedNoteId, relation } for each linked note that is not itself a seed. It follows only the allowlist in Expected behavior.
    • buildLtmGraphIndex is unchanged.
  2. retrieval.ts.
    • Remove the graph lane and pickGraphSeedNotes.
    • Fuse and budget the remaining lanes as today.
    • When the graph weight is above 0 and the threshold is above the floor (at or below it, the first pass already admitted every candidate linked recall could add):
      • Seed from the notes of the budgeted chunks.
      • Take the linked notes' chunks that are in the fused ranking with their own relevance at least LTM_LINKED_RECALL_MIN_RELEVANCE. Skip chunks already selected.
      • Mark each one as linked from its seed: lane graph, reason graph:<relation>:<seedNoteId>.
      • Run the budget once more over the selected chunks in fused order, then the linked chunks by fused score, then the rest of the ranking.
  3. budget.ts / ranking.ts.
    • A candidate marked as linked skips the threshold check.
    • It keeps its own relevance score, so Debug does not show an inflated value.
    • The selected chunk is identified by its graph lane and reason; it needs no separate mark.
  4. constants.ts.
    • Add LTM_LINKED_RECALL_MIN_RELEVANCE = 0.2, with a ponytail: note: it was measured only at balanced and threshold 0.35. The upgrade path is to scale it with the threshold or the graph weight after measuring.
    • Update the preset comment that describes the graph ceiling.
    • The preset weights are unchanged.
  5. Locale text.
    • Graph weight help: describe it as on/off for linked recall.
    • Threshold help: drop "the graph lane caps at half its weight" and say that a memory linked from a recalled memory can be included below the threshold.
  6. Tests.
    • Replace the preset assertion at index-keys.regression.ts:354-370 with one that pins the floor below the default threshold and above 0.
    • Replace the runtime case "graph recall must expand from keyword-seeded notes" (runtime.regression.ts:835-851; it links world → world caused_by to a neighbour with no signal of its own) with these cases:
      • a typed neighbour of a recalled memory, with its own relevance between the floor and the threshold, is recalled, and the reason names its seed;
      • the same neighbour behind an untyped link is not recalled;
      • a neighbour below the floor is not recalled;
      • a neighbour of a memory that was not recalled is not recalled;
      • a graph weight of 0 disables linked recall;
      • the memory cap still bounds the total, with recalled memories kept first.
  7. Release. A patch version with a changelog entry. Rebuild the package and catalog.

Other callers:

  • Generation injection and /search pass the graph weight and the threshold.
  • Candidate reconciliation and source-extraction context pass neither, so the graph is on by default and the threshold is 0.
    • With no threshold, linked recall cannot add anything that non-graph recall did not already admit, so it is skipped. For these callers the change only removes graph-only neighbours from their candidates.
    • Reconciliation queries one note type at a time. Most stored links join different types, but same-type links exist (for example world → world caused_by), so its candidates can lose a graph-only neighbour.
    • Their existing tests must pass unchanged.

Not in scope:

  • A graded meaning for the graph weight.
  • Two-hop links.
  • New link extraction: event → event (caused_by, paid_off_in) and event → participant (involves), with hub damping for the main characters. This is the larger opportunity, and needs its own issue and re-extraction.
  • A client Debug change to show the seed memory's title. The recall explanation already lists the graph lane and the reason.
  • Low recall on the holdout set (essential recall .21–.33), which no graph rule can fix.

Release note: Recall can now include a memory that nearly matches the chat when a recalled memory links to it with an explanatory link. This applies in the balanced, broad and story styles. A memory reached only through a link, with no match of its own, is no longer recalled, even at a threshold of 0. A saved custom graph weight now turns linked recall on or off and no longer scales a score.

Related: #1272, #1264, #1258.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 13, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1360 Originally assigned to: @Promansis on GitHub. ## Summary The graph lane still cannot change which memories are recalled. A graph match scores at most half its lane weight, which is below the default 0.35 threshold in every preset. Turning the lane off changes no selection on the evaluation. #1272's proposal to let a linked memory borrow its seed's relevance was measured and rejected. Two further rounds tested narrower rules, the second on a blind holdout set. One rule raised F1 in every measured cell without raising off-topic injections. That rule follows only explanatory link types from memories that were actually recalled, and requires the linked memory's own relevance to be at least 0.2. This issue replaces the current graph lane with that rule. ## Affected package `long-term-memory` 1.4.29 (`upstream/staging` 9c2108fab): - `graph.ts`, `retrieval.ts`, `budget.ts` and `ranking.ts` under `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/` - `constants.ts` under `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory/` - `locales/en.json` under `packages/long-term-memory/src/engine/packages/client/src/features/long-term-memory/` (two help strings) - `tests/long-term-memory-runtime.regression.ts` and `tests/long-term-memory-index-keys.regression.ts` ## Expected behavior - Suppose memory A is recalled and has an explanatory link to memory B. If B nearly matches the chat on its own, B is recalled as well. "Nearly matches" means B's own relevance is at least 0.2 but below the threshold. - Only these links are followed. A link is identified by its stored relation, the type of the note that stores it, and the type of its target. Each is followed from either end: - `evidenced_by`, whichever note stores it; - `caused_by` or `triggered_by` stored on a `thread` and pointing to a `timeline_event`; - `caused_by` stored on a `relationship` and pointing to a `timeline_event`. - Other links are not followed: world `planted_in` → event, character `caused_by` → event, `extracted_from`, and the rest. - Some links add nothing: - a link from a memory that was not recalled; - a link to a memory whose own relevance is below 0.2. - Memories recalled without links keep their places. The memory cap and the token budget still bound the total. - A memory reached only through a link, with no match of its own, is not recalled, even at a threshold of 0. - A graph weight of 0 turns linked recall off, and any positive graph weight turns it on. Preset graph weights are unchanged, so `exact` (graph weight 0) keeps linked recall off. - The recall explanation records the recalled memory and the relation each linked memory came through. ## Actual behavior At `upstream/staging` 9c2108fab: 1. **A graph match cannot clear the threshold.** A graph hit scores `1 / (distance + 1)` (`graph.ts:92`), and relevance is the lane score × the lane weight (`ranking.ts:61`). - That caps graph relevance at 0.053 in balanced, 0.105 in broad, 0.21 in story and 0 in exact. - `constants.ts:280-293` documents this, and `tests/long-term-memory-index-keys.regression.ts:354-370` pins it. 2. **Seeds ignore what was recalled.** The graph starts from the top 5 BM25 notes and the top 5 keyword notes (`retrieval.ts:188-190`). This happens even when those hits failed the threshold or their lane weight is 0. Vector and direct hits never seed it. 3. **The walk ignores link type.** It follows every link up to two hops (`graph.ts:59`), scored only by distance. 4. **The source of a graph hit is lost.** `viaNoteId` is the note reached, not the seed it was reached from (`graph.ts:95`). 5. **The lane has no effect.** On the evaluation below, turning the graph lane off changes 0 of 76 selections. ## Steps to reproduce 1. Create a `thread` memory A with a distinctive keyword phrase. Create a `timeline_event` memory B that A links to with `caused_by`, and that shares one ordinary word with the chat. B's own relevance must fall between 0.2 and 0.35. 2. Use the default `balanced` style and threshold 0.35, with debug logging on. Send a turn that contains A's phrase and B's word. 3. A is injected and B is not. B's graph relevance is at most 0.5 × 0.105 ≈ 0.053, and its own relevance is below the threshold. ## Environment - Marinara Engine version: 2.5.0 line - Package version: long-term-memory 1.4.29 (`upstream/staging` 9c2108fab) - Install type: source (code reading plus a local evaluation running the package's real retrieval code) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video **Evaluation setup:** - Three memory sets from one real vault. - 34 hand-written 4-message windows, of which 6 are off-topic. - Each window was run short and with long, roleplay-length messages. - The balanced style at threshold 0.35, a cap of 12 memories, a 4096-token budget and MiniLM embeddings. - Additions entered through the real budget and serializer, with recalled memories kept first. - Labels and windows are hand-written, so treat the numbers as directional. No vault content is included here. **How the link types were chosen:** in round 1, links from a recalled memory to a memory that was not recalled were tallied by type: - world `planted_in` → event: 0 relevant / 16 wrong; - event → character `caused_by`: 1 / 22; - `evidenced_by`: 4 / 0; - thread `caused_by` → event: 2 / 0; - relationship `caused_by` ↔ event: 4 / 6. **What predicts a useful link:** - The linked memory's own relevance was the strongest filter: - below 0.20: 2 relevant / 43 wrong; - 0.20–0.25: 5 / 7; - 0.25 and above: 8 / 5. - No link from a wrongly recalled memory reached a relevant one: 0 relevant / 57 wrong, pooled over the three sets. **Results, typed links with floor 0.2 vs recall without links (measured on 1.4.18; the implementation reproduces the same numbers on 1.4.29):** | Set | Short F1 | Short precision | Long F1 | Long precision | |---|---|---|---|---| | Set 1 | .766 → .796 | .900 → .833 | .454 → .488 | .483 → .500 | | Set 2 | .600 → .628 | .708 → .714 | .667 → .713 | .750 → .750 | | Holdout | .443 → .458 | .692 → .667 | .321 → .351 | .684 → .714 | | Pooled | .573 → .597 | .757 → .729 | .465 → .506 | .625 → .646 | - Added memories: short +9 relevant / +6 wrong; long +6 / +1. - Off-topic injections: unchanged in every cell. **The holdout test:** - The link types and the floor were fixed from the first two sets. - The holdout set's labels were then frozen, written from note titles and text without looking at the links, before any run. - The test was pre-registered as strict: no precision loss on short or long windows. It failed on short windows (.692 → .667). - Two of the three wrong short-window additions were borderline, but the labels were not changed. **Gate for this issue:** F1 up in every cell, no rise in off-topic injections, and long-window precision held or improved in every set. Long windows are the realistic case for roleplay-length messages. The cost is a small short-window precision loss in two of three sets (pooled .757 → .729). **Rejected alternatives:** - Untyped links: lower long-window gains. - Floor 0.25: fewer long-window gains. - Relevance borrowing (#1272): adds more irrelevant memories than relevant ones at every decay that changes anything. - Entity specificity: raises off-topic injections on two sets. - Attaching linked titles without adding memories: under half relevant. ## Additional context **Minimal fix:** 1. **`graph.ts`.** Replace `expandLtmGraph` with a one-hop typed lookup. - It takes the recall graph, the recalled seed note ids and a note-type lookup. - It returns `{ noteId, seedNoteId, relation }` for each linked note that is not itself a seed. It follows only the allowlist in Expected behavior. - `buildLtmGraphIndex` is unchanged. 2. **`retrieval.ts`.** - Remove the graph lane and `pickGraphSeedNotes`. - Fuse and budget the remaining lanes as today. - When the graph weight is above 0 and the threshold is above the floor (at or below it, the first pass already admitted every candidate linked recall could add): - Seed from the notes of the budgeted chunks. - Take the linked notes' chunks that are in the fused ranking with their own relevance at least `LTM_LINKED_RECALL_MIN_RELEVANCE`. Skip chunks already selected. - Mark each one as linked from its seed: lane `graph`, reason `graph:<relation>:<seedNoteId>`. - Run the budget once more over the selected chunks in fused order, then the linked chunks by fused score, then the rest of the ranking. 3. **`budget.ts` / `ranking.ts`.** - A candidate marked as linked skips the threshold check. - It keeps its own relevance score, so Debug does not show an inflated value. - The selected chunk is identified by its `graph` lane and reason; it needs no separate mark. 4. **`constants.ts`.** - Add `LTM_LINKED_RECALL_MIN_RELEVANCE = 0.2`, with a `ponytail:` note: it was measured only at balanced and threshold 0.35. The upgrade path is to scale it with the threshold or the graph weight after measuring. - Update the preset comment that describes the graph ceiling. - The preset weights are unchanged. 5. **Locale text.** - Graph weight help: describe it as on/off for linked recall. - Threshold help: drop "the graph lane caps at half its weight" and say that a memory linked from a recalled memory can be included below the threshold. 6. **Tests.** - Replace the preset assertion at `index-keys.regression.ts:354-370` with one that pins the floor below the default threshold and above 0. - Replace the runtime case "graph recall must expand from keyword-seeded notes" (`runtime.regression.ts:835-851`; it links world → world `caused_by` to a neighbour with no signal of its own) with these cases: - a typed neighbour of a recalled memory, with its own relevance between the floor and the threshold, is recalled, and the reason names its seed; - the same neighbour behind an untyped link is not recalled; - a neighbour below the floor is not recalled; - a neighbour of a memory that was not recalled is not recalled; - a graph weight of 0 disables linked recall; - the memory cap still bounds the total, with recalled memories kept first. 7. **Release.** A patch version with a changelog entry. Rebuild the package and catalog. **Other callers:** - Generation injection and `/search` pass the graph weight and the threshold. - Candidate reconciliation and source-extraction context pass neither, so the graph is on by default and the threshold is 0. - With no threshold, linked recall cannot add anything that non-graph recall did not already admit, so it is skipped. For these callers the change only removes graph-only neighbours from their candidates. - Reconciliation queries one note type at a time. Most stored links join different types, but same-type links exist (for example world → world `caused_by`), so its candidates can lose a graph-only neighbour. - Their existing tests must pass unchanged. **Not in scope:** - A graded meaning for the graph weight. - Two-hop links. - New link extraction: event → event (`caused_by`, `paid_off_in`) and event → participant (`involves`), with hub damping for the main characters. This is the larger opportunity, and needs its own issue and re-extraction. - A client Debug change to show the seed memory's title. The recall explanation already lists the `graph` lane and the reason. - Low recall on the holdout set (essential recall .21–.33), which no graph rule can fix. **Release note:** Recall can now include a memory that nearly matches the chat when a recalled memory links to it with an explanatory link. This applies in the balanced, broad and story styles. A memory reached only through a link, with no match of its own, is no longer recalled, even at a threshold of 0. A saved `custom` graph weight now turns linked recall on or off and no longer scales a score. Related: #1272, #1264, #1258. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:29:49 +07:00
  • closed this issue
  • added the
    bug
    label
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#695
No description provided.