qdrant_client/builders/
vector_params_diff_builder.rs

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