supercompress package. The types fall into four groups: the compression result dataclasses (CompressResult, LineAnnotation), the sustainability estimation types (SustainabilityEstimate, SustainabilityAssumptions), and the eviction policy abstract base class and its built-in implementations. All of the dataclasses below are importable from supercompress without any sub-module path.
CompressResult
CompressResult is the return type of compress_context, compress_for_turn, and compare_policies. It is a standard Python dataclass with two computed properties.
str
The full input context string before any eviction. Stored verbatim so you can diff it against
compressed_text if needed.str
The eviction output — the subset of lines and tokens that survived the budget cut, ready to be sent directly to your LLM.
int
Number of tokens in
original_text as counted by the internal tokeniser.int
Number of tokens retained in
compressed_text after eviction.float
The
budget_ratio value used for this compression call.str
The user query passed to the compression call, stored here for downstream metrics and logging.
float
Fraction of source lines present in
compressed_text. This is typically higher than kept_tokens / original_tokens because attention-sink and recent-context lines are always retained regardless of the budget.str
Human-readable name of the eviction policy that ran. Common values:
"SuperCompress", "H2O-fallback", "FIFO", "Truncation", "H2O", "Summarization", "noop" (empty input).float
Computed property. Percentage of KV-cache entries eliminated:
(1 − kept_tokens / max(original_tokens, 1)) × 100. Uses max(original_tokens, 1) as a guard against division by zero when original_tokens is zero.float
Computed property. Ratio of original to kept tokens:
original_tokens / kept_tokens. Returns 0.0 when kept_tokens is zero.LineAnnotation
LineAnnotation is returned by compress_detailed as one element per source line. It explains the keep/drop decision at line granularity.
int
Zero-based index of this line in the original
text.str
The raw content of the line as it appeared in the input (no trailing newline).
bool
True if this line appears in the compressed output; False if it was evicted.str
One of five string literals explaining why this line was kept or dropped:
"attention sink (always kept)"— line index 0 or 1; always retained."recent context (always kept)"— one of the last 8 lines; always retained."question entity match"— line contains a named entity extracted fromquestion."learned retention score"— policy scored this line above the eviction threshold."evicted by policy"— line did not meet any retention criterion.
SustainabilityEstimate
SustainabilityEstimate is returned by sustainability_from_tokens_saved in supercompress.benchmarks.metrics. It translates a token savings figure into illustrative environmental impact numbers.
int
Number of tokens eliminated by compression (clamped to 0 if negative).
float
Estimated GPU-seconds avoided, derived from
tokens_saved × kv_share_of_prefill / tokens_per_gpu_second.float
Estimated watt-hours saved:
gpu_seconds_avoided × gpu_watts / 3600.float
Estimated kilograms of CO₂ avoided:
watt_hours_saved × grid_kg_co2_per_kwh / 1000.SustainabilityAssumptions
The
SustainabilityAssumptions dataclass used for this calculation (see below).SustainabilityAssumptions
SustainabilityAssumptions is a frozen dataclass that holds the constants used by sustainability_from_tokens_saved. All fields have documented defaults; override any of them by constructing a custom instance and passing it as the assumptions argument.
float
Assumed throughput of the GPU in tokens per second. Default:
2500.0.float
Assumed power draw of the GPU in watts. Default:
150.0.float
Carbon intensity of the electricity grid in kg CO₂ per kWh. Default:
0.417.Fraction of prefill compute attributed to KV-cache processing. Default:
0.55.SustainabilityAssumptions to sustainability_from_tokens_saved:
All sustainability figures are illustrative estimates based on the assumptions above — they are not measured values from your specific hardware or deployment environment. See the project’s
ENVIRONMENT.md for the full methodology.EvictionPolicy
EvictionPolicy is the abstract base class that all compression policies implement. It lives in supercompress.policies and defines a single abstract method.
select receives a list of TokenRecord objects (one per token in the input) and the integer token budget, and must return a list of token position indices to retain.
Built-in implementations
All of the following are importable fromsupercompress.policies: