mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
2 lines
7.9 KiB
JavaScript
2 lines
7.9 KiB
JavaScript
import{_ as e,o,c as a,ag as s}from"./chunks/framework.DXGyWiRo.js";const p=JSON.parse('{"title":"Context Compaction","description":"","frontmatter":{},"headers":[],"relativePath":"getting-started/compaction.md","filePath":"getting-started/compaction.md","lastUpdated":1776332711000}'),n={name:"getting-started/compaction.md"};function i(r,t,c,l,d,h){return o(),a("div",null,[...t[0]||(t[0]=[s('<h1 id="context-compaction" tabindex="-1">Context Compaction <a class="header-anchor" href="#context-compaction" aria-label="Permalink to "Context Compaction""></a></h1><p><strong>Context Compaction</strong> reduces the prompt footprint of a single conversation session by summarizing older turns and keeping the active context smaller.</p><p>This page is about <strong>session context</strong>, not long-term memory storage. If you want to merge or rewrite stored memories in a memory provider, see <a href="/getting-started/memory.html">Bot Memory Management</a>.</p><hr><h2 id="why-it-exists" tabindex="-1">Why It Exists <a class="header-anchor" href="#why-it-exists" aria-label="Permalink to "Why It Exists""></a></h2><p>As a conversation grows, the bot needs to send more prior messages back to the model. That increases:</p><ul><li>token usage</li><li>latency</li><li>pressure on the model's context window</li><li>the chance that older but still important turns will crowd out newer ones</li></ul><p>Context compaction helps by replacing older conversational detail with a shorter summary that still preserves enough continuity for the next turns.</p><hr><h2 id="what-it-changes" tabindex="-1">What It Changes <a class="header-anchor" href="#what-it-changes" aria-label="Permalink to "What It Changes""></a></h2><p>Context compaction affects the <strong>active session context</strong> only.</p><p>It does <strong>not</strong>:</p><ul><li>delete the bot itself</li><li>change the configured memory provider</li><li>merge long-term memory records</li><li>replace the need for memory search</li></ul><p>In practice, it changes how much historical session text is carried into future model calls.</p><hr><h2 id="automatic-compaction" tabindex="-1">Automatic Compaction <a class="header-anchor" href="#automatic-compaction" aria-label="Permalink to "Automatic Compaction""></a></h2><p>Configure automatic context compaction from the bot's <strong>General</strong> tab.</p><p>Relevant fields:</p><table tabindex="0"><thead><tr><th>Field</th><th>Description</th></tr></thead><tbody><tr><td><strong>Compaction Enabled</strong></td><td>Enable or disable automatic context compaction for this bot.</td></tr><tr><td><strong>Compaction Threshold</strong></td><td>Estimated token threshold that triggers background compaction.</td></tr><tr><td><strong>Compaction Ratio</strong></td><td>How aggressively the session should be reduced during compaction.</td></tr><tr><td><strong>Compaction Model</strong></td><td>The model used to summarize old session context.</td></tr></tbody></table><p>When enabled, Memoh can compact context in the background after a turn when the estimated input size passes the configured threshold.</p><p>Memoh also uses the selected model's <code>context_window</code> to understand how close the session is to the available budget.</p><hr><h2 id="immediate-compaction" tabindex="-1">Immediate Compaction <a class="header-anchor" href="#immediate-compaction" aria-label="Permalink to "Immediate Compaction""></a></h2><p>You can trigger compaction immediately for the current session in two ways:</p><h3 id="from-the-session-status-panel" tabindex="-1">From The Session Status Panel <a class="header-anchor" href="#from-the-session-status-panel" aria-label="Permalink to "From The Session Status Panel""></a></h3><ol><li>Open the active conversation.</li><li>Open the session status panel.</li><li>Click <strong>Compact Now</strong>.</li></ol><p>The status panel also shows the current context usage, cache hit rate, and used skills, which helps you decide whether compaction is useful right now.</p><h3 id="from-slash-commands" tabindex="-1">From Slash Commands <a class="header-anchor" href="#from-slash-commands" aria-label="Permalink to "From Slash Commands""></a></h3><p>Run:</p><div class="language-text vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">text</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>/compact</span></span></code></pre></div><p>or:</p><div class="language-text vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">text</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span>/compact run</span></span></code></pre></div><p>This runs synchronous context compaction for the current session and returns a status result to chat.</p><hr><h2 id="status-and-logs" tabindex="-1">Status And Logs <a class="header-anchor" href="#status-and-logs" aria-label="Permalink to "Status And Logs""></a></h2><p>The <strong>Compaction</strong> tab in the bot detail page provides an audit trail for context compaction runs.</p><p>Typical fields include:</p><ul><li><strong>Status</strong> — whether the compaction finished successfully or failed</li><li><strong>Summary</strong> — the compacted summary text or a summary preview</li><li><strong>Message Count</strong> — how many messages were involved</li><li><strong>Started / Completed Time</strong> — when the run happened</li><li><strong>Model / Usage</strong> — metadata about the model and token usage when available</li></ul><p>The log list is useful when you want to verify that automatic compaction is actually running or diagnose a failure.</p><hr><h2 id="relationship-to-context-window" tabindex="-1">Relationship To <code>context_window</code> <a class="header-anchor" href="#relationship-to-context-window" aria-label="Permalink to "Relationship To `context_window`""></a></h2><p>Memoh tracks the current session against the selected chat model's <code>context_window</code>.</p><p>You can see this in:</p><ul><li>the Web UI session status panel</li><li>the <code>/status</code> slash command</li></ul><p>Compaction becomes more valuable as the active session gets closer to the model's context limit. A dedicated compaction model can also be used to summarize more cheaply than the main chat model.</p><hr><h2 id="context-compaction-vs-memory-compaction" tabindex="-1">Context Compaction vs Memory Compaction <a class="header-anchor" href="#context-compaction-vs-memory-compaction" aria-label="Permalink to "Context Compaction vs Memory Compaction""></a></h2><p>These two features sound similar but solve different problems:</p><table tabindex="0"><thead><tr><th>Feature</th><th>Scope</th><th>Trigger</th><th>Result</th></tr></thead><tbody><tr><td><strong>Context Compaction</strong></td><td>One active session</td><td>Session panel or <code>/compact</code></td><td>Summarizes older chat history for future turns</td></tr><tr><td><strong>Memory Compaction</strong></td><td>Long-term memory provider</td><td>Memory tab</td><td>Rewrites stored memory entries</td></tr></tbody></table><p>Use <strong>Context Compaction</strong> when one conversation has become too large.</p><p>Use <strong>Memory Compaction</strong> when the bot's stored memories themselves have become noisy or redundant.</p><hr><h2 id="next-steps" tabindex="-1">Next Steps <a class="header-anchor" href="#next-steps" aria-label="Permalink to "Next Steps""></a></h2><ul><li>To inspect session runtime information, see <a href="/getting-started/sessions.html">Sessions</a>.</li><li>To understand slash-triggered compaction, see <a href="/getting-started/slash-commands.html">Slash Commands</a>.</li><li>To manage long-term memory instead of session context, see <a href="/getting-started/memory.html">Bot Memory Management</a>.</li></ul>',54)])])}const u=e(n,[["render",i]]);export{p as __pageData,u as default};
|