The headline
| Property | Value |
|---|---|
| Sample | 1,314 real Kemory chat sessions; 8,369 decision steps (one per user → assistant exchange) |
| Excluded | 12 chats with no complete exchange |
| Compared | Full-history replay against Kemory's tiered context, at every step of every session |
| Metric | Reader input tokens, summed across steps — each turn re-sends its context to a stateless API |
| Tokenizer | tiktoken o200k_base, as a documented proxy (see caveats) |
| Compactor | Kemory's configured route, Groq openai/gpt-oss-120b; the digest itself comes from Kemory's deterministic extractive path |
| Price reference | Frontier reader at claude-opus-4-8 published input price |
| Evidence | Deterministic replay for tokens; published-rate scenario for money. No figure here is observed billing. |
| Snapshot | All persisted chats in the Kemory database, July 2026; measurement package dated 22 July 2026 |
Four answers
The study answers four questions, each labelled with the kind of evidence behind it.
| Question | Answer | Evidence |
|---|---|---|
| A. What does routing the compactor to an open-weight model save? | The same workload — 6,196,796 input and 1,739,864 output tokens across 2,026 compactor calls — costs $1.97 on Groq gpt-oss-120b and $74.48 at claude-opus-4-8 prices. A 97.4% unit-price saving. | Replay workload × published rates |
| B. How many reader tokens does tiered context avoid? | 73,346,915 → 20,414,684: 52,932,231 avoided (72.2%). Producing the digests costs 7,936,660 tokens — 28.0% of the strategy's tokens — so the reduction in total tokens is 61.3%. | Deterministic replay |
| C. What is the net saving in money? | Full history at a frontier reader's input price: $366.73. Tiered reader plus open-weight compactor: $104.05. Net saving $262.69 (71.6%), without prompt caching. | Replay tokens × published rates |
| D. Does anything that shouldn't reach the prompt reach it? | AAAK payloads in the default context: 0. Every digest carries the ids of the exchanges, turns and memories it was built from. | Audit of the assembly path |
72.2% is reader tokens avoided — what a premium model no longer has to read. 61.3% is total tokens, after adding back what the compactor reads and writes to produce the digests. The first matters because reader tokens are the expensive ones; the second is the honest count of work done. They answer different questions and should not be quoted as one another.
By session length
The aggregate is real, but it rests on the long sessions. Change in reader input tokens, tiered context against full history, by the number of exchanges in the session:
| Exchanges | Sessions | Full history | Tiered | Reader tokens saved | Compaction tax |
|---|---|---|---|---|---|
| 1 | 396 | 31,991 | 93,829 | −193.3% | 0 |
| 2 | 254 | 167,423 | 199,589 | −19.2% | 0 |
| 3–5 | 278 | 1,605,794 | 1,682,475 | −4.8% | 382,226 |
| 6–9 | 159 | 3,240,596 | 2,682,124 | 17.2% | 930,906 |
| 10–19 | 130 | 9,538,651 | 4,873,152 | 48.9% | 1,960,288 |
| 20+ | 97 | 58,762,460 | 10,883,515 | 81.5% | 4,663,240 |
| All | 1,314 | 73,346,915 | 20,414,684 | 72.2% | 7,936,660 |
On sessions of five exchanges or fewer, tiered context sends more than full history. The namespace background summary and the digest wrapper cost more than simply re-sending a handful of short exchanges. It crosses over at six to nine exchanges, and the 97 sessions of twenty or more exchanges account for 90% of every token avoided — 58.8M down to 10.9M.
Add the compaction tax back in and, counted in raw tokens, the crossover moves out: the 6–9 bin uses 11.5% more tokens in total, and only from ten exchanges up does the total fall (−28.4% at 10–19, −73.5% at 20+). Counted in money it does not move, because the tax is paid at open-weight prices and the saving at frontier ones: the 6–9 bin still costs 15.8% less.
Where the tokens go
Mean composition of the tiered context at the last step of a session, in tokens:
| Exchanges | Background (L3) | Digest (L2.1) | Raw tail | Current message | Total |
|---|---|---|---|---|---|
| 1 | 156 | 0 | 0 | 81 | 237 |
| 2 | 63 | 0 | 573 | 26 | 662 |
| 3–5 | 84 | 171 | 2,175 | 60 | 2,490 |
| 6–9 | 73 | 810 | 2,395 | 49 | 3,327 |
| 10–19 | 108 | 890 | 2,268 | 35 | 3,301 |
| 20+ | 104 | 900 | 2,043 | 23 | 3,070 |
From six exchanges up, the tiered context is roughly flat at three thousand tokens however long the session grows. The digest is capped by its token budget at around nine hundred, the raw tail is always the latest three exchanges, and the background summary is bounded. Full history has no such ceiling: it grows with every exchange and is re-sent on every step. That is the whole mechanism, and why the saving concentrates where it does.
Two components are zero by construction. AAAK, Kemory's storage and export dialect, is never part of the default context — it is not a compression scheme for prompts, and no AAAK byte ratio is used as a token count anywhere in this study. Recalled memories are zero because a replay has no query to recall against; see the caveats for which way that cuts.
What it is worth
Every dollar figure here is a published-rate scenario: replayed token counts multiplied by list prices from a versioned rate card dated 22 July 2026. None of it is observed spend.
The compactor route
The identical compactor workload — 6.2M input and 1.7M output tokens — priced under each route:
| Route | Input / output per MTok | Cost |
|---|---|---|
Groq openai/gpt-oss-120b — Kemory's configured route | $0.15 / $0.60 | $1.97 |
Groq llama-3.3-70b-versatile | $0.59 / $0.79 | $5.03 |
OpenAI gpt-4o class | $2.50 / $10.00 | $32.89 |
Anthropic claude-sonnet-5 | $3.00 / $15.00 | $44.69 |
Anthropic claude-opus-4-8 — frontier reference | $5.00 / $25.00 | $74.48 |
This is a pricing comparison on a fixed workload. It claims nothing about whether the digests each model would write are equally good.
The net position
| Policy | Tokens | Cost |
|---|---|---|
| Full-history replay, frontier reader | 73.3M reader | $366.73 |
| Tiered context, frontier reader | 20.4M reader | $102.07 |
| Compactor, open-weight route | 7.9M compactor | $1.97 |
| Tiered total | 28.4M | $104.05 |
| Net saving | 45.0M (61.3%) | $262.69 (71.6%) |
Two things move this in opposite directions. The tokenizer proxy undercounts Anthropic tokens, so the frontier costs are a floor. And prompt caching is not modelled; real full-history spend with prefix caching is lower, so the net saving is a no-caching upper bound. Quote it as one.
What we compared
For every real session, both policies are replayed at every decision step — once per exchange — and the reader input each would send to a stateless API is summed across the session.
| Policy | What the reader receives at each step |
|---|---|
| Full-history replay | The system prompt, every prior exchange, and the current user message. |
| Tiered context — what Kemory sends today | The namespace and session background summary (L3), the rolling digest (L2.1) of every exchange older than the raw tail, the latest three exchanges verbatim, and the current user message. |
Summing across steps is the point. A stateless API is sent the whole context again on every turn, so full history costs grow roughly with the square of session length, and that is where compaction earns its keep.
How the replay works
The replay mirrors the service's own functions rather than approximating them. Exchanges are reconstructed with the same turn-pairing the backend uses; the tiered context is assembled as the session-context service formats it; and the rolling digest is folded in batches of three exchanges, exactly as the service refreshes it.
The digest is produced by Kemory's deterministic extractive path — the code the service runs when no AI backend is configured. That makes the replay reproducible and free of external calls. An LLM-written digest would differ in wording but is bounded by the same token budget, so the reader-side accounting is representative.
The compactor workload is the token count of the prompt the digest generator would be fed, plus the digest it produces, per batch. That workload is what section A prices under each route.
Token counts use tiktoken's o200k_base encoding as a documented proxy: the open-weight models Kemory routes to have no tiktoken mapping. No byte count is used as a token count anywhere.
Evidence classes
Three kinds of evidence are used, and they are never merged without a label.
| Class | What it covers |
|---|---|
| Observed | Only the counts of real sessions and turns. Kemory does not yet record compactor token usage, so nothing else here is observed. |
| Deterministic replay | Reader-input and compactor-workload token counts, recomputed from the real sessions with the real assembly policy. The strongest evidence on the page. |
| Published-rate scenario | Every dollar figure. Replayed tokens multiplied by list prices from a versioned, source-cited rate card. |
Privacy: the measurement reads conversation text into memory only to count it. Nothing it writes contains conversation text, personal data or credentials — only counts and salted pseudonyms — and it never writes to the database.
Caveats
Five things a careful reader should know before quoting any number on this page.
1. One account dominates the sample
This is the most important one. 1,227 of the 1,314 sessions belong to a single account, and so does every session longer than two exchanges. The other 23 accounts contribute 87 short sessions and about two thousand tokens between them. Since the saving lives in the long sessions, the headline describes one heavy user's working pattern, not a population of users.
The method does not depend on whose sessions they are, and the mechanism behind the result — a bounded context against an unbounded one — is general. But a different mix of session lengths gives a different aggregate, and a user whose sessions are mostly short would see tiered context cost them tokens. A multi-account re-run is the obvious next measurement.
2. Replay, not billing
Kemory does not currently persist what the compactor actually reads and writes: the provider's usage figures are discarded after each call, and no session digests were stored in the measured database. So the compactor numbers are a replayed workload, and every dollar figure is that workload at list price. The measurement package includes an analysis of the instrumentation that would turn the replay into an observation.
3. Bounds that cut both ways
| Limitation | Effect |
|---|---|
| The tokenizer is an OpenAI encoding; it undercounts Anthropic tokens by roughly 15–20% on prose, more on code | Frontier-reader costs are a floor |
| Prompt caching is not modelled; real full-history spend with prefix caching is lower | The net saving is an upper bound |
| Recalled memories are absent from the replay, which has no query to recall against | Tiered totals are a floor, so the token saving is an upper bound |
4. Tokens, not answers
This measures what is sent to the model. It does not measure whether the model answers as well from a digest as from the full transcript. A saving that degraded answers would not be a saving, and this study cannot rule that out. The routing comparison is likewise a pricing comparison only.
5. A live snapshot
The figures are a snapshot of all persisted chats. The code is deterministic over a fixed database — two back-to-back runs produce byte-identical outputs — but a background worker refreshes namespace summaries, so re-running against a live database moves the tiered and compactor totals by around 0.2%. Full-history counts do not move. For an exactly citable sample, pin a date window and run against a quiesced snapshot.
What we have not measured
| Answer quality | Not measured here — see caveat 4. |
| Observed compactor usage and latency | Not recorded by Kemory today; replayed instead. |
| Drill-down to raw sources | Rehydration is read-only and not instrumented, so how often the reader pulls raw exchanges back in, and how many tokens that adds, is unknown. |
| Prompt-cached pricing | The rate card records cache-read prices, but no cache-adjusted scenario has been run. |
| LLM-written digests | Replayed with the extractive digest; same budget, different wording. |
Reproduce it
The measurement package — the replay code, its unit tests, the rate card, the data dictionary, the instrumentation-gap analysis and the aggregate outputs behind every table on this page — is published in the Kemory Community Edition repository.
It reads the same chat tables Community Edition creates, so you can run it against your own local install and see what tiered context does with your sessions — which is a better answer to caveat 1 than anything we could publish.
cd benchmarks/context_compaction_empirical
pip install -r requirements.txt
export KEMORY_ANALYSIS_SALT="<any stable secret>"
# 1) unit tests — rate arithmetic, zero denominators, batching, the AAAK audit
python -m unittest discover -s tests -p 'test_*.py'
# 2) the measurement — writes out/*.csv and out/headline.json
python -m src.run_analysis --limit 0 --out out --tokenizer proxy
# 3) charts, then one self-contained HTML report
python charts/make_charts.py --out out
python build_report.py --out out --report kemory_compaction_report.html
The loader is strictly read-only and streams from Postgres through docker exec, so it needs no exposed port and no password; the package README has the exact invocation for a Community Edition stack. Content is held in memory only long enough to count it.
We publish the aggregate outputs. The per-session and per-step files stay private: they hold nothing but counts and salted pseudonyms, but together they would still show how one account uses the product. Run the package yourself and you get your own.
If you want this run on hosted Kemory against your own sessions, email hello@sekondbrain.ai. A measurement over your own work is worth more than one over ours.