[GH-ISSUE #6705] [Feature]: Make semantic summary retrieval parameters configurable per chat #3755

Closed
opened 2026-10-21 06:06:52 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @boricha417 on GitHub (Sep 26, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6705

Originally assigned to: @SpicyMarinara on GitHub.

Follow-up to #5240 / #5246, which introduced semantic summary retrieval with these fixed values.

What problem does this solve?

When Semantic summary retrieval is enabled for a Roleplay chat, the number of summaries that reach the prompt is fixed by hard-coded constants in
packages/server/src/services/generation/roleplay-summary-retrieval.ts:

Constant Current value Effect
SEMANTIC_SUMMARY_RECENT_ENTRY_COUNT 2 Newest summaries that are always kept in context
SEMANTIC_SUMMARY_TOP_K 3 Maximum older summaries pulled in by similarity
SEMANTIC_SUMMARY_MIN_SIMILARITY 0.15 Calibrated similarity threshold for older summaries
(inline .slice(-4)) 4 Recent messages concatenated into the retrieval query

There is no way to change these from the UI, chat metadata, or app settings. In practice the right amount varies by scene: a long, slow-burn story benefits from keeping more recent summaries verbatim, while a fast-moving plot needs fewer. Likewise, some chats want older memories recalled more aggressively and others want them recalled only when clearly relevant.

For comparison, summaryTailMessages (the raw recent-message tail) is already user-adjustable, so the summary side is the only part of this system that cannot be tuned.

Proposed solution

Read the values from ChatMetadata with the current constants as defaults, so existing chats behave exactly as they do today:

  • semanticSummaryRecentEntryCount (default 2)
  • semanticSummaryTopK (default 3)
  • semanticSummaryMinSimilarity (default 0.15)

Expose them in the Chat Settings drawer next to the existing Semantic summary retrieval toggle (ChatSettingsDrawer.tsx), shown only while the toggle is on. Numeric inputs are enough; a single "long-term memory strength" slider that maps to top-K and threshold together would also work if a simpler UI is preferred.

The query message count could stay internal, since it affects retrieval accuracy rather than prompt size.

Alternatives considered

  • Personal extension. Not possible: the values are server constants, not metadata. Sandboxed server extensions have no access to generation, and browser extensions can only PATCH fields that already exist.
  • Toggling summary entries' enabled flag from an extension before each generation. Technically possible but it rewrites user-visible summary state on every turn, so it was rejected.

Additional context

Related observation while reading the code: older summaries are re-embedded on every generation (embedMemoryRecallTexts(olderEntries.map(...))), with no cache keyed by entry ID or content hash. With a remote embedding provider this means one embedding request per older summary per generation. Caching embeddings alongside the entries would reduce cost, and would matter more once users can raise top-K. Happy to split that into a separate issue if preferred.

Call sites that would receive the new options: generate.routes.ts, generate/dry-run-route.ts, generate/retry-agents-route.ts (all call resolveRoleplayChatSummaryForPrompt).

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @boricha417 on GitHub (Sep 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6705 Originally assigned to: @SpicyMarinara on GitHub. Follow-up to #5240 / #5246, which introduced semantic summary retrieval with these fixed values. ## What problem does this solve? When **Semantic summary retrieval** is enabled for a Roleplay chat, the number of summaries that reach the prompt is fixed by hard-coded constants in `packages/server/src/services/generation/roleplay-summary-retrieval.ts`: | Constant | Current value | Effect | |---|---|---| | `SEMANTIC_SUMMARY_RECENT_ENTRY_COUNT` | 2 | Newest summaries that are always kept in context | | `SEMANTIC_SUMMARY_TOP_K` | 3 | Maximum older summaries pulled in by similarity | | `SEMANTIC_SUMMARY_MIN_SIMILARITY` | 0.15 | Calibrated similarity threshold for older summaries | | (inline `.slice(-4)`) | 4 | Recent messages concatenated into the retrieval query | There is no way to change these from the UI, chat metadata, or app settings. In practice the right amount varies by scene: a long, slow-burn story benefits from keeping more recent summaries verbatim, while a fast-moving plot needs fewer. Likewise, some chats want older memories recalled more aggressively and others want them recalled only when clearly relevant. For comparison, `summaryTailMessages` (the raw recent-message tail) is already user-adjustable, so the summary side is the only part of this system that cannot be tuned. ## Proposed solution Read the values from `ChatMetadata` with the current constants as defaults, so existing chats behave exactly as they do today: - `semanticSummaryRecentEntryCount` (default 2) - `semanticSummaryTopK` (default 3) - `semanticSummaryMinSimilarity` (default 0.15) Expose them in the Chat Settings drawer next to the existing **Semantic summary retrieval** toggle (`ChatSettingsDrawer.tsx`), shown only while the toggle is on. Numeric inputs are enough; a single "long-term memory strength" slider that maps to top-K and threshold together would also work if a simpler UI is preferred. The query message count could stay internal, since it affects retrieval accuracy rather than prompt size. ## Alternatives considered - **Personal extension.** Not possible: the values are server constants, not metadata. Sandboxed server extensions have no access to generation, and browser extensions can only PATCH fields that already exist. - **Toggling summary entries' `enabled` flag from an extension before each generation.** Technically possible but it rewrites user-visible summary state on every turn, so it was rejected. ## Additional context Related observation while reading the code: older summaries are re-embedded on every generation (`embedMemoryRecallTexts(olderEntries.map(...))`), with no cache keyed by entry ID or content hash. With a remote embedding provider this means one embedding request per older summary per generation. Caching embeddings alongside the entries would reduce cost, and would matter more once users can raise top-K. Happy to split that into a separate issue if preferred. Call sites that would receive the new options: `generate.routes.ts`, `generate/dry-run-route.ts`, `generate/retry-agents-route.ts` (all call `resolveRoleplayChatSummaryForPrompt`). ## Template check - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@SirAdoni commented on GitHub (Sep 26, 2026):

I'm working on this in a clean sandbox based on current staging. I'll add per-chat controls for recent summaries, older-summary count, and the relevance threshold while preserving the current defaults, with regression coverage. I'll keep this in a focused PR; embedding-cache changes will stay outside this scope.

<!-- gh-comment-id:5847618832 --> @SirAdoni commented on GitHub (Sep 26, 2026): I'm working on this in a clean sandbox based on current staging. I'll add per-chat controls for recent summaries, older-summary count, and the relevance threshold while preserving the current defaults, with regression coverage. I'll keep this in a focused PR; embedding-cache changes will stay outside this scope.
Author
Owner

@boricha417 commented on GitHub (Sep 27, 2026):

Thanks for picking this up so quickly! The three controls and preserved defaults are exactly what I was hoping for, and the summary vector cache is a welcome bonus.

One request about placement, and this is my fault: the issue pointed at ChatSettingsDrawer.tsx, but the semantic retrieval switch lives in a different place per mode:

Mode Existing switch
Roleplay Chat Summaries popover (SummaryPopover.tsx)
Conversation Chat Settings drawer, Automatic Summarization section

The server side of #6744 already reads the new settings in both modes, but the controls only render for Roleplay, in a new drawer section with a second copy of the switch. So Roleplay gets a duplicate toggle away from the one people actually use, and Conversation has no way to set the values.

Could the three controls go directly under the existing switch in each mode, shown only while it is on, and the new Roleplay drawer section be dropped? A small shared component would cover both.

Minor: in Conversation the "recent" count applies to week summaries, so a label like "Recent weeks" would be clearer there.

If the popover is too tight on mobile, a collapsed "Advanced" row under the switch would work too.

<!-- gh-comment-id:5852960858 --> @boricha417 commented on GitHub (Sep 27, 2026): Thanks for picking this up so quickly! The three controls and preserved defaults are exactly what I was hoping for, and the summary vector cache is a welcome bonus. One request about placement, and this is my fault: the issue pointed at `ChatSettingsDrawer.tsx`, but the semantic retrieval switch lives in a different place per mode: | Mode | Existing switch | |---|---| | Roleplay | Chat Summaries popover (`SummaryPopover.tsx`) | | Conversation | Chat Settings drawer, Automatic Summarization section | The server side of #6744 already reads the new settings in both modes, but the controls only render for Roleplay, in a new drawer section with a second copy of the switch. So Roleplay gets a duplicate toggle away from the one people actually use, and Conversation has no way to set the values. Could the three controls go directly under the existing switch in each mode, shown only while it is on, and the new Roleplay drawer section be dropped? A small shared component would cover both. Minor: in Conversation the "recent" count applies to week summaries, so a label like "Recent weeks" would be clearer there. If the popover is too tight on mobile, a collapsed "Advanced" row under the switch would work too.
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-Engine#3755
No description provided.