1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Post-fusion reranking: composable, synchronous, in-place stages.
//!
//! A [`Reranker`] mutates the fused candidate vector — boosting, filtering,
//! truncating, re-ordering. Stages run in declaration order inside a
//! [`Pipeline`]. The trait is deliberately synchronous: rerankers are CPU
//! operations; async systems (remote ML rerankers, APIs) adapt *outside* the
//! core by materializing their result before or after the pipeline.
//!
//! Stages own the output order: a stage that changes scores is responsible
//! for re-sorting if it wants score order restored (see the closure example
//! on [`Reranker`]).
pub use Pipeline;
use crateScored;
/// A post-fusion stage that mutates the ranked candidates in place.
///
/// The receiver is `&mut Vec` (not `&mut [_]`) so stages may filter and
/// truncate, not just reorder. Any `Fn(&mut Vec<Scored<Id, M>>)` closure is a
/// reranker — no struct needed for one-liners:
///
/// ```
/// use rankfusion::{Pipeline, RankedList, Rrf, Scored};
///
/// let boost_doc_b = |candidates: &mut Vec<Scored<&str, ()>>| {
/// for c in candidates.iter_mut() {
/// if *c.id() == "b" {
/// c.score *= 2.0;
/// }
/// }
/// candidates.sort_by(Scored::cmp_score_desc);
/// };
///
/// let list: RankedList<&str> = ["a", "b"].into_iter().collect();
/// let fused = Pipeline::new(Rrf::default())
/// .reranker(boost_doc_b)
/// .rank(vec![list])
/// .unwrap();
/// assert_eq!(*fused[0].id(), "b");
/// ```
/// Keep only the top `k` candidates (in current order).
///
/// The canonical truncating stage — final result sizing belongs at the end of
/// a pipeline, after boosts have settled the order.