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    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    pub fn quantization_config<
23        VALUE: core::convert::Into<quantization_config_diff::Quantization>,
24    >(
25        self,
26        value: VALUE,
27    ) -> Self {
28        let mut new = self;
29        new.quantization_config = Option::Some(value.into());
30        new
31    }
32    /// If true - serve vectors from disk. If set to false, the vectors will be loaded in RAM.
33    pub fn on_disk(self, value: bool) -> Self {
34        let mut new = self;
35        new.on_disk = Option::Some(Option::Some(value));
36        new
37    }
38
39    fn build_inner(self) -> Result<VectorParamsDiff, std::convert::Infallible> {
40        Ok(VectorParamsDiff {
41            hnsw_config: self.hnsw_config.unwrap_or_default(),
42            quantization_config: { convert_option(&self.quantization_config) },
43            on_disk: self.on_disk.unwrap_or_default(),
44        })
45    }
46    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
47    fn create_empty() -> Self {
48        Self {
49            hnsw_config: core::default::Default::default(),
50            quantization_config: core::default::Default::default(),
51            on_disk: core::default::Default::default(),
52        }
53    }
54}
55
56impl Default for VectorParamsDiffBuilder {
57    fn default() -> Self {
58        Self::create_empty()
59    }
60}
61
62impl From<VectorParamsDiffBuilder> for VectorParamsDiff {
63    fn from(value: VectorParamsDiffBuilder) -> Self {
64        value.build_inner().unwrap_or_else(|_| {
65            panic!(
66                "Failed to convert {0} to {1}",
67                "VectorParamsDiffBuilder", "VectorParamsDiff"
68            )
69        })
70    }
71}
72
73impl VectorParamsDiffBuilder {
74    /// Builds the desired type. Can often be omitted.
75    pub fn build(self) -> VectorParamsDiff {
76        self.build_inner().unwrap_or_else(|_| {
77            panic!(
78                "Failed to build {0} into {1}",
79                "VectorParamsDiffBuilder", "VectorParamsDiff"
80            )
81        })
82    }
83}