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
//! # rankfusion
//!
//! Backend-agnostic rank aggregation, score fusion, and reranking.
//!
//! This library is **not** a search engine. It does not perform retrieval and
//! knows nothing about ANN, BM25, embeddings, databases, or storage. Its only
//! responsibility: given multiple ranked candidate lists produced by external
//! systems, combine them into a single optimized ranking using configurable
//! fusion and reranking strategies.
//!
//! ```text
//! External sources ──▶ RankedList / ScoredList ──▶ fusion ──▶ reranking ──▶ Vec<Scored>
//! ```
//!
//! ## Data model
//!
//! Rank-based inputs and score-based inputs are distinct types — see the
//! [`core`] module docs for the full design rationale (score
//! status, metadata merge policy, NaN policy):
//!
//! - [`RankedList`]: ordered candidates, rank implicit — feeds rank fusion (RRF).
//! - [`ScoredList`]: ordered + uniformly scored — feeds score fusion; converts
//! to [`RankedList`] for free.
//! - Fusion always outputs [`Scored`] candidates: a fused score always exists.
//!
//! ## Example
//!
//! ```
//! use rankfusion::{Pipeline, RankedList, Rrf, Scored, TopK};
//!
//! // ranked lists from two external systems (vector search, keyword search…)
//! let list_a: RankedList<&str> = ["a", "b", "c"].into_iter().collect();
//! let list_b: RankedList<&str> = ["b", "d", "a"].into_iter().collect();
//!
//! let freshness_boost = |candidates: &mut Vec<Scored<&str, ()>>| {
//! for c in candidates.iter_mut() {
//! if *c.id() == "d" {
//! c.score *= 1.5;
//! }
//! }
//! candidates.sort_by(Scored::cmp_score_desc);
//! };
//!
//! let results = Pipeline::new(Rrf::default())
//! .reranker(freshness_boost)
//! .reranker(TopK::new(3))
//! .rank(vec![list_a, list_b])
//! .unwrap();
//!
//! assert_eq!(results.len(), 3);
//! assert_eq!(*results[0].id(), "b");
//! ```
//!
//! ## Feature flags
//!
//! - `ahash` — faster hashing for the fusion accumulators.
//! - `eval` — ranking-quality metrics (`ndcg@k`, MRR, `recall@k`), zero extra
//! dependencies.
//! - `serde` — `Serialize`/`Deserialize` on the core data model and
//! explainability types.
pub use crate;
pub use crate;
pub use crate;
pub use crate;
pub use crate;