RAG context compression
Reduce RAG context without pretending retrieval is a summary problem.
RAG systems can retrieve more material than a model needs for one question. Tokz gives the application a way to select the source passages and structured records most relevant to that question while keeping the retained text tied to its source.
const result = await tokz.compress(retrievedDocument, {
query: "Which policy applies to this incident?",
targetRatio: 0.45,
});Retrieve broadly, send deliberately
Retrieval recall and context selection are different jobs. A system can retain enough candidate documents for coverage, then select the passages that answer the active request rather than asking a model to read every retrieved page.
Provenance matters for prose
Prose takes the semantic path: selected source sentences are returned with a provenance map. This is extractive and checkable, but it is not the structural offsets-only response used for JSON and similar inputs.
Protect the context you cannot drop
Use preserve controls for identifiers and application-required spans. A compression ratio is a budget, not a substitute for a data contract.
Limitations
Selection does not correct stale retrieval, resolve contradictory source documents, or verify a model citation. Keep retrieval quality and answer evaluation as separate measurements.