#[non_exhaustive]pub struct Answer {
pub value: AnswerValue,
pub probabilities: BTreeMap<String, f32>,
pub confidence: f32,
pub model: Option<String>,
}Expand description
One answer: the value decided, the probability mass per label, and the probability of the value that came back.
#[non_exhaustive], so an adapter builds one with Answer::new or
the three conveniences rather than a struct literal, and a field added
later is not a breaking change for every adapter.
Answer::confidence is not comparable across adapters — see
Calibration.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.value: AnswerValueThe value decided, matching the shape of the Question asked.
probabilities: BTreeMap<String, f32>Probability mass per label, keyed as Question::labels names
them. The port does not require the masses to sum to one: some
providers report only a top-1.
confidence: f32Probability of the label in value. See Calibration — not
comparable across adapters.
model: Option<String>The vendor-reported model version that produced this answer, when
the adapter knows it. An alias (jev-latest) can move under an
unchanged request, and a threshold was tuned against a specific
version’s numbers — the version that actually answered is how a
drifted answer is traced back to its cause. None when the adapter
does not know (or its port has no such report); set with
Answer::with_model.
Implementations§
Source§impl Answer
impl Answer
Sourcepub fn new(
value: AnswerValue,
probabilities: BTreeMap<String, f32>,
confidence: f32,
) -> Self
pub fn new( value: AnswerValue, probabilities: BTreeMap<String, f32>, confidence: f32, ) -> Self
An answer with the value, probabilities and confidence given. The
conveniences below are the usual way in: they pick confidence
out of probabilities themselves.
Sourcepub fn with_model(self, model: impl Into<String>) -> Self
pub fn with_model(self, model: impl Into<String>) -> Self
Records the vendor-reported model version that produced this
answer, for the adapters whose vendor reports one. Chainable on
any constructor:
Answer::noul(..).with_model("jev-1.13.0").
Sourcepub fn choice(
label: impl Into<String>,
probabilities: BTreeMap<String, f32>,
) -> Self
pub fn choice( label: impl Into<String>, probabilities: BTreeMap<String, f32>, ) -> Self
An answer to a Question::Choice: label is one of its
criteria, and confidence is looked up in probabilities under
it — 0.0 when the label is absent.
Sourcepub fn score(value: f32, probabilities: BTreeMap<String, f32>) -> Self
pub fn score(value: f32, probabilities: BTreeMap<String, f32>) -> Self
An answer to a Question::Score: value is on the scale, and
confidence is looked up in probabilities under the score’s own
name — the convention when a scale’s levels are named for their
scores ("1".."5"). A provider that reports confidence another
way builds the answer with Answer::new instead. 0.0 when the
label is absent.