qdrant_client/builders/
quantization_search_params_builder.rs

1use crate::qdrant::*;
2
3pub struct QuantizationSearchParamsBuilder {
4    ///
5    /// If set to true, search will ignore quantized vector data
6    pub(crate) ignore: Option<Option<bool>>,
7    ///
8    /// If true, use original vectors to re-score top-k results. If ignored, qdrant decides automatically does rescore enabled or not.
9    pub(crate) rescore: Option<Option<bool>>,
10    ///
11    /// Oversampling factor for quantization.
12    ///
13    /// Defines how many extra vectors should be pre-selected using quantized index,
14    /// and then re-scored using original vectors.
15    ///
16    /// For example, if `oversampling` is 2.4 and `limit` is 100, then 240 vectors will be pre-selected using quantized index,
17    /// and then top-100 will be returned after re-scoring.
18    pub(crate) oversampling: Option<Option<f64>>,
19}
20
21impl QuantizationSearchParamsBuilder {
22    ///
23    /// If set to true, search will ignore quantized vector data
24    #[allow(unused_mut)]
25    pub fn ignore(self, value: bool) -> Self {
26        let mut new = self;
27        new.ignore = Option::Some(Option::Some(value));
28        new
29    }
30    ///
31    /// If true, use original vectors to re-score top-k results. If ignored, qdrant decides automatically does rescore enabled or not.
32    #[allow(unused_mut)]
33    pub fn rescore(self, value: bool) -> Self {
34        let mut new = self;
35        new.rescore = Option::Some(Option::Some(value));
36        new
37    }
38    ///
39    /// Oversampling factor for quantization.
40    ///
41    /// Defines how many extra vectors should be pre-selected using quantized index,
42    /// and then re-scored using original vectors.
43    ///
44    /// For example, if `oversampling` is 2.4 and `limit` is 100, then 240 vectors will be pre-selected using quantized index,
45    /// and then top-100 will be returned after re-scoring.
46    #[allow(unused_mut)]
47    pub fn oversampling(self, value: f64) -> Self {
48        let mut new = self;
49        new.oversampling = Option::Some(Option::Some(value));
50        new
51    }
52
53    fn build_inner(self) -> Result<QuantizationSearchParams, std::convert::Infallible> {
54        Ok(QuantizationSearchParams {
55            ignore: self.ignore.unwrap_or_default(),
56            rescore: self.rescore.unwrap_or_default(),
57            oversampling: self.oversampling.unwrap_or_default(),
58        })
59    }
60    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
61    fn create_empty() -> Self {
62        Self {
63            ignore: core::default::Default::default(),
64            rescore: core::default::Default::default(),
65            oversampling: core::default::Default::default(),
66        }
67    }
68}
69
70impl Default for QuantizationSearchParamsBuilder {
71    fn default() -> Self {
72        Self::create_empty()
73    }
74}
75
76impl From<QuantizationSearchParamsBuilder> for QuantizationSearchParams {
77    fn from(value: QuantizationSearchParamsBuilder) -> Self {
78        value.build_inner().unwrap_or_else(|_| {
79            panic!(
80                "Failed to convert {0} to {1}",
81                "QuantizationSearchParamsBuilder", "QuantizationSearchParams"
82            )
83        })
84    }
85}
86
87impl QuantizationSearchParamsBuilder {
88    /// Builds the desired type. Can often be omitted.
89    pub fn build(self) -> QuantizationSearchParams {
90        self.build_inner().unwrap_or_else(|_| {
91            panic!(
92                "Failed to build {0} into {1}",
93                "QuantizationSearchParamsBuilder", "QuantizationSearchParams"
94            )
95        })
96    }
97}