Skip to main content

qdrant_client/builders/
vector_params_diff_builder.rs

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