Skip to main content

qdrant_client/builders/
quantization_search_params_builder.rs

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