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    /// Memory placement of the original vector storage.
14    pub(crate) memory: Option<Option<i32>>,
15}
16
17impl VectorParamsDiffBuilder {
18    /// Update params for HNSW index. If empty object - it will be unset
19    pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
20        let mut new = self;
21        new.hnsw_config = Option::Some(Option::Some(value.into()));
22        new
23    }
24    /// Update quantization params. If none - it is left unchanged.
25    pub fn quantization_config<
26        VALUE: core::convert::Into<quantization_config_diff::Quantization>,
27    >(
28        self,
29        value: VALUE,
30    ) -> Self {
31        let mut new = self;
32        new.quantization_config = Option::Some(value.into());
33        new
34    }
35    /// If true - serve vectors from disk. If set to false, the vectors will be loaded in RAM.
36    ///
37    /// Deprecated since 1.19.0, use [`memory`](Self::memory) instead.
38    pub fn on_disk(self, value: bool) -> Self {
39        let mut new = self;
40        new.on_disk = Option::Some(Option::Some(value));
41        new
42    }
43    /// Memory placement of the original vector storage.
44    /// Overrides the deprecated `on_disk` flag if both are set.
45    /// [`Memory::Pinned`] is not supported for dense vector storage.
46    pub fn memory<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
47        let mut new = self;
48        new.memory = Option::Some(Option::Some(value.into()));
49        new
50    }
51
52    #[allow(deprecated)]
53    fn build_inner(self) -> Result<VectorParamsDiff, std::convert::Infallible> {
54        Ok(VectorParamsDiff {
55            hnsw_config: self.hnsw_config.unwrap_or_default(),
56            quantization_config: { convert_option(&self.quantization_config) },
57            on_disk: self.on_disk.unwrap_or_default(),
58            memory: self.memory.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            hnsw_config: core::default::Default::default(),
65            quantization_config: core::default::Default::default(),
66            on_disk: core::default::Default::default(),
67            memory: core::default::Default::default(),
68        }
69    }
70}
71
72impl Default for VectorParamsDiffBuilder {
73    fn default() -> Self {
74        Self::create_empty()
75    }
76}
77
78impl From<VectorParamsDiffBuilder> for VectorParamsDiff {
79    fn from(value: VectorParamsDiffBuilder) -> Self {
80        value.build_inner().unwrap_or_else(|_| {
81            panic!(
82                "Failed to convert {0} to {1}",
83                "VectorParamsDiffBuilder", "VectorParamsDiff"
84            )
85        })
86    }
87}
88
89impl VectorParamsDiffBuilder {
90    /// Builds the desired type. Can often be omitted.
91    pub fn build(self) -> VectorParamsDiff {
92        self.build_inner().unwrap_or_else(|_| {
93            panic!(
94                "Failed to build {0} into {1}",
95                "VectorParamsDiffBuilder", "VectorParamsDiff"
96            )
97        })
98    }
99}