pub trait Objective<T>: Send + Sync {
// Required method
fn score(&self, candidate: &T, context: &ObjectiveContext) -> f64;
// Provided methods
fn precision(&self, _candidate: &T, _context: &ObjectiveContext) -> f64 { ... }
fn passes_score(&self, score: f64, context: &ObjectiveContext) -> bool { ... }
fn passes(&self, candidate: &T, context: &ObjectiveContext) -> bool { ... }
fn batch_score(
&self,
candidates: &[T],
context: &ObjectiveContext,
) -> Vec<(usize, f64)> { ... }
fn select<'a>(
&self,
candidates: &'a [T],
context: &ObjectiveContext,
) -> ObjectiveResult<Selection<&'a T>> { ... }
fn select_top<'a>(
&self,
candidates: &'a [T],
n: usize,
context: &ObjectiveContext,
) -> Vec<Selection<&'a T>> { ... }
fn name(&self) -> &str { ... }
}Expand description
Trait for objective functions that select from candidates.
An objective function is a measurement operator that collapses a space of possibilities into a single selection. Objectives are deterministic, composable, and introspectable.
Required Methods§
Sourcefn score(&self, candidate: &T, context: &ObjectiveContext) -> f64
fn score(&self, candidate: &T, context: &ObjectiveContext) -> f64
Evaluate a single candidate.
Provided Methods§
Sourcefn precision(&self, _candidate: &T, _context: &ObjectiveContext) -> f64
fn precision(&self, _candidate: &T, _context: &ObjectiveContext) -> f64
Precision (inverse variance) estimate for the score of a candidate.
Default is 1.0 (fully trusted). Override when score reliability varies
across candidates — e.g., an embedding model that returns a confidence
alongside the similarity score. The effective ranking value used by the
default select / select_top implementations is score * precision
(ADR-059, Predictive Coding).
When overriding, return values in (0, 1]. Non-finite values are treated as 1.0 by the default implementations.
Sourcefn passes_score(&self, score: f64, context: &ObjectiveContext) -> bool
fn passes_score(&self, score: f64, context: &ObjectiveContext) -> bool
Check if a score passes the threshold.
Non-finite scores never pass.
Sourcefn passes(&self, candidate: &T, context: &ObjectiveContext) -> bool
fn passes(&self, candidate: &T, context: &ObjectiveContext) -> bool
Check if a candidate passes the threshold.
Sourcefn batch_score(
&self,
candidates: &[T],
context: &ObjectiveContext,
) -> Vec<(usize, f64)>
fn batch_score( &self, candidates: &[T], context: &ObjectiveContext, ) -> Vec<(usize, f64)>
Score a batch of candidates and return the passing (index, score) pairs.
The default implementation is a scalar fallback. Objectives with SIMD-friendly layouts can override this hook for higher throughput.
Sourcefn select<'a>(
&self,
candidates: &'a [T],
context: &ObjectiveContext,
) -> ObjectiveResult<Selection<&'a T>>
fn select<'a>( &self, candidates: &'a [T], context: &ObjectiveContext, ) -> ObjectiveResult<Selection<&'a T>>
Select the best candidate from a list.
Ranking uses score * precision so that unreliable high-scores do not
dominate over lower-scoring but precise candidates (ADR-059). When all
precisions are 1.0 (the default), ranking is identical to raw score order.
Sourcefn select_top<'a>(
&self,
candidates: &'a [T],
n: usize,
context: &ObjectiveContext,
) -> Vec<Selection<&'a T>>
fn select_top<'a>( &self, candidates: &'a [T], n: usize, context: &ObjectiveContext, ) -> Vec<Selection<&'a T>>
Select the top N candidates.
Ranking uses score * precision (ADR-059). Small n (≤96) uses a sorted
small-vector path with binary-search insertion. Large n uses a worst-first heap.
Implementors§
impl<T, F> Objective<T> for F
Implement Objective for closures.