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}
13
14impl RrfBuilder {
15 /// Create a new RrfBuilder with default values.
16 ///
17 /// # Examples
18 ///
19 /// ```
20 /// use qdrant_client::qdrant::RrfBuilder;
21 ///
22 /// let rrf = RrfBuilder::new().build();
23 /// ```
24 pub fn new() -> Self {
25 Self::create_empty()
26 }
27
28 /// Create a new RrfBuilder with a specific k parameter.
29 ///
30 /// # Arguments
31 ///
32 /// * `k` - K parameter for reciprocal rank fusion. Default is 60.
33 ///
34 /// # Examples
35 ///
36 /// ```
37 /// use qdrant_client::qdrant::RrfBuilder;
38 ///
39 /// let rrf = RrfBuilder::with_k(100).build();
40 /// ```
41 pub fn with_k(k: u32) -> Self {
42 Self::new().k(k)
43 }
44
45 /// Set the K parameter for reciprocal rank fusion.
46 ///
47 /// Controls how quickly the weights decrease as rank increases.
48 /// Higher values make the weighting more uniform across ranks.
49 ///
50 /// Default value is 60.
51 pub fn k(self, value: u32) -> Self {
52 let mut new = self;
53 new.k = Option::Some(Option::Some(value));
54 new
55 }
56
57 pub fn build(self) -> Rrf {
58 Rrf {
59 k: self.k.unwrap_or_default(),
60 }
61 }
62
63 /// Create an empty builder, with all fields set to `None`.
64 fn create_empty() -> Self {
65 Self {
66 k: core::default::Default::default(),
67 }
68 }
69}
70
71impl From<RrfBuilder> for Rrf {
72 fn from(value: RrfBuilder) -> Self {
73 value.build()
74 }
75}
76
77impl Default for RrfBuilder {
78 fn default() -> Self {
79 Self::create_empty()
80 }
81}