1mod compose;
31mod context;
32mod error;
33mod fold;
34mod result;
35
36pub mod checkpoint;
39
40pub use compose::{filter, map, DualFold, FilterFold, MapFold, SequentialFold};
41pub use context::{FoldContext, SharedJson};
42pub use error::{FoldError, FoldResult, FoldResult as FoldResultType};
43pub use fold::{
44 fold_fn, AnyFold, BoxedFold, CommonFold, CommonFoldState, CountFold, FilterCountFold, FnFold,
45 Fold, FoldFailure, SumI64Fold, TryFold,
46};
47pub use result::FoldOutcome;
48
49pub use checkpoint::{Checkpoint, CheckpointStore, InMemoryCheckpointStore};
52
53pub mod anchor;
56
57pub use anchor::{Anchor, AnchorGraph, AnchorRef, BfsAnchor};
58
59pub mod selector;
62
63pub use selector::{GreedySelector, Selector, SelectorInput, SelectorOutput, SelectorWeights};
64
65pub mod objective;
68pub mod ordering;
69
70pub use khive_score::{cmp_asc_then_id, cmp_desc_then_id, DeterministicScore};
71pub use objective::builtin::{
72 FirstMatchObjective, HasImportance, HasTimestamp, ImportanceObjective, MaxScoreObjective,
73 RecencyObjective, RelevanceObjective, ThresholdObjective,
74};
75pub use objective::compose::{
76 ConsensusObjective, NegateObjective, PriorityObjective, ScaleObjective, UnionObjective,
77 WeightedObjective,
78};
79pub use objective::error::{ObjectiveError, ObjectiveResult};
80pub use objective::{objective_fn, DeterministicObjective, Objective, ObjectiveContext, Selection};
81pub use ordering::{
82 canonical_f32, canonical_f64, cmp_asc_score_then_id, cmp_desc_score_then_id, HasId, Ranked,
83 ScoredEntry,
84};
85
86pub struct ComposePipeline<T> {
90 pub anchor: Box<dyn Anchor>,
91 pub objective: Box<dyn Objective<T>>,
92 pub selector: Box<dyn Selector<T>>,
93}
94
95impl<T: Clone + Send + Sync + 'static> ComposePipeline<T> {
96 pub fn execute(
98 &self,
99 _graph: &AnchorGraph,
100 candidates: Vec<SelectorInput<T>>,
101 budget: usize,
102 weights: &SelectorWeights,
103 context: &ObjectiveContext,
104 ) -> Result<SelectorOutput<T>, FoldError> {
105 let scored = candidates
106 .into_iter()
107 .map(|mut candidate| {
108 candidate.score = self.objective.score(&candidate.content, context) as f32;
109 candidate
110 })
111 .collect();
112 self.selector.select(scored, budget, weights)
113 }
114}