qdrant_client/builders/
quantization_search_params_builder.rs

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