Engineering · AI · Performance

Compressing Files So File Chat Uses 92% Fewer Tokens

4 min read

How File Chat stopped sending the whole textbook every time someone asked a question.


Picture a student who uploads a 100-page textbook to File Chat, the part of Cereby that answers questions about uploaded study materials, and asks it to "explain the chain rule in chapter 5". In the first version, they got a correct answer, and this:

Sent in full, a 100-page textbook cost about 150,000 tokens per question. Documents over roughly 85 pages hit the model's context limit and failed outright, and on any given question, 80 to 90% of the pages we sent had nothing to do with what was asked. This was not a model problem. It was an input problem.

This is part 1 of our series on fitting large files into a question; part 2 is Trimming Huge Pages Without Cutting Out the Answer. This one describes hierarchical context compression: work done once per page at upload, so that each question sends only the pages it needs.

Send what the question needs, not the first N pages

At upload, each page gets an AI-written summary of three to five sentences, its keywords and topics, token counts for the page and the summary, and a baseline importance score from its position, length and keyword density. That runs once and costs roughly $0.01 to $0.02 for a 100-page document. Each question then scores every page and treats it one of three ways:

A note in the context lists the page ranges that were left out, so the model knows what it did not see. A document with no metadata (an older upload, or one whose processing failed) falls back to simple truncation rather than an error.

Before and after

BeforeAfter
Tokens per question150,0005,000 to 8,000 (92% fewer)
Cost per question$1.50 to $2.00$0.05 to $0.10 (93% less)
Response time15 to 20 seconds2 to 3 seconds (85% faster)
Largest documentabout 85 pages500+ pages (6x)
Preprocessing, 100 pagesnoneabout $0.01 to $0.02, once

Accuracy held. Against full-context answers across representative questions, the compressed version scored 4.6 out of 5 overall against 4.7, and relevance went up, 4.7 against 4.5, because the model was no longer reading noise. Completeness dipped slightly when compression left out a page that would have added peripheral context. At these costs and speeds, we took that trade.

What this taught us

Preprocessing pays for itself on the first question: a cent or two per 100 pages, once.

Simple heuristics are enough for structured academic content. We considered heavier language models for keyword and relevance scoring, but frequency analysis and pattern matching worked well enough that the complexity was not justified.

Three tiers was the right number. Two (full or left out) and four (adding a partial-page tier) both balanced coverage against tokens worse.

Summaries have to be dense. Early ones from looser prompts were too vague to help the scoring; tighter instructions with specific output requirements improved both the scores and the context.

All engineering posts