qdrant_client/builders/
vector_params_diff_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4pub struct VectorParamsDiffBuilder {
5    /// Update params for HNSW index. If empty object - it will be unset
6    pub(crate) hnsw_config: Option<Option<HnswConfigDiff>>,
7    /// Update quantization params. If none - it is left unchanged.
8    quantization_config: Option<quantization_config_diff::Quantization>,
9    /// If true - serve vectors from disk. If set to false, the vectors will be loaded in RAM.
10    pub(crate) on_disk: Option<Option<bool>>,
11}
12
13impl VectorParamsDiffBuilder {
14    /// Update params for HNSW index. If empty object - it will be unset
15    #[allow(unused_mut)]
16    pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
17        let mut new = self;
18        new.hnsw_config = Option::Some(Option::Some(value.into()));
19        new
20    }
21    /// Update quantization params. If none - it is left unchanged.
22    #[allow(unused_mut)]
23    pub fn quantization_config<
24        VALUE: core::convert::Into<quantization_config_diff::Quantization>,
25    >(
26        self,
27        value: VALUE,
28    ) -> Self {
29        let mut new = self;
30        new.quantization_config = Option::Some(value.into());
31        new
32    }
33    /// If true - serve vectors from disk. If set to false, the vectors will be loaded in RAM.
34    #[allow(unused_mut)]
35    pub fn on_disk(self, value: bool) -> Self {
36        let mut new = self;
37        new.on_disk = Option::Some(Option::Some(value));
38        new
39    }
40
41    fn build_inner(self) -> Result<VectorParamsDiff, std::convert::Infallible> {
42        Ok(VectorParamsDiff {
43            hnsw_config: self.hnsw_config.unwrap_or_default(),
44            quantization_config: { convert_option(&self.quantization_config) },
45            on_disk: self.on_disk.unwrap_or_default(),
46        })
47    }
48    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
49    fn create_empty() -> Self {
50        Self {
51            hnsw_config: core::default::Default::default(),
52            quantization_config: core::default::Default::default(),
53            on_disk: core::default::Default::default(),
54        }
55    }
56}
57
58impl Default for VectorParamsDiffBuilder {
59    fn default() -> Self {
60        Self::create_empty()
61    }
62}
63
64impl From<VectorParamsDiffBuilder> for VectorParamsDiff {
65    fn from(value: VectorParamsDiffBuilder) -> Self {
66        value.build_inner().unwrap_or_else(|_| {
67            panic!(
68                "Failed to convert {0} to {1}",
69                "VectorParamsDiffBuilder", "VectorParamsDiff"
70            )
71        })
72    }
73}
74
75impl VectorParamsDiffBuilder {
76    /// Builds the desired type. Can often be omitted.
77    pub fn build(self) -> VectorParamsDiff {
78        self.build_inner().unwrap_or_else(|_| {
79            panic!(
80                "Failed to build {0} into {1}",
81                "VectorParamsDiffBuilder", "VectorParamsDiff"
82            )
83        })
84    }
85}