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§
Sourcefn compress(&self, input: &str, model: Model) -> Compressed
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.
Sourcefn select_format(&self, input: &str, model: Model) -> Format
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.
Sourcefn fallback(
&self,
input: &str,
model: Model,
reason: FallbackReason,
) -> Compressed
fn fallback( &self, input: &str, model: Model, reason: FallbackReason, ) -> Compressed
Explicit fallback request — used when downstream quality monitor flags a previously-compressed payload.