Skip to main content

Encoder

Trait Encoder 

Source
pub trait Encoder: Send + Sync {
    // Required methods
    fn compress(&self, input: &str, model: Model) -> Compressed;
    fn select_format(&self, input: &str, model: Model) -> Format;
    fn fallback(
        &self,
        input: &str,
        model: Model,
        reason: FallbackReason,
    ) -> Compressed;
}
Expand description

A pass-through encoder interface. Implementors MUST preserve semantic fidelity of the compressed output at or above the Phase-0 kill-switch threshold (≥0.90 cosine similarity under the target LLM’s response).

Required Methods§

Source

fn compress(&self, input: &str, model: Model) -> Compressed

Compress input for the target model. Must run in <5ms at p95. Returns Compressed even on fallback; format field reports what was used.

Source

fn select_format(&self, input: &str, model: Model) -> Format

Pick the best format for input without actually encoding. Used by A/B samplers and planners. Must match [compress]’s selection.

Source

fn fallback( &self, input: &str, model: Model, reason: FallbackReason, ) -> Compressed

Explicit fallback request — used when downstream quality monitor flags a previously-compressed payload.

Implementors§