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
//! Fusion algorithms for combining retrieval results.
//!
//! This module implements rank fusion strategies for hybrid search, combining
//! results from multiple retrieval sources (e.g., vector search, keyword search).
//!
//! # Supported Strategies
//!
//! - **RRF (Reciprocal Rank Fusion)**: Default and recommended. Uses only ranks,
//! making it robust to score distribution differences.
//! - **Weighted**: Linear combination of scores with configurable weights.
//! - **Union**: Takes the maximum score per ID across sources.
//!
//! # Algorithm
//!
//! RRF formula:
//! ```text
//! score(d) = Σ 1/(k + rank_i(d))
//! ```
//! where:
//! - k = 60 (standard, dampens high-rank dominance)
//! - rank_i(d) = position of d in retriever i's results (1-indexed)
//! - If d not in retriever i, contribution = 0
//!
//! # Example
//!
//! ```rust
//! use khive_fusion::{fuse, FusionStrategy, reciprocal_rank_fusion};
//! use khive_score::DeterministicScore;
//!
//! // Two retrieval sources with different rankings
//! let vector_results = vec![
//! ("doc_a", DeterministicScore::from_f64(0.95)),
//! ("doc_b", DeterministicScore::from_f64(0.90)),
//! ("doc_c", DeterministicScore::from_f64(0.85)),
//! ];
//!
//! let keyword_results = vec![
//! ("doc_b", DeterministicScore::from_f64(0.88)),
//! ("doc_c", DeterministicScore::from_f64(0.75)),
//! ("doc_d", DeterministicScore::from_f64(0.70)),
//! ];
//!
//! // Fuse using RRF with k=60
//! let fused = fuse(
//! vec![vector_results, keyword_results],
//! &FusionStrategy::Rrf { k: 60 },
//! 5,
//! );
//!
//! // doc_b appears in both sources, so it gets highest RRF score
//! assert_eq!(fused[0].0, "doc_b");
//! ```
// Re-export public types and functions
pub use fuse;
pub use reciprocal_rank_fusion;
pub use ;
pub use union_fusion;
pub use ;