Skip to main content

Classifier

Trait Classifier 

Source
pub trait Classifier: Send + Sync {
    // Required methods
    fn profile(&self) -> ClassifierProfile;
    fn ask<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        state: &'life1 str,
        questions: &'life2 BTreeMap<String, Question>,
    ) -> Pin<Box<dyn Future<Output = Result<BTreeMap<String, Answer>, ClassifierError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
}
Expand description

Answers a set of typed questions about a state, over whichever classifier the venture wired. The sibling of TextModel: a module asks “which of these is it, and how sure are you” and holds Arc<dyn Classifier> without learning who answered.

§Confidence is per-adapter

Answer::confidence is not comparable across adapters. It comes from the family ClassifierProfile::calibration names, and a 0.8 from one family is not a 0.8 from the other — see Calibration. A module that thresholds on it must say in its own docs that the threshold is per-adapter: swapping the adapter re-tunes every threshold downstream of it.

§state is truncated by the adapter

When state is longer than ClassifierProfile::max_state_chars the adapter truncates it — deterministically, on a char boundary, with a log line. It has to be the adapter that does it: only the adapter knows its provider’s budget. A silently trimmed state is the worst failure mode a classifier has, because the answer comes back confident and wrong.

Required Methods§

Source

fn profile(&self) -> ClassifierProfile

What family of numbers this adapter’s confidence comes from, and how much state it will carry.

Source

fn ask<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, state: &'life1 str, questions: &'life2 BTreeMap<String, Question>, ) -> Pin<Box<dyn Future<Output = Result<BTreeMap<String, Answer>, ClassifierError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Answers every question in questions about state, keyed the same way.

questions is a set, not a loop: the provider evaluates the questions of one call against one state in parallel, and the expensive part is carrying the state, not answering. An adapter validates the set with validate_questions and answers ClassifierError::Rejected rather than panicking on a malformed one.

§Errors

ClassifierError::NotConfigured when no adapter is wired; ClassifierError::Rejected when the provider or validate_questions refused the request; ClassifierError::Transient when the call is retryable, with the provider’s back-off where it named one; ClassifierError::Transport when the call never completed as a decision.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§