[GH-ISSUE #1465] [Issue]: Long-Term Memory: a memory that shares one distinctive word with the chat is never recalled #744

Closed
opened 2026-10-20 17:30:17 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara, @Promansis on GitHub.

Summary

A memory whose only overlap with the chat is one distinctive word is never recalled, even when full-text search agrees it matches. Since #1264, a single ordinary exact keyword is capped at half the keyword lane (relevance 0.28 under the balanced style), which is below the 0.35 default threshold. The cap is right for everyday words, but it also blocks these memories, and on a labelled test fixture they are the largest group of missed essential memories. Counting the word when BM25 also rates the memory a reasonable match (normalized score ≥ 0.2) brings them back within the agreed noise limit.

Affected package

long-term-memory 1.4.53 (upstream/staging 2a3c37bb2).

S = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory

Expected behavior

An invented example. The chat says: "Want to hear me play the violin? Shut the door first."

Memory Shares Today Expected
Elena's violin was smashed in the storm; she hasn't played since. "violin", in 2 memories; BM25 agrees not recalled recalled
A violin shop opened by the station. "violin"; BM25 agrees not recalled may be recalled (accepted noise)
The cellar door sticks when it's wet. "door", in many memories not recalled not recalled, as #1264 intends

Today the reply can contradict the first memory ("Elena tunes her violin..."). Expected: the AI knows the violin is gone.

Actual behavior

S/recall/keyword-index.ts:209-218 caps every single ordinary exact keyword at LTM_KEYWORD_MAX_SCORE / 2. With the balanced keyword weight 0.56 that is relevance 0.28, so the 0.35 threshold drops the memory unless another lane scores it higher. The cap only changes a hit when 3 × frequency weight ≥ 2, which means the keyword is on about 5 or fewer of ~150 in-scope memories, so every capped hit is already a distinctive word.

Measurement

A private labelled fixture: 4 roleplay chats, 76 queries run as short and long windows (152), 89 essential labels per window length, plus off-topic windows. Balanced style, local MiniLM embeddings, threshold 0.35, cap 12. Notes are counted against today's selections. Only aggregate numbers are shared here.

Ruled out first:

  • Cap: 8 to 20 gives identical selections; it never binds.
  • Threshold: 0.28 recovers more but adds about 4 unwanted memories per recovered one, and off-topic chats get 7× more injections.
  • Title-aware embeddings and a salience boost: every variant loses essential memories at 0.35.

Decision (2026-10-19): a single shared word counts only when it is distinctive and BM25 agrees, and a fix may bring in at most 2 unwanted memories for each forgotten one it recovers. The pass rule and the variant were fixed before the run.

Result against today, all 152 windows
Essential memories recovered 24
Essential memories lost 0
Unwanted memories added 46 (11 in off-topic windows)
Unwanted per recovered 1.92 (limit 2): passes
Held-out chat, essential found 15 → 23 of 43 short; 10 → 19 of 43 long
F1, all chats .592 → .632 short; .501 → .573 long
Memories per off-topic window .33 → 1.00 short; .50 → 1.67 long
Without embeddings 27 recovered, 46 unwanted

Caveats: the pass is narrow, and most of the gain is on one chat (17 recovered for 18 unwanted; the other three give 7 for 28). The 0.2 gate came from an analysis that included that chat. A 0.3 gate gave 18 for 27; it is listed for context only and was not the pre-registered variant.

Steps to reproduce

  1. Give one memory a keyword that only one or two memories in the chat's scope have, and use the word in its text.
  2. Send a roleplay message that uses that word and shares nothing else with the memory.
  3. Recall with the balanced defaults and recall debug on. The memory is not injected; the Activity view lists it among the rejected candidates at relevance 0.28, under the 0.35 threshold marker.

Minimal fix

One PR, patch bump.

  • S/recall/keyword-index.ts: searchLtmKeywordIndex takes an optional lexicalScores?: ReadonlyMap<string, number> (chunk id to BM25 normalized score). In the #1264 cap loop (:209-218), a hit the cap would actually reduce (score ≥ LTM_KEYWORD_MAX_SCORE / 2 before the cap) whose lexical score is ≥ 0.2 scores LTM_KEYWORD_MAX_SCORE * 0.75 instead of being capped. Export the 0.2 gate as a named constant next to LTM_KEYWORD_MAX_SCORE. Names, multi-word phrases and two-keyword hits are unchanged, and a hit the cap does not reduce (an everyday word) is never lifted.
  • S/recall/retrieval.ts:178: pass the BM25 normalized scores that :152 already computes (lexical), keyed by chunk id.
  • CHANGELOG under ## Unreleased: one bullet.

Not included

  • A graded keyword score, a threshold change, or title embeddings (measured: no gain).
  • The keyword lane's per-recall cost: separate issue.

Regression proof

  • tests/long-term-memory-index-keys.regression.ts, beside the #1264 single-keyword case (:424): with a lexical score of 0.25 a single distinctive keyword scores 0.75 of the maximum; at 0.15, or with no map, it stays at or below 0.5; a keyword the cap does not reduce is not lifted, even with a high lexical score; the name and pair cases are unchanged.
  • In the same file, a retrieval case: a chunk sharing one distinctive keyword, with BM25 agreement, clears the default threshold in the balanced style. Re-check the #1264 per-style threshold cases (:354); a single-keyword chunk there may need text that keeps BM25 under the gate.

Environment

  • Marinara Engine version: 2.5.0 line (staging 2039583ca)
  • Package version: long-term-memory 1.4.53 (upstream/staging 2a3c37bb2)
  • Install type: source (measurement on a private fixture)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

None. The numbers come from a private labelled fixture and harness; the fixture contains private chat data, so only aggregates are shared.

Additional context

Tracker item RS-7. Follows #1264 (the single-keyword cap) and #1363 (known names keep full credit).

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 19, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1465 Originally assigned to: @SpicyMarinara, @Promansis on GitHub. ## Summary A memory whose only overlap with the chat is one distinctive word is never recalled, even when full-text search agrees it matches. Since #1264, a single ordinary exact keyword is capped at half the keyword lane (relevance 0.28 under the balanced style), which is below the 0.35 default threshold. The cap is right for everyday words, but it also blocks these memories, and on a labelled test fixture they are the largest group of missed essential memories. Counting the word when BM25 also rates the memory a reasonable match (normalized score ≥ 0.2) brings them back within the agreed noise limit. ## Affected package `long-term-memory` 1.4.53 (`upstream/staging` 2a3c37bb2). `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` ## Expected behavior An invented example. The chat says: "Want to hear me play the violin? Shut the door first." | Memory | Shares | Today | Expected | |---|---|---|---| | Elena's violin was smashed in the storm; she hasn't played since. | "violin", in 2 memories; BM25 agrees | not recalled | recalled | | A violin shop opened by the station. | "violin"; BM25 agrees | not recalled | may be recalled (accepted noise) | | The cellar door sticks when it's wet. | "door", in many memories | not recalled | not recalled, as #1264 intends | Today the reply can contradict the first memory ("Elena tunes her violin..."). Expected: the AI knows the violin is gone. ## Actual behavior `S/recall/keyword-index.ts:209-218` caps every single ordinary exact keyword at `LTM_KEYWORD_MAX_SCORE / 2`. With the balanced keyword weight 0.56 that is relevance 0.28, so the 0.35 threshold drops the memory unless another lane scores it higher. The cap only changes a hit when `3 × frequency weight ≥ 2`, which means the keyword is on about 5 or fewer of ~150 in-scope memories, so every capped hit is already a distinctive word. ### Measurement A private labelled fixture: 4 roleplay chats, 76 queries run as short and long windows (152), 89 essential labels per window length, plus off-topic windows. Balanced style, local MiniLM embeddings, threshold 0.35, cap 12. Notes are counted against today's selections. Only aggregate numbers are shared here. Ruled out first: - **Cap:** 8 to 20 gives identical selections; it never binds. - **Threshold:** 0.28 recovers more but adds about 4 unwanted memories per recovered one, and off-topic chats get 7× more injections. - **Title-aware embeddings and a salience boost:** every variant loses essential memories at 0.35. Decision (2026-10-19): a single shared word counts only when it is distinctive and BM25 agrees, and a fix may bring in at most 2 unwanted memories for each forgotten one it recovers. The pass rule and the variant were fixed before the run. | Result against today, all 152 windows | | |---|---| | Essential memories recovered | 24 | | Essential memories lost | 0 | | Unwanted memories added | 46 (11 in off-topic windows) | | Unwanted per recovered | 1.92 (limit 2): passes | | Held-out chat, essential found | 15 → 23 of 43 short; 10 → 19 of 43 long | | F1, all chats | .592 → .632 short; .501 → .573 long | | Memories per off-topic window | .33 → 1.00 short; .50 → 1.67 long | | Without embeddings | 27 recovered, 46 unwanted | Caveats: the pass is narrow, and most of the gain is on one chat (17 recovered for 18 unwanted; the other three give 7 for 28). The 0.2 gate came from an analysis that included that chat. A 0.3 gate gave 18 for 27; it is listed for context only and was not the pre-registered variant. ## Steps to reproduce 1. Give one memory a keyword that only one or two memories in the chat's scope have, and use the word in its text. 2. Send a roleplay message that uses that word and shares nothing else with the memory. 3. Recall with the balanced defaults and recall debug on. The memory is not injected; the Activity view lists it among the rejected candidates at relevance 0.28, under the 0.35 threshold marker. ## Minimal fix One PR, patch bump. - **`S/recall/keyword-index.ts`**: `searchLtmKeywordIndex` takes an optional `lexicalScores?: ReadonlyMap<string, number>` (chunk id to BM25 normalized score). In the #1264 cap loop (`:209-218`), a hit the cap would actually reduce (score ≥ `LTM_KEYWORD_MAX_SCORE / 2` before the cap) whose lexical score is ≥ 0.2 scores `LTM_KEYWORD_MAX_SCORE * 0.75` instead of being capped. Export the 0.2 gate as a named constant next to `LTM_KEYWORD_MAX_SCORE`. Names, multi-word phrases and two-keyword hits are unchanged, and a hit the cap does not reduce (an everyday word) is never lifted. - **`S/recall/retrieval.ts:178`**: pass the BM25 normalized scores that `:152` already computes (`lexical`), keyed by chunk id. - **CHANGELOG under `## Unreleased`**: one bullet. **Not included** - A graded keyword score, a threshold change, or title embeddings (measured: no gain). - The keyword lane's per-recall cost: separate issue. ## Regression proof - **`tests/long-term-memory-index-keys.regression.ts`**, beside the #1264 single-keyword case (`:424`): with a lexical score of 0.25 a single distinctive keyword scores 0.75 of the maximum; at 0.15, or with no map, it stays at or below 0.5; a keyword the cap does not reduce is not lifted, even with a high lexical score; the name and pair cases are unchanged. - In the same file, a retrieval case: a chunk sharing one distinctive keyword, with BM25 agreement, clears the default threshold in the balanced style. Re-check the #1264 per-style threshold cases (`:354`); a single-keyword chunk there may need text that keeps BM25 under the gate. ## Environment - Marinara Engine version: 2.5.0 line (`staging` 2039583ca) - Package version: long-term-memory 1.4.53 (`upstream/staging` 2a3c37bb2) - Install type: source (measurement on a private fixture) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video None. The numbers come from a private labelled fixture and harness; the fixture contains private chat data, so only aggregates are shared. ## Additional context Tracker item RS-7. Follows #1264 (the single-keyword cap) and #1363 (known names keep full credit). ## 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:30:17 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Oct 19, 2026):

@Promansis the maintainer asked us to land this for the release, so it is in Pasta-Devs/Marinara-Agents#1472, after the Pasta-Devs/Marinara-Agents#1467 keyword-lane fix (Long-Term Memory 1.4.54). It is implemented as written: an optional lexicalScores map, LTM_SINGLE_KEYWORD_BM25_AGREEMENT = 0.2 exported beside LTM_KEYWORD_MAX_SCORE, a flat LTM_KEYWORD_MAX_SCORE * 0.75 for a hit the cap would cut, and retrieval passing its BM25 normalized scores. The regression adds your violin example as a balanced-style retrieval case. The changelog bullet is under the 1.4.54 heading instead of ## Unreleased, because the notes build requires the version it publishes. Thank you for the labelled-fixture measurements and the pre-registered pass rule.

<!-- gh-comment-id:6264346921 --> @SpicyMarinara commented on GitHub (Oct 19, 2026): @Promansis the maintainer asked us to land this for the release, so it is in Pasta-Devs/Marinara-Agents#1472, after the Pasta-Devs/Marinara-Agents#1467 keyword-lane fix (Long-Term Memory 1.4.54). It is implemented as written: an optional `lexicalScores` map, `LTM_SINGLE_KEYWORD_BM25_AGREEMENT = 0.2` exported beside `LTM_KEYWORD_MAX_SCORE`, a flat `LTM_KEYWORD_MAX_SCORE * 0.75` for a hit the cap would cut, and retrieval passing its BM25 normalized scores. The regression adds your violin example as a balanced-style retrieval case. The changelog bullet is under the 1.4.54 heading instead of `## Unreleased`, because the notes build requires the version it publishes. Thank you for the labelled-fixture measurements and the pre-registered pass rule.
Author
Owner

@SpicyMarinara commented on GitHub (Oct 19, 2026):

Fixed on staging by #1472; update Long-Term Memory from the catalog to get it.

<!-- gh-comment-id:6265130052 --> @SpicyMarinara commented on GitHub (Oct 19, 2026): Fixed on staging by #1472; update Long-Term Memory from the catalog to get it.
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#744
No description provided.