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>>,
31}
32
33impl StrictModeConfigBuilder {
34 pub fn enabled(self, value: bool) -> Self {
35 let mut new = self;
36 new.enabled = Option::Some(Option::Some(value));
37 new
38 }
39
40 pub fn max_query_limit(self, value: u32) -> Self {
41 let mut new = self;
42 new.max_query_limit = Option::Some(Option::Some(value));
43 new
44 }
45
46 pub fn max_timeout(self, value: u32) -> Self {
47 let mut new = self;
48 new.max_timeout = Option::Some(Option::Some(value));
49 new
50 }
51
52 pub fn unindexed_filtering_retrieve(self, value: bool) -> Self {
53 let mut new = self;
54 new.unindexed_filtering_retrieve = Option::Some(Option::Some(value));
55 new
56 }
57
58 pub fn unindexed_filtering_update(self, value: bool) -> Self {
59 let mut new = self;
60 new.unindexed_filtering_update = Option::Some(Option::Some(value));
61 new
62 }
63
64 pub fn search_max_hnsw_ef(self, value: u32) -> Self {
65 let mut new = self;
66 new.search_max_hnsw_ef = Option::Some(Option::Some(value));
67 new
68 }
69
70 pub fn search_allow_exact(self, value: bool) -> Self {
71 let mut new = self;
72 new.search_allow_exact = Option::Some(Option::Some(value));
73 new
74 }
75
76 pub fn search_max_oversampling(self, value: f32) -> Self {
77 let mut new = self;
78 new.search_max_oversampling = Option::Some(Option::Some(value));
79 new
80 }
81
82 pub fn upsert_max_batchsize(self, value: u64) -> Self {
83 let mut new = self;
84 new.upsert_max_batchsize = Option::Some(Option::Some(value));
85 new
86 }
87
88 pub fn search_max_batchsize(self, value: u64) -> Self {
89 let mut new = self;
90 new.search_max_batchsize = Option::Some(Option::Some(value));
91 new
92 }
93
94 pub fn max_collection_vector_size_bytes(self, value: u64) -> Self {
95 let mut new = self;
96 new.max_collection_vector_size_bytes = Option::Some(Option::Some(value));
97 new
98 }
99
100 pub fn read_rate_limit(self, value: u32) -> Self {
101 let mut new = self;
102 new.read_rate_limit = Option::Some(Option::Some(value));
103 new
104 }
105
106 pub fn write_rate_limit(self, value: u32) -> Self {
107 let mut new = self;
108 new.write_rate_limit = Option::Some(Option::Some(value));
109 new
110 }
111
112 pub fn max_collection_payload_size_bytes(self, value: u64) -> Self {
113 let mut new = self;
114 new.max_collection_payload_size_bytes = Option::Some(Option::Some(value));
115 new
116 }
117
118 pub fn filter_max_conditions(self, value: u64) -> Self {
119 let mut new = self;
120 new.filter_max_conditions = Option::Some(Option::Some(value));
121 new
122 }
123
124 pub fn condition_max_size(self, value: u64) -> Self {
125 let mut new = self;
126 new.condition_max_size = Option::Some(Option::Some(value));
127 new
128 }
129
130 pub fn multivector_config(self, value: impl Into<StrictModeMultivectorConfig>) -> Self {
131 let mut new = self;
132 new.multivector_config = Option::Some(Option::Some(value.into()));
133 new
134 }
135
136 pub fn sparse_config(self, value: impl Into<StrictModeSparseConfig>) -> Self {
137 let mut new = self;
138 new.sparse_config = Option::Some(Option::Some(value.into()));
139 new
140 }
141
142 pub fn max_points_count(self, value: u64) -> Self {
143 let mut new = self;
144 new.max_points_count = Option::Some(Option::Some(value));
145 new
146 }
147
148 pub fn max_payload_index_count(self, value: u64) -> Self {
149 let mut new = self;
150 new.max_payload_index_count = Option::Some(Option::Some(value));
151 new
152 }
153
154 pub fn max_resident_memory_percent(self, value: u32) -> Self {
162 let mut new = self;
163 new.max_resident_memory_percent = Option::Some(Option::Some(value));
164 new
165 }
166
167 #[allow(deprecated)]
168 fn build_inner(self) -> Result<StrictModeConfig, std::convert::Infallible> {
169 Ok(StrictModeConfig {
170 enabled: self.enabled.unwrap_or_default(),
171 max_query_limit: self.max_query_limit.unwrap_or_default(),
172 max_timeout: self.max_timeout.unwrap_or_default(),
173 unindexed_filtering_retrieve: self.unindexed_filtering_retrieve.unwrap_or_default(),
174 unindexed_filtering_update: self.unindexed_filtering_update.unwrap_or_default(),
175 search_max_hnsw_ef: self.search_max_hnsw_ef.unwrap_or_default(),
176 search_allow_exact: self.search_allow_exact.unwrap_or_default(),
177 search_max_oversampling: self.search_max_oversampling.unwrap_or_default(),
178 upsert_max_batchsize: self.upsert_max_batchsize.unwrap_or_default(),
179 search_max_batchsize: self.search_max_batchsize.unwrap_or_default(),
180 max_collection_vector_size_bytes: self
181 .max_collection_vector_size_bytes
182 .unwrap_or_default(),
183 read_rate_limit: self.read_rate_limit.unwrap_or_default(),
184 write_rate_limit: self.write_rate_limit.unwrap_or_default(),
185 max_collection_payload_size_bytes: self
186 .max_collection_payload_size_bytes
187 .unwrap_or_default(),
188 filter_max_conditions: self.filter_max_conditions.unwrap_or_default(),
189 condition_max_size: self.condition_max_size.unwrap_or_default(),
190 multivector_config: self.multivector_config.unwrap_or_default(),
191 sparse_config: self.sparse_config.unwrap_or_default(),
192 max_points_count: self.max_points_count.unwrap_or_default(),
193 max_payload_index_count: self.max_payload_index_count.unwrap_or_default(),
194 max_resident_memory_percent: self.max_resident_memory_percent.unwrap_or_default(),
195 })
196 }
197 fn create_empty() -> Self {
199 Self {
200 enabled: core::default::Default::default(),
201 max_query_limit: core::default::Default::default(),
202 max_timeout: core::default::Default::default(),
203 unindexed_filtering_retrieve: core::default::Default::default(),
204 unindexed_filtering_update: core::default::Default::default(),
205 search_max_hnsw_ef: core::default::Default::default(),
206 search_allow_exact: core::default::Default::default(),
207 search_max_oversampling: core::default::Default::default(),
208 upsert_max_batchsize: core::default::Default::default(),
209 search_max_batchsize: core::default::Default::default(),
210 max_collection_vector_size_bytes: core::default::Default::default(),
211 read_rate_limit: core::default::Default::default(),
212 write_rate_limit: core::default::Default::default(),
213 max_collection_payload_size_bytes: core::default::Default::default(),
214 filter_max_conditions: core::default::Default::default(),
215 condition_max_size: core::default::Default::default(),
216 multivector_config: core::default::Default::default(),
217 sparse_config: core::default::Default::default(),
218 max_points_count: core::default::Default::default(),
219 max_payload_index_count: core::default::Default::default(),
220 max_resident_memory_percent: core::default::Default::default(),
221 }
222 }
223}
224
225impl Default for StrictModeConfigBuilder {
226 fn default() -> Self {
227 Self::create_empty()
228 }
229}
230
231impl From<StrictModeConfigBuilder> for StrictModeConfig {
232 fn from(value: StrictModeConfigBuilder) -> Self {
233 value.build_inner().unwrap_or_else(|_| {
234 panic!(
235 "Failed to convert {0} to {1}",
236 "StrictModeConfigBuilder", "StrictModeConfig"
237 )
238 })
239 }
240}
241
242impl StrictModeConfigBuilder {
243 pub fn build(self) -> StrictModeConfig {
245 self.build_inner().unwrap_or_else(|_| {
246 panic!(
247 "Failed to build {0} into {1}",
248 "StrictModeConfigBuilder", "StrictModeConfig"
249 )
250 })
251 }
252}