AAAK Compression
Adaptive Associative Abstraction Kernel (AAAK) is Mnemosyne's text substitution system for reducing memory content size. It is not a method on the Memory class — it is a standalone utility used during consolidation.
The Problem
Agent context windows are limited (4K–128K tokens). Raw memory dumps consume precious space. AAAK applies deterministic text substitutions to compress related memories into shorter representations.
How AAAK Works
The encode() function performs text substitution in three passes:
- Category prefixes: Replaces verbose category labels with short tokens (e.g.,
"conversation:"→"conv:") - Phrase compression: Substitutes common phrases with abbreviated forms
- Structural: Normalizes whitespace, removes redundant formatting
Compression Ratios
AAAK achieves approximately 30–50% text reduction:
| Content Type | Original | Compressed | Reduction |
|---|---|---|---|
| Conversation | 1,000 chars | ~600 chars | ~40% |
| Documentation | 800 chars | ~500 chars | ~38% |
| Mixed content | 1,200 chars | ~700 chars | ~42% |
Actual ratios vary by content. AAAK is lossy — some detail is sacrificed for brevity.
Using AAAK
from mnemosyne.aaak import encode
# Encode (compress) text
compressed = encode(original_text)
# The result is a shorter string, not a separate object
print(f"Original: {len(original_text)} chars")
print(f"Compressed: {len(compressed)} chars")
During Consolidation
AAAK is applied automatically during sleep consolidation when summarizing groups of Working Memory entries:
flowchart LR WM[Working Memory Entries] -->|group by source| G[Grouped] G -->|encode via AAAK| C[Compressed Summary] C -->|promote| EM[Episodic Memory]
Important Notes
encode()is one-way: There is nodecode()orexpand()function. Once compressed, the original text is not recoverable from the output alone.- Not a Memory method: AAAK is a standalone module, not called via
mem.compress()ormem.expand(). - Used during consolidation: Applied by the sleep consolidation pipeline to compress summaries before promoting to Episodic Memory.
AAAK is lossy — fine details may be lost during compression. Critical facts should be stored in Semantic Memory (which is not compressed) or marked with high importance to preserve detail.
Mnemosyne