A deep technical exploration of semantic compression — the process of reducing AI conversation transcripts by 60-80% while preserving entities, decisions, preferences, and structural relationships.
Founder & Lead Engineer at Toffee
When most people hear "compression" in the context of AI conversations, they imagine a simple summary — a paragraph that captures the gist of what was discussed. While summarization is a useful tool, it is fundamentally insufficient for preserving the richness of an AI interaction. A summary captures what was discussed but loses how decisions were made, what alternatives were rejected, and why specific approaches were chosen.
Semantic compression is a more sophisticated approach. Rather than producing a prose summary, it deconstructs a conversation into its constituent knowledge components — entities, relationships, decisions, preferences, and patterns — then reconstructs this information in a structured, token-efficient format that another language model can fully internalize.
The distinction matters because the goal of compression in the context transfer domain is not human readability. The goal is model comprehension: producing an artifact that allows a receiving AI model to behave as if it had participated in the original conversation.
This article explains the theory, architecture, and implementation of semantic compression as used in modern AI context transfer systems.
Consider a typical 45-minute software development conversation with ChatGPT. The raw transcript might contain 20,000–35,000 tokens. If you examine that transcript carefully, you will find that a significant portion consists of:
In our analysis of over 1,000 real-world AI conversations, we found that on average 65% of tokens in a conversation transcript are semantically redundant for the purpose of context reconstruction. This means a 30,000-token conversation contains approximately 10,500 tokens of unique, essential information.
The challenge is identifying which tokens are essential and which can be safely discarded without losing meaning. This is where the multi-stage compression pipeline becomes necessary.
Toffee's semantic compression engine processes conversations through eight sequential stages, each targeting a different type of information extraction:
The raw conversation is parsed into a structured turn-by-turn format, separating user prompts from model responses. Code blocks are extracted and tagged with their language. This stage also normalizes formatting differences across platforms — ChatGPT, Claude, and Gemini each use slightly different markdown conventions.
interface ParsedTurn {
role: 'user' | 'assistant';
content: string;
codeBlocks: Array<{
language: string;
code: string;
context: string; // What was the code solving?
}>;
timestamp?: string;
turnIndex: number;
}
The engine identifies all named entities in the conversation: file names, function names, API endpoints, database tables, configuration values, URLs, library names, and technical concepts. Each entity is tagged with its type and the context in which it appeared.
For example, in a conversation about building a REST API, the entity extractor might identify:
users table (database entity)POST /api/auth/login (API endpoint)bcrypt (library dependency)JWT_SECRET (configuration value)UserService.authenticate() (function reference)This stage identifies explicit and implicit decisions made during the conversation. A decision is any point where alternatives were considered and a choice was made. The mapper extracts:
For instance: "Decided to use PostgreSQL instead of MongoDB because the data has relational structure and we need ACID transactions for payment processing."
The engine detects user preferences that influence how the AI should respond. These include coding style preferences (tabs vs. spaces, semicolons, naming conventions), communication preferences (concise vs. detailed explanations), and architectural preferences (monolith vs. microservices, REST vs. GraphQL).
Domain-specific knowledge established during the conversation is synthesized into declarative statements. This transforms conversational back-and-forth into structured facts that a receiving model can immediately apply.
For conversations involving code, this stage identifies the final, working version of any code artifact. Intermediate attempts, debugging iterations, and superseded implementations are discarded. Only the final working code, its purpose, and its integration context are preserved.
Not all extracted information is equally important. This stage assigns relevance scores based on recency (more recent = higher priority), frequency of reference (entities mentioned multiple times are more important), and dependency (information that other pieces depend on is prioritized).
The final stage assembles all extracted components into the structured .toffee bundle format, applying final token optimization (removing unnecessary whitespace, using abbreviations where unambiguous) and generating the HMAC integrity signature.
The effectiveness of semantic compression varies significantly depending on the conversation type. Here are benchmark ratios from real-world testing across different use cases:
| Conversation Type | Avg. Input Tokens | Avg. Output Tokens | Compression Ratio |
|---|---|---|---|
| Software development (debugging) | 28,000 | 7,200 | 74% |
| Software development (architecture) | 22,000 | 8,800 | 60% |
| Research analysis | 35,000 | 11,500 | 67% |
| Content writing | 18,000 | 6,300 | 65% |
| Data analysis | 25,000 | 9,000 | 64% |
| Learning/tutorial | 20,000 | 5,400 | 73% |
Debugging conversations achieve the highest compression ratios because they contain the most redundancy: failed attempts, error messages, and iterative fixes that all collapse into the final solution. Architecture discussions compress less efficiently because almost every statement contains unique design information.
The key insight is that compression ratio alone is not the right metric. What matters is semantic preservation: does the compressed bundle contain enough information for a receiving model to continue the work effectively? Our internal testing shows that bundles achieving 60-75% compression still preserve over 95% of actionable context.
The compression pipeline itself uses an LLM to perform the semantic analysis. This creates an interesting architectural pattern: using one AI model to compress context for another.
The compression prompt is engineered to produce structured output. Here is a simplified version of the system prompt used for the synthesis stage:
You are a semantic compression engine. Analyze the following AI conversation
and produce a structured context bundle.
EXTRACT:
1. ENTITIES: All named technical entities (files, functions, APIs, configs)
2. DECISIONS: Every decision made, including alternatives considered
3. PREFERENCES: User's stated or implied preferences
4. KNOWLEDGE: Domain facts established during the conversation
5. CODE: Final versions of any code artifacts (discard intermediate attempts)
6. OPEN_ITEMS: Unresolved questions or planned next steps
FORMAT RULES:
- Use bullet points, not prose
- Include entity types in brackets: [file], [function], [api], [config]
- For decisions, use: DECIDED: X, REJECTED: Y, REASON: Z
- Omit all pleasantries, acknowledgments, and filler text
- Preserve exact names, values, and code identifiers
This approach is more effective than rule-based extraction because LLMs understand semantic relationships that regular expressions and NLP pipelines cannot capture. The model understands that when a user says "let's go with the first approach," it refers to a specific technical choice discussed earlier in the conversation.
The compression model itself runs on our backend, but raw conversations are only sent to it when the user explicitly requests server-side compression. For local-only mode, we use a lighter heuristic-based compression that achieves approximately 40-50% reduction without requiring any network requests.
How do you verify that compression preserved the essential information? This is one of the hardest problems in semantic compression, and there is no perfect solution. We employ several approaches:
We periodically test compressed bundles by injecting them into a fresh AI session and asking the model questions that can only be answered correctly with full context. If the model correctly answers questions about decisions, entities, and preferences, the bundle passes verification.
We compare the set of entities in the original conversation against the set in the compressed bundle. A well-compressed bundle should retain at least 95% of unique entities (with the missing 5% being incidental mentions that do not affect the ongoing work).
After injecting a bundle, users can rate whether the receiving model "understood" their context. This feedback is used to continuously improve the compression prompts and pipeline stages.
Semantic compression is not a solved problem — it is an active area of research and development. Each improvement in LLM capability enables more sophisticated compression, and each new AI platform's unique strengths require adapting the injection format. What matters is that the current state of the art is already dramatically better than the alternative of manual copy-pasting or starting every conversation from scratch.
Text summarization produces a human-readable prose summary. Semantic compression deconstructs a conversation into structured components — entities, decisions, preferences, code artifacts — optimized for another AI model to internalize. The output is designed for machine comprehension, not human reading.
Based on testing across thousands of conversations, semantic compression achieves 60-80% token reduction depending on the conversation type. Debugging sessions compress more (74% average) because they contain high redundancy from iterative attempts. Architecture discussions compress less (60% average) because each statement carries unique information.
A well-designed compression pipeline preserves over 95% of actionable context. The removed content consists of politeness tokens, redundant re-explanations, superseded code attempts, and exploratory tangents that do not affect the ongoing work. Decisions, entities, preferences, and final code artifacts are always preserved.
Yes. Toffee bundles are transparent — you can inspect the compressed output before injecting it into another platform. The bundle shows extracted entities, decisions, preferences, and synthesized knowledge in a structured format.
Learn how AI context transfer works, why language models lose memory between sessions, and how protocols like Toffee compress and port conversation context across ChatGPT, Claude, and Gemini without data loss.
Practical techniques for reducing token usage in AI applications — from prompt engineering and context pruning to semantic deduplication and budget-aware injection strategies.
How to architect systems that give AI applications persistent, cross-platform memory — covering local-first storage, sync engines, offline support, and the future of AI knowledge graphs.