[GH-ISSUE #1917] [Feature]: Long-Term Memory: Chat import detail setting (Standard or Detailed) #1821

Closed
opened 2026-11-07 16:36:53 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

Chat messages import cuts a chat into pieces of up to 24,000 characters and extracts memories from each piece. On a long roleplay chat, a 24k piece holds many scenes. The extractor keeps the main events and drops the small ones: a minor character, a side remark, a detail that matters later.

We measured this on one long roleplay chat. Each setting was imported twice with Sonnet, and Opus compared the resulting vaults. This ran after #1909, which merges short and full character names into one note.

24k pieces (today) 12k pieces
Pieces 18 38
Cost per import (Sonnet) $3.12–3.28 $5.70–5.71
Active memories 244–253 392–422
Facts found only in that vault, against the other 73 and 67 117 and 177
Run-to-run noise at 12k (facts only in one of two runs) 78 / 84
Character notes 12 16–17
Short/full-name duplicate pairs 1–2 0
Wrong facts (Opus) 2–3 7–11
Duplicate note groups (Opus) 14 28–37

Smaller pieces find clearly more, beyond the run-to-run noise, for about 1.8 times the cost. They also produce more duplicates and more wrong facts. So neither size is better for everyone. A user with a long, detailed roleplay and a budget for it wants more detail. A user with a cheaper model or a short chat wants today's behaviour.

Proposed package or change

An extraction setting, Chat import detail, with two choices:

  • Standard (default): 24,000 characters per piece, exactly as today.
  • Detailed: 12,000 characters per piece. Finds more small details, costs about 1.8 times as much, and may create more duplicate memories to review.

Each chat keeps the size it was first imported with. Pieces are named by their first message (entryId), so cutting an already-imported chat at a new size would produce different pieces. The old ones would then show as outdated in the preview, and importing the new ones would duplicate memories. So:

  • A chat with no imported pieces uses the current setting.
  • A chat that already has imported pieces keeps their size, whatever the setting says now. A branch takes the size of its chat group, so its pieces still match the parent's imported pieces after the setting changes.
  • Chats imported before this change have no recorded size and stay at 24k.

Re-importing an existing chat at a new size is not part of this issue.

Minimal fix

  • Setting: shared/src/features/agents/long-term-memory/schema/settings.ts
    • chatImportDetail: z.enum(["standard", "detailed"]).optional() in ltmExtractionSettingsFields (~298, next to finishCutOffAnswers);
    • chatImportDetail: z.enum([...]) in ltmResolvedExtractionSettingsSchema (~345).
    • The default "standard" goes in DEFAULT_LTM_EXTRACTION_CONFIG, server/.../extraction/extraction-config.ts (~36).
  • Piece size: server/src/services/long-term-memory/sources/interop.ts
    • chunks(value, cap) (~148) and transcriptPieces(messages, speaker, isStart, cap = 24_000) (~174) take the cap instead of the hard-coded 24_000 (~151, ~159 as cap / 2, ~194, ~203).
    • Record the size on the piece. A Detailed chat's chat_transcript candidates add piece_size:12000 to their evidence (~713). Standard pieces add nothing, so every existing source note keeps its evidence and its extraction fingerprint (candidateFingerprintForNote, ~372, hashes evidence), and nothing shows as updated.
    • Read it back. existingMatcher (~765) already walks every chat_transcript source note to build pieceStarts; it also records each chat group's size: 12,000 when a note carries piece_size:12000, otherwise 24,000. The key is the note's chat group (getLtmScopeGroupIds(note.scope)[0]), falling back to the chat id, the same key the branch merge (~420) uses. A branch copies messages under new ids and matches the parent's pieces only by identical text, so a branch that was never imported must cut at its group's size, or it would offer every piece as new.
    • candidates (~575) gets the chat sizes and the current setting next to pieceStarts. The messages builder (~694) uses the recorded size of the chat's group (falling back to its chat id), or the setting's size when neither has one. The three callers (previewPackageInterop ~916/~935, source details ~1102, importPackageInterop ~1144) read the setting with getLtmExtractionConfig(root).
    • CHAT_PIECE_TAIL_CHARS (3,000) and the branch-merge key (~420) stay as they are.
  • Client: client/src/features/long-term-memory/settings/MemorySettings.tsx
    • a two-option select in the Extraction section (next to "Finish cut-off answers", ~1079), with a help line that says what each choice costs and that it applies to chats imported from now on;
    • en and ko strings in client/src/features/long-term-memory/locales/. node scripts/validate-package-locales.mjs must pass.
  • Docs: packages/long-term-memory/docs/UI.md (~163) says Chat Messages imports in pieces of up to 24,000 characters; add one sentence on Detailed (12,000) and that each chat keeps the size of its first import. docs/ is in .git/info/exclude, so stage the tracked file with git add -u.

Regression

In tests/long-term-memory-chat-transcript-import.regression.ts, with its fake host and fake language model:

  1. transcriptPieces with a 12,000 cap keeps every piece at or under 12,000 characters. A single message longer than the cap splits into :part: pieces (as the 24k check at ~97 does).
  2. Setting Standard: preview and import give the same pieces, ids and evidence as today.
  3. Setting Detailed, new chat: pieces are cut at 12k and carry piece_size:12000.
  4. Chat imported at Standard, then the setting changes to Detailed: the preview gives the same pieces as before, reports nothing outdated, and everything stays current. New messages extend the chat at 24k.
  5. Chat imported at Detailed, then the setting changes back to Standard: the chat stays at 12k, with the same checks.
  6. A branch of a chat imported at Detailed, never imported itself, with the setting now Standard: the branch cuts at 12k and its shared pieces merge with the parent's imported pieces (no new rows for them).

In tests/long-term-memory-storage.regression.ts (~319): chatImportDetail defaults to "standard" and saves.

Non-goals

  • Re-importing an already-imported chat at another size.
  • A per-chat choice in the import dialog. The setting is global, and the recorded size is per chat.
  • Changing chat summary imports, character or lorebook imports, or the 3,000-character tail the next piece sees.
  • Reducing the duplicates and wrong facts that smaller pieces produce. That is extraction quality work and can follow separately.

Why should this be optional?

Detailed costs about 1.8 times as much per import and produces more duplicates to review. Standard stays the default, so nobody's cost or results change unless they choose Detailed.

Alternatives considered

  • A message count instead of a size. Messages vary from one line to several thousand characters, so a fixed count would give pieces of very different sizes. Pieces need a character limit for the prompt, so the setting stays a size, shown as two named choices.
  • Switch everyone to 12k. It doubles everyone's cost and adds duplicates, and every chat already imported would re-cut, show its old pieces as outdated, and duplicate memories on re-import. Rejected.
  • Cut at scene boundaries instead of a size. Measured in the same study (44 pieces, $6.6–6.8 a run): the extra facts came from the smaller pieces, not from where the cuts fell, and a 12k size cap found more for less. Rejected.
  • A free number field. More to explain, and the sizes between 12k and 24k were not measured. Two choices cover the trade-off.

Additional context

  • Measurement harness and runs are local (scratch/cut-point/): 38/38 pieces succeeded in both 12k runs, with 392–422 active memories.
  • The remaining 12k character errors were one conflation (two similar sisters), one name drift per run, and a name misspelled in the chat itself. None of them are piece-size bugs.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1917 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? Chat messages import cuts a chat into pieces of up to 24,000 characters and extracts memories from each piece. On a long roleplay chat, a 24k piece holds many scenes. The extractor keeps the main events and drops the small ones: a minor character, a side remark, a detail that matters later. We measured this on one long roleplay chat. Each setting was imported twice with Sonnet, and Opus compared the resulting vaults. This ran after #1909, which merges short and full character names into one note. | | 24k pieces (today) | 12k pieces | |---|---|---| | Pieces | 18 | 38 | | Cost per import (Sonnet) | $3.12–3.28 | $5.70–5.71 | | Active memories | 244–253 | 392–422 | | Facts found only in that vault, against the other | 73 and 67 | 117 and 177 | | Run-to-run noise at 12k (facts only in one of two runs) | | 78 / 84 | | Character notes | 12 | 16–17 | | Short/full-name duplicate pairs | 1–2 | 0 | | Wrong facts (Opus) | 2–3 | 7–11 | | Duplicate note groups (Opus) | 14 | 28–37 | Smaller pieces find clearly more, beyond the run-to-run noise, for about 1.8 times the cost. They also produce more duplicates and more wrong facts. So neither size is better for everyone. A user with a long, detailed roleplay and a budget for it wants more detail. A user with a cheaper model or a short chat wants today's behaviour. ## Proposed package or change An extraction setting, **Chat import detail**, with two choices: - **Standard** (default): 24,000 characters per piece, exactly as today. - **Detailed**: 12,000 characters per piece. Finds more small details, costs about 1.8 times as much, and may create more duplicate memories to review. **Each chat keeps the size it was first imported with.** Pieces are named by their first message (`entryId`), so cutting an already-imported chat at a new size would produce different pieces. The old ones would then show as outdated in the preview, and importing the new ones would duplicate memories. So: - A chat with no imported pieces uses the current setting. - A chat that already has imported pieces keeps their size, whatever the setting says now. A branch takes the size of its chat group, so its pieces still match the parent's imported pieces after the setting changes. - Chats imported before this change have no recorded size and stay at 24k. Re-importing an existing chat at a new size is not part of this issue. ### Minimal fix - Setting: `shared/src/features/agents/long-term-memory/schema/settings.ts` - `chatImportDetail: z.enum(["standard", "detailed"]).optional()` in `ltmExtractionSettingsFields` (~298, next to `finishCutOffAnswers`); - `chatImportDetail: z.enum([...])` in `ltmResolvedExtractionSettingsSchema` (~345). - The default `"standard"` goes in `DEFAULT_LTM_EXTRACTION_CONFIG`, `server/.../extraction/extraction-config.ts` (~36). - Piece size: `server/src/services/long-term-memory/sources/interop.ts` - `chunks(value, cap)` (~148) and `transcriptPieces(messages, speaker, isStart, cap = 24_000)` (~174) take the cap instead of the hard-coded `24_000` (~151, ~159 as `cap / 2`, ~194, ~203). - Record the size on the piece. A Detailed chat's `chat_transcript` candidates add `piece_size:12000` to their `evidence` (~713). Standard pieces add nothing, so every existing source note keeps its evidence and its extraction fingerprint (`candidateFingerprintForNote`, ~372, hashes `evidence`), and nothing shows as updated. - Read it back. `existingMatcher` (~765) already walks every `chat_transcript` source note to build `pieceStarts`; it also records each chat group's size: 12,000 when a note carries `piece_size:12000`, otherwise 24,000. The key is the note's chat group (`getLtmScopeGroupIds(note.scope)[0]`), falling back to the chat id, the same key the branch merge (~420) uses. A branch copies messages under new ids and matches the parent's pieces only by identical text, so a branch that was never imported must cut at its group's size, or it would offer every piece as new. - `candidates` (~575) gets the chat sizes and the current setting next to `pieceStarts`. The messages builder (~694) uses the recorded size of the chat's group (falling back to its chat id), or the setting's size when neither has one. The three callers (`previewPackageInterop` ~916/~935, source details ~1102, `importPackageInterop` ~1144) read the setting with `getLtmExtractionConfig(root)`. - `CHAT_PIECE_TAIL_CHARS` (3,000) and the branch-merge key (~420) stay as they are. - Client: `client/src/features/long-term-memory/settings/MemorySettings.tsx` - a two-option select in the Extraction section (next to "Finish cut-off answers", ~1079), with a help line that says what each choice costs and that it applies to chats imported from now on; - `en` and `ko` strings in `client/src/features/long-term-memory/locales/`. `node scripts/validate-package-locales.mjs` must pass. - Docs: `packages/long-term-memory/docs/UI.md` (~163) says Chat Messages imports in pieces of up to 24,000 characters; add one sentence on Detailed (12,000) and that each chat keeps the size of its first import. `docs/` is in `.git/info/exclude`, so stage the tracked file with `git add -u`. ### Regression In `tests/long-term-memory-chat-transcript-import.regression.ts`, with its fake host and fake language model: 1. `transcriptPieces` with a 12,000 cap keeps every piece at or under 12,000 characters. A single message longer than the cap splits into `:part:` pieces (as the 24k check at ~97 does). 2. Setting Standard: preview and import give the same pieces, ids and evidence as today. 3. Setting Detailed, new chat: pieces are cut at 12k and carry `piece_size:12000`. 4. Chat imported at Standard, then the setting changes to Detailed: the preview gives the same pieces as before, reports nothing outdated, and everything stays current. New messages extend the chat at 24k. 5. Chat imported at Detailed, then the setting changes back to Standard: the chat stays at 12k, with the same checks. 6. A branch of a chat imported at Detailed, never imported itself, with the setting now Standard: the branch cuts at 12k and its shared pieces merge with the parent's imported pieces (no new rows for them). In `tests/long-term-memory-storage.regression.ts` (~319): `chatImportDetail` defaults to `"standard"` and saves. ### Non-goals - Re-importing an already-imported chat at another size. - A per-chat choice in the import dialog. The setting is global, and the recorded size is per chat. - Changing chat summary imports, character or lorebook imports, or the 3,000-character tail the next piece sees. - Reducing the duplicates and wrong facts that smaller pieces produce. That is extraction quality work and can follow separately. ## Why should this be optional? Detailed costs about 1.8 times as much per import and produces more duplicates to review. Standard stays the default, so nobody's cost or results change unless they choose Detailed. ## Alternatives considered - **A message count instead of a size.** Messages vary from one line to several thousand characters, so a fixed count would give pieces of very different sizes. Pieces need a character limit for the prompt, so the setting stays a size, shown as two named choices. - **Switch everyone to 12k.** It doubles everyone's cost and adds duplicates, and every chat already imported would re-cut, show its old pieces as outdated, and duplicate memories on re-import. Rejected. - **Cut at scene boundaries instead of a size.** Measured in the same study (44 pieces, $6.6–6.8 a run): the extra facts came from the smaller pieces, not from where the cuts fell, and a 12k size cap found more for less. Rejected. - **A free number field.** More to explain, and the sizes between 12k and 24k were not measured. Two choices cover the trade-off. ## Additional context - Measurement harness and runs are local (`scratch/cut-point/`): 38/38 pieces succeeded in both 12k runs, with 392–422 active memories. - The remaining 12k character errors were one conflation (two similar sisters), one name drift per run, and a name misspelled in the chat itself. None of them are piece-size bugs. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-11-07 16:36:53 +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#1821
No description provided.