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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use crate::qdrant::Rrf;
#[derive(Clone)]
pub struct RrfBuilder {
/// K parameter for reciprocal rank fusion.
///
/// Controls how quickly the weights decrease as rank increases.
/// Higher values make the weighting more uniform across ranks.
///
/// Default value is 60.
pub(crate) k: Option<Option<u32>>,
/// Weights for each prefetch source.
/// Higher weight gives more influence on the final ranking.
/// If not specified, all prefetches are weighted equally.
pub(crate) weights: Option<Vec<f32>>,
}
impl RrfBuilder {
/// Create a new RrfBuilder with default values.
///
/// # Examples
///
/// ```
/// use qdrant_client::qdrant::RrfBuilder;
///
/// let rrf = RrfBuilder::new().build();
/// ```
pub fn new() -> Self {
Self::create_empty()
}
/// Create a new RrfBuilder with a specific k parameter.
///
/// # Arguments
///
/// * `k` - K parameter for reciprocal rank fusion. Default is 60.
///
/// # Examples
///
/// ```
/// use qdrant_client::qdrant::RrfBuilder;
///
/// let rrf = RrfBuilder::with_k(100).build();
/// ```
pub fn with_k(k: u32) -> Self {
Self::new().k(k)
}
/// Set the K parameter for reciprocal rank fusion.
///
/// Controls how quickly the weights decrease as rank increases.
/// Higher values make the weighting more uniform across ranks.
///
/// Default value is 60.
pub fn k(self, value: u32) -> Self {
let mut new = self;
new.k = Option::Some(Option::Some(value));
new
}
/// Weights for each prefetch source.
/// Higher weight gives more influence on the final ranking.
/// If not specified, all prefetches are weighted equally.
pub fn weights(self, value: Vec<f32>) -> Self {
let mut new = self;
new.weights = Option::Some(value);
new
}
pub fn build(self) -> Rrf {
Rrf {
k: self.k.unwrap_or_default(),
weights: self.weights.unwrap_or_default(),
}
}
/// Create an empty builder, with all fields set to `None`.
fn create_empty() -> Self {
Self {
k: core::default::Default::default(),
weights: core::default::Default::default(),
}
}
}
impl From<RrfBuilder> for Rrf {
fn from(value: RrfBuilder) -> Self {
value.build()
}
}
impl Default for RrfBuilder {
fn default() -> Self {
Self::create_empty()
}
}