Every compression system faces the same tension: compress more to save tokens, or compress less to preserve information. CCR (Cache, Compress, Retrieve) resolves this tension by making compression reversible — removed blocks are replaced with retrieval markers, and the original content can be restored on demand.

TL;DR: CCR caches removed text blocks, replaces them with [SC-Retrieve: hash] markers in the compressed output, and provides a /api/retrieve endpoint to restore originals. It's like a reversible compression codec for LLM prompts. Zero data loss, full audit trail.

The Problem with Lossy Compression

Standard prompt compression is lossy — removed tokens are gone forever. For most use cases (chat history, RAG context, agent memory), this is fine because the removed content is truly irrelevant to the query. But there are cases where lossy compression creates risk:

CCR solves all of these. The removal is still lossy from the LLM's perspective (the marker takes ~5 tokens instead of the original block), but it's reversible from the application's perspective — you can always get the original back.

How CCR Works

Step 1: Cache

The original text is hashed with simpleHash (a fast, collision-resistant hash function) and stored in an LRU cache. On the browser side, the cache lives in a JS Map with max 500 entries and access-tracking for LRU eviction. On the server side, the cache is backed by Vercel Blob for persistent storage.

Hash algorithm:
  1. For each byte in the UTF-8 encoded text:
     hash = (hash × 31 + byte) & 0xFFFFFFFF
  2. Return hex(hash) + "_" + hex(text.length)

Step 2: Compress with Markers

The compressor runs as usual, scoring and removing low-value lines. But instead of discarding removed blocks entirely, it:

  1. Hashes each removed block (blocks > 10 tokens)
  2. Stores the original text in the cache
  3. Replaces the block with [SC-Retrieve: hash] at the exact position where the block was removed
// Original:
Line 1: API responded with status 200
Line 2: Processing user data... (removed)
Line 3: Validating input fields... (removed)
Line 4: User validation passed
Line 5: DEBUG: cache hit ratio 0.87 (removed)
Line 6: Generating response...

// Compressed with CCR:
Line 1: API responded with status 200
[SC-Retrieve: a1b2c3d4_1a]  ← lines 2-3 were removed
Line 4: User validation passed
[SC-Retrieve: e5f6g7h8_2b]  ← line 5 was removed
Line 6: Generating response...

Step 3: Retrieve

An LLM or agent that encounters a [SC-Retrieve: hash] marker can fetch the original content:

# The LLM reads the marker and decides it needs the original
# The application calls:
GET /api/retrieve?hash=a1b2c3d4_1a

# Response:
{
  "original": "Processing user data...\nValidating input fields...",
  "hash": "a1b2c3d4_1a",
  "retrieved_at": "2026-07-07T12:00:00Z",
  "token_count": 12
}

Retrieval is authenticated via the same X-API-Key header used for compression. Rate-limited at 600 requests per minute.

Architecture

ComponentClient-SideServer-Side
StorageLRU Map (max 500 entries)Vercel Blob (persistent)
HashsimpleHash (JS)simpleHash (matching implementation)
MarkersInterspersed at correct line positionsAppended at end of compressed text
RetrievalccrRetrieve(hash) from cacheGET /api/retrieve?hash=
EvictionLRU (oldest-access-first)Vercel Blob (no eviction)

Use Cases

1. Agent Workflows with Checkpoints

An agent compresses context at each step. If a later step needs a detail that was removed, it retrieves it via the hash. This enables aggressive compression between steps without sacrificing eventual answer quality.

Step 1: Compress(original_context, "Find the user") → [SC-Retrieve: hash1]... [SC-Retrieve: hash2]
Step 2: Agent reads marker hash1 → retrieves → answers "User is Alice"
Step 3: Compress(step2_context, "Check Alice's permissions") → ...
Step 4: Agent needs step 1 detail → retrieves hash2

2. Audit Trails

For regulated industries (finance, healthcare, legal), CCR provides a complete audit trail. Every removed block has a retrievable original and a timestamp of when it was stored.

// Audit log entry:
{
  "request_id": "req_42",
  "hash": "a1b2c3d4_1a",
  "stored_at": "2026-07-07T12:00:00Z",
  "original_tokens": 150,
  "removed_by": "compiler",
  "retrieved_at": null  // Never needed originals
}

3. Debugging Compression Quality

When a compressed prompt produces a wrong answer, you can inspect exactly what was removed. This is invaluable for tuning compression thresholds and understanding failure modes.

// Before: Why did the LLM answer incorrectly?
// After debugging with CCR:
retrieved_block = ccrRetrieve("e5f6g7h8_2b")
// → "The answer to the user's question is: 42"
// Problem: The answer line was incorrectly scored as low-value!

Usage

HTTP API

# Compress with CCR enabled
curl -X POST https://supercompress.dev/api/v1/compress \
  -H "X-API-Key: sc_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "context": "long context...",
    "query": "What matters?",
    "ccr": true
  }'

# Response:
# {
#   "compressed_text": "Kept line 1\n[SC-Retrieve: a1b2c3d4_1a]\nKept line 3\n...",
#   "ccr": {
#     "hash": "fulltext_hash_1a2b",
#     "stored": true,
#     "retrieve_url": "/api/retrieve?hash=fulltext_hash_1a2b"
#   },
#   "tokens_saved": 850
# }

# Retrieve a removed block
curl https://supercompress.dev/api/retrieve?hash=a1b2c3d4_1a \
  -H "X-API-Key: sc_live_YOUR_KEY"
# → {"original": "...", "hash": "a1b2c3d4_1a", "retrieved_at": "...", "token_count": 12}

Browser (JS)

// Compress with CCR
const result = SuperCompressEngine.compressCCR(
  context, query, model,
  { enableMarkers: true }
);
// result.compressed_text has [SC-Retrieve: hash] markers

// Retrieve a block
const original = SuperCompressEngine.ccrRetrieve("a1b2c3d4_1a");

// Check cache stats
const stats = SuperCompressEngine.ccrGetStats();
console.log(`Cache: ${stats.entries} entries, ${stats.bytes} bytes`);

Tradeoffs

FactorStandard CompressionCCR
Token savings~82.5%~80% (markers take ~5 tokens each)
Data lossYesNone (reversible)
StorageNone neededCache/bloom storage for removed blocks
Latency overhead~60ms+5–10ms (hashing + cache writes)
Audit trailNoYes — every removal is logged

What's Next


CCR is available in SuperCompress v0.6+. Get your API key to try it on production traffic. Combine with Precision Mode for guaranteed-quality, reversible compression.