compress_detailed performs the same learned compression as compress_context but additionally returns a LineAnnotation for every line in the original text. Each annotation records whether the line was kept, and the human-readable reason behind that decision — whether it was retained as an attention sink, matched a question entity, scored highly by the learned policy, or was evicted. Use compress_detailed when you need to understand exactly what the compressor is doing: building a visualisation, writing tests that assert retention behaviour, or demonstrating the system to stakeholders.
Function signature
Parameters
str
required
The full context string to compress. Split into lines internally; each line receives its own
LineAnnotation in the returned list.str
required
The current user query. Used to identify question entities for retention scoring and to populate the
"question entity match" reason in annotations.float
default:"0.35"
Fraction of tokens to retain, in
(0, 1]. Forwarded to the same eviction logic used by compress_context.EvictionPolicy
An explicit eviction policy that overrides the checkpoint-loaded learned policy. When
None, the default checkpoint is used with an automatic H2O fallback.str
Path to a trained weights file. Defaults to the bundled
checkpoints/default.pt. Only used when policy is None.Returns
Returns a two-element tuple.CompressResult
The full
CompressResult — identical to what compress_context would return for the same arguments.List[LineAnnotation]
A list of
LineAnnotation objects, one per line in the original text, in source order. Empty when text is blank.LineAnnotation fields
Each element of theannotations list is a LineAnnotation dataclass with the following fields:
int
Zero-based index of this line in the original text.
str
The raw content of the line as it appeared in the input.
bool
True if this line is present in result.compressed_text; False if it was evicted.str
A human-readable explanation for the keep/drop decision. Exactly one of the following values:
Example
When
text is empty or whitespace-only, compress_detailed delegates to compress_context internally and returns an empty annotations list []. No error is raised.