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    #[allow(unused_mut)]
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    #[allow(unused_mut)]
34    pub fn rescore(self, value: bool) -> Self {
35        let mut new = self;
36        new.rescore = Option::Some(Option::Some(value));
37        new
38    }
39    ///
40    /// Oversampling factor for quantization.
41    ///
42    /// Defines how many extra vectors should be pre-selected using quantized index,
43    /// and then re-scored using original vectors.
44    ///
45    /// For example, if `oversampling` is 2.4 and `limit` is 100, then 240 vectors will be pre-selected using quantized index,
46    /// and then top-100 will be returned after re-scoring.
47    #[allow(unused_mut)]
48    pub fn oversampling(self, value: f64) -> Self {
49        let mut new = self;
50        new.oversampling = Option::Some(Option::Some(value));
51        new
52    }
53
54    fn build_inner(self) -> Result<QuantizationSearchParams, std::convert::Infallible> {
55        Ok(QuantizationSearchParams {
56            ignore: self.ignore.unwrap_or_default(),
57            rescore: self.rescore.unwrap_or_default(),
58            oversampling: self.oversampling.unwrap_or_default(),
59        })
60    }
61    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
62    fn create_empty() -> Self {
63        Self {
64            ignore: core::default::Default::default(),
65            rescore: core::default::Default::default(),
66            oversampling: core::default::Default::default(),
67        }
68    }
69}
70
71impl Default for QuantizationSearchParamsBuilder {
72    fn default() -> Self {
73        Self::create_empty()
74    }
75}
76
77impl From<QuantizationSearchParamsBuilder> for QuantizationSearchParams {
78    fn from(value: QuantizationSearchParamsBuilder) -> Self {
79        value.build_inner().unwrap_or_else(|_| {
80            panic!(
81                "Failed to convert {0} to {1}",
82                "QuantizationSearchParamsBuilder", "QuantizationSearchParams"
83            )
84        })
85    }
86}
87
88impl QuantizationSearchParamsBuilder {
89    /// Builds the desired type. Can often be omitted.
90    pub fn build(self) -> QuantizationSearchParams {
91        self.build_inner().unwrap_or_else(|_| {
92            panic!(
93                "Failed to build {0} into {1}",
94                "QuantizationSearchParamsBuilder", "QuantizationSearchParams"
95            )
96        })
97    }
98}