Skip to main content

qdrant_client/builders/
strict_mode_config_builder.rs

1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct StrictModeConfigBuilder {
6    pub(crate) enabled: Option<Option<bool>>,
7    pub(crate) max_query_limit: Option<Option<u32>>,
8    pub(crate) max_timeout: Option<Option<u32>>,
9    pub(crate) unindexed_filtering_retrieve: Option<Option<bool>>,
10    pub(crate) unindexed_filtering_update: Option<Option<bool>>,
11    pub(crate) search_max_hnsw_ef: Option<Option<u32>>,
12    pub(crate) search_allow_exact: Option<Option<bool>>,
13    pub(crate) search_max_oversampling: Option<Option<f32>>,
14    pub(crate) upsert_max_batchsize: Option<Option<u64>>,
15    pub(crate) search_max_batchsize: Option<Option<u64>>,
16    pub(crate) max_collection_vector_size_bytes: Option<Option<u64>>,
17    pub(crate) read_rate_limit: Option<Option<u32>>,
18    pub(crate) write_rate_limit: Option<Option<u32>>,
19    pub(crate) max_collection_payload_size_bytes: Option<Option<u64>>,
20    pub(crate) filter_max_conditions: Option<Option<u64>>,
21    pub(crate) condition_max_size: Option<Option<u64>>,
22    pub(crate) multivector_config: Option<Option<StrictModeMultivectorConfig>>,
23    pub(crate) sparse_config: Option<Option<StrictModeSparseConfig>>,
24    pub(crate) max_points_count: Option<Option<u64>>,
25    pub(crate) max_payload_index_count: Option<Option<u64>>,
26    pub(crate) max_resident_memory_percent: Option<Option<u32>>,
27}
28
29impl StrictModeConfigBuilder {
30    pub fn enabled(self, value: bool) -> Self {
31        let mut new = self;
32        new.enabled = Option::Some(Option::Some(value));
33        new
34    }
35
36    pub fn max_query_limit(self, value: u32) -> Self {
37        let mut new = self;
38        new.max_query_limit = Option::Some(Option::Some(value));
39        new
40    }
41
42    pub fn max_timeout(self, value: u32) -> Self {
43        let mut new = self;
44        new.max_timeout = Option::Some(Option::Some(value));
45        new
46    }
47
48    pub fn unindexed_filtering_retrieve(self, value: bool) -> Self {
49        let mut new = self;
50        new.unindexed_filtering_retrieve = Option::Some(Option::Some(value));
51        new
52    }
53
54    pub fn unindexed_filtering_update(self, value: bool) -> Self {
55        let mut new = self;
56        new.unindexed_filtering_update = Option::Some(Option::Some(value));
57        new
58    }
59
60    pub fn search_max_hnsw_ef(self, value: u32) -> Self {
61        let mut new = self;
62        new.search_max_hnsw_ef = Option::Some(Option::Some(value));
63        new
64    }
65
66    pub fn search_allow_exact(self, value: bool) -> Self {
67        let mut new = self;
68        new.search_allow_exact = Option::Some(Option::Some(value));
69        new
70    }
71
72    pub fn search_max_oversampling(self, value: f32) -> Self {
73        let mut new = self;
74        new.search_max_oversampling = Option::Some(Option::Some(value));
75        new
76    }
77
78    pub fn upsert_max_batchsize(self, value: u64) -> Self {
79        let mut new = self;
80        new.upsert_max_batchsize = Option::Some(Option::Some(value));
81        new
82    }
83
84    pub fn search_max_batchsize(self, value: u64) -> Self {
85        let mut new = self;
86        new.search_max_batchsize = Option::Some(Option::Some(value));
87        new
88    }
89
90    pub fn max_collection_vector_size_bytes(self, value: u64) -> Self {
91        let mut new = self;
92        new.max_collection_vector_size_bytes = Option::Some(Option::Some(value));
93        new
94    }
95
96    pub fn read_rate_limit(self, value: u32) -> Self {
97        let mut new = self;
98        new.read_rate_limit = Option::Some(Option::Some(value));
99        new
100    }
101
102    pub fn write_rate_limit(self, value: u32) -> Self {
103        let mut new = self;
104        new.write_rate_limit = Option::Some(Option::Some(value));
105        new
106    }
107
108    pub fn max_collection_payload_size_bytes(self, value: u64) -> Self {
109        let mut new = self;
110        new.max_collection_payload_size_bytes = Option::Some(Option::Some(value));
111        new
112    }
113
114    pub fn filter_max_conditions(self, value: u64) -> Self {
115        let mut new = self;
116        new.filter_max_conditions = Option::Some(Option::Some(value));
117        new
118    }
119
120    pub fn condition_max_size(self, value: u64) -> Self {
121        let mut new = self;
122        new.condition_max_size = Option::Some(Option::Some(value));
123        new
124    }
125
126    pub fn multivector_config(self, value: impl Into<StrictModeMultivectorConfig>) -> Self {
127        let mut new = self;
128        new.multivector_config = Option::Some(Option::Some(value.into()));
129        new
130    }
131
132    pub fn sparse_config(self, value: impl Into<StrictModeSparseConfig>) -> Self {
133        let mut new = self;
134        new.sparse_config = Option::Some(Option::Some(value.into()));
135        new
136    }
137
138    pub fn max_points_count(self, value: u64) -> Self {
139        let mut new = self;
140        new.max_points_count = Option::Some(Option::Some(value));
141        new
142    }
143
144    pub fn max_payload_index_count(self, value: u64) -> Self {
145        let mut new = self;
146        new.max_payload_index_count = Option::Some(Option::Some(value));
147        new
148    }
149
150    pub fn max_resident_memory_percent(self, value: u32) -> Self {
151        let mut new = self;
152        new.max_resident_memory_percent = Option::Some(Option::Some(value));
153        new
154    }
155
156    fn build_inner(self) -> Result<StrictModeConfig, std::convert::Infallible> {
157        Ok(StrictModeConfig {
158            enabled: self.enabled.unwrap_or_default(),
159            max_query_limit: self.max_query_limit.unwrap_or_default(),
160            max_timeout: self.max_timeout.unwrap_or_default(),
161            unindexed_filtering_retrieve: self.unindexed_filtering_retrieve.unwrap_or_default(),
162            unindexed_filtering_update: self.unindexed_filtering_update.unwrap_or_default(),
163            search_max_hnsw_ef: self.search_max_hnsw_ef.unwrap_or_default(),
164            search_allow_exact: self.search_allow_exact.unwrap_or_default(),
165            search_max_oversampling: self.search_max_oversampling.unwrap_or_default(),
166            upsert_max_batchsize: self.upsert_max_batchsize.unwrap_or_default(),
167            search_max_batchsize: self.search_max_batchsize.unwrap_or_default(),
168            max_collection_vector_size_bytes: self
169                .max_collection_vector_size_bytes
170                .unwrap_or_default(),
171            read_rate_limit: self.read_rate_limit.unwrap_or_default(),
172            write_rate_limit: self.write_rate_limit.unwrap_or_default(),
173            max_collection_payload_size_bytes: self
174                .max_collection_payload_size_bytes
175                .unwrap_or_default(),
176            filter_max_conditions: self.filter_max_conditions.unwrap_or_default(),
177            condition_max_size: self.condition_max_size.unwrap_or_default(),
178            multivector_config: self.multivector_config.unwrap_or_default(),
179            sparse_config: self.sparse_config.unwrap_or_default(),
180            max_points_count: self.max_points_count.unwrap_or_default(),
181            max_payload_index_count: self.max_payload_index_count.unwrap_or_default(),
182            max_resident_memory_percent: self.max_resident_memory_percent.unwrap_or_default(),
183        })
184    }
185    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
186    fn create_empty() -> Self {
187        Self {
188            enabled: core::default::Default::default(),
189            max_query_limit: core::default::Default::default(),
190            max_timeout: core::default::Default::default(),
191            unindexed_filtering_retrieve: core::default::Default::default(),
192            unindexed_filtering_update: core::default::Default::default(),
193            search_max_hnsw_ef: core::default::Default::default(),
194            search_allow_exact: core::default::Default::default(),
195            search_max_oversampling: core::default::Default::default(),
196            upsert_max_batchsize: core::default::Default::default(),
197            search_max_batchsize: core::default::Default::default(),
198            max_collection_vector_size_bytes: core::default::Default::default(),
199            read_rate_limit: core::default::Default::default(),
200            write_rate_limit: core::default::Default::default(),
201            max_collection_payload_size_bytes: core::default::Default::default(),
202            filter_max_conditions: core::default::Default::default(),
203            condition_max_size: core::default::Default::default(),
204            multivector_config: core::default::Default::default(),
205            sparse_config: core::default::Default::default(),
206            max_points_count: core::default::Default::default(),
207            max_payload_index_count: core::default::Default::default(),
208            max_resident_memory_percent: core::default::Default::default(),
209        }
210    }
211}
212
213impl Default for StrictModeConfigBuilder {
214    fn default() -> Self {
215        Self::create_empty()
216    }
217}
218
219impl From<StrictModeConfigBuilder> for StrictModeConfig {
220    fn from(value: StrictModeConfigBuilder) -> Self {
221        value.build_inner().unwrap_or_else(|_| {
222            panic!(
223                "Failed to convert {0} to {1}",
224                "StrictModeConfigBuilder", "StrictModeConfig"
225            )
226        })
227    }
228}
229
230impl StrictModeConfigBuilder {
231    /// Builds the desired type. Can often be omitted.
232    pub fn build(self) -> StrictModeConfig {
233        self.build_inner().unwrap_or_else(|_| {
234            panic!(
235                "Failed to build {0} into {1}",
236                "StrictModeConfigBuilder", "StrictModeConfig"
237            )
238        })
239    }
240}