TOON for RAG & context windows

Retrieval-augmented generation lives inside a fixed budget: the context window. Every retrieved record you add costs tokens, and tokens cost money and, eventually, room. When the records you retrieve are structured — rows, entities, tables — serializing them as JSON spends a large part of that budget on repeated field names and punctuation. Converting them to TOON buys back the room.

The context-window squeeze

More retrieved documents mean better recall but a bigger, pricier prompt — and past a point, truncation. If each record is a JSON object with the same keys repeated, you are paying to send those keys once per record. That is budget you could have spent on more records, or simply saved.

TOON for the retrieved block

When your retrieved chunk is a uniform set of records, TOON declares the fields once and streams the rows:

results[3]{title,year,score}:
  Retrieval-Augmented Generation,2020,0.94
  Dense Passage Retrieval,2020,0.91
  In-Context Learning,2022,0.88

The same three records as pretty-printed JSON cost noticeably more tokens. Across a context block of dozens of records, that difference is the number of records you can fit — or the cost of every single query, multiplied by your traffic.

What to convert, and what not to

  • Convert: tables of records, entity lists, structured metadata with shared fields.
  • Leave as text: prose passages, document excerpts, anything free-form.

TOON compresses structure, not language. A retrieved paragraph has no repeated keys to remove, so keep it as plain text and reserve the conversion for the tabular parts of your context.

Where it slots in

Keep your vector store, chunks and application code on JSON. Convert to TOON only at prompt assembly, the same place you already format the context block. Everything about retrieval stays the same; only the serialization of the final block changes. See TOON for LLM prompts for the general pattern and TOON vs JSON for the trade-offs.

Size the saving

Take one representative retrieved block, paste it into the converter, and read the token receipt. That number, multiplied by your query volume, is your monthly saving — measured, not estimated, and computed entirely in your browser.