qdrant_client/builders/rrf_builder.rs
1use crate::qdrant::Rrf;
2
3#[derive(Clone)]
4pub struct RrfBuilder {
5 /// K parameter for reciprocal rank fusion.
6 ///
7 /// Controls how quickly the weights decrease as rank increases.
8 /// Higher values make the weighting more uniform across ranks.
9 ///
10 /// Default value is 60.
11 pub(crate) k: Option<Option<u32>>,
12 /// Weights for each prefetch source.
13 /// Higher weight gives more influence on the final ranking.
14 /// If not specified, all prefetches are weighted equally.
15 pub(crate) weights: Option<Vec<f32>>,
16}
17
18impl RrfBuilder {
19 /// Create a new RrfBuilder with default values.
20 ///
21 /// # Examples
22 ///
23 /// ```
24 /// use qdrant_client::qdrant::RrfBuilder;
25 ///
26 /// let rrf = RrfBuilder::new().build();
27 /// ```
28 pub fn new() -> Self {
29 Self::create_empty()
30 }
31
32 /// Create a new RrfBuilder with a specific k parameter.
33 ///
34 /// # Arguments
35 ///
36 /// * `k` - K parameter for reciprocal rank fusion. Default is 60.
37 ///
38 /// # Examples
39 ///
40 /// ```
41 /// use qdrant_client::qdrant::RrfBuilder;
42 ///
43 /// let rrf = RrfBuilder::with_k(100).build();
44 /// ```
45 pub fn with_k(k: u32) -> Self {
46 Self::new().k(k)
47 }
48
49 /// Set the K parameter for reciprocal rank fusion.
50 ///
51 /// Controls how quickly the weights decrease as rank increases.
52 /// Higher values make the weighting more uniform across ranks.
53 ///
54 /// Default value is 60.
55 pub fn k(self, value: u32) -> Self {
56 let mut new = self;
57 new.k = Option::Some(Option::Some(value));
58 new
59 }
60
61 /// Weights for each prefetch source.
62 /// Higher weight gives more influence on the final ranking.
63 /// If not specified, all prefetches are weighted equally.
64 pub fn weights(self, value: Vec<f32>) -> Self {
65 let mut new = self;
66 new.weights = Option::Some(value);
67 new
68 }
69
70 pub fn build(self) -> Rrf {
71 Rrf {
72 k: self.k.unwrap_or_default(),
73 weights: self.weights.unwrap_or_default(),
74 }
75 }
76
77 /// Create an empty builder, with all fields set to `None`.
78 fn create_empty() -> Self {
79 Self {
80 k: core::default::Default::default(),
81 weights: core::default::Default::default(),
82 }
83 }
84}
85
86impl From<RrfBuilder> for Rrf {
87 fn from(value: RrfBuilder) -> Self {
88 value.build()
89 }
90}
91
92impl Default for RrfBuilder {
93 fn default() -> Self {
94 Self::create_empty()
95 }
96}