JDogo
Open playground

RAG context

Retrieved chunks arrive as lists of records with the same metadata keys. JDogo writes those keys once, so the same budget holds more context.

Measured

Benchmark caseJSONTOONJDogovs JSON
Sparse RAG chunks8361,064465−44%
RAG vector retrieval, top-K570611332−42%
RAG chunks with metadata (3 chunks)937974−20%

GPT-4 tokens (cl100k) for the JDogo document. The savings grow with the number of chunks: three chunks have little to share, twenty have a lot. TOON is larger than JSON on two of these because the metadata is nested or sparse.

How

from jdogo import compress_context

context = compress_context(retrieved_chunks)        # instruction + data, ready for the prompt
prompt = f"{context}\n\nQuestion: {question}"

The default layout is the one measured in live model runs: full ids and values, so the model can quote them back. Models read it about as accurately as JSON, for about half the tokens.

When it helps less

Paste your own retrieval results into the playground to see the saving column by column.