x-pipe-rs
Composable recommendation and feed pipeline framework built on comp-cat-rs.
Inspired by the X algorithm's candidate-pipeline architecture, generalized into a typed, reusable framework where every pipeline stage is a Kleisli arrow in the Io monad.
Architecture
A pipeline assembles six kinds of stages:
- Source -- produce candidate items from backends
- Hydrator -- enrich candidates with additional data
- Filter -- remove candidates that fail criteria
- Scorer -- assign relevance scores
- Selector -- choose final candidates (dedup, diversity, budget)
- SideEffect -- observe without modifying (logging, metrics)
Each trait converts to a Stage<E, A, B>, the universal Kleisli arrow type. Stages compose via Stage::then (Kleisli composition). The final Pipeline is itself a single Stage from query to scored results.
Categorical justification
Stage forms a category whose morphisms are Kleisli arrows A -> Io<E, B>. Composition is associative with identity, and by comp-cat-rs's collapse::monad_is_kan, every such composition is a pair of Kan extensions. Score implements JoinSemilattice, making score merging a colimit (left Kan extension).
Quick start
use Io;
use Pipeline;
use Score;
use Scorer;
use ;
use Source;
;
;
let pipeline = from_source
.score
.select;
// Pipeline returns a lazy Io; call .run() only at the boundary.
let results = pipeline.execute.run;
Running the example
License
MIT OR Apache-2.0