1use std::collections::HashMap;
2
3use crate::grpc_conversions::metadata::MetadataWrapper;
4use crate::grpc_macros::convert_option;
5use crate::qdrant::*;
6
7#[must_use]
8#[derive(Debug, Clone)]
9pub struct CreateCollectionBuilder {
10 pub(crate) collection_name: Option<String>,
12 pub(crate) hnsw_config: Option<Option<HnswConfigDiff>>,
14 pub(crate) wal_config: Option<Option<WalConfigDiff>>,
16 pub(crate) optimizers_config: Option<Option<OptimizersConfigDiff>>,
18 pub(crate) shard_number: Option<Option<u32>>,
20 pub(crate) on_disk_payload: Option<Option<bool>>,
22 pub(crate) timeout: Option<Option<u64>>,
24 pub(crate) vectors_config: Option<Option<VectorsConfig>>,
26 pub(crate) replication_factor: Option<Option<u32>>,
28 pub(crate) write_consistency_factor: Option<Option<u32>>,
30 quantization_config: Option<quantization_config::Quantization>,
32 pub(crate) sharding_method: Option<Option<i32>>,
34 pub(crate) sparse_vectors_config: Option<Option<SparseVectorConfig>>,
36 pub(crate) strict_mode_config: Option<Option<StrictModeConfig>>,
38 pub(crate) metadata: Option<HashMap<String, Value>>,
40 pub(crate) payload: Option<Option<PayloadStorageParams>>,
42}
43
44#[allow(clippy::all)]
45#[allow(clippy::derive_partial_eq_without_eq)]
46impl CreateCollectionBuilder {
47 pub fn collection_name<VALUE: Into<String>>(self, value: VALUE) -> Self {
49 let mut new = self;
50 new.collection_name = Option::Some(value.into());
51 new
52 }
53 pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
55 let mut new = self;
56 new.hnsw_config = Option::Some(Option::Some(value.into()));
57 new
58 }
59 pub fn wal_config<VALUE: core::convert::Into<WalConfigDiff>>(self, value: VALUE) -> Self {
61 let mut new = self;
62 new.wal_config = Option::Some(Option::Some(value.into()));
63 new
64 }
65 pub fn optimizers_config<VALUE: core::convert::Into<OptimizersConfigDiff>>(
67 self,
68 value: VALUE,
69 ) -> Self {
70 let mut new = self;
71 new.optimizers_config = Option::Some(Option::Some(value.into()));
72 new
73 }
74 pub fn shard_number(self, value: u32) -> Self {
76 let mut new = self;
77 new.shard_number = Option::Some(Option::Some(value));
78 new
79 }
80 pub fn on_disk_payload(self, value: bool) -> Self {
84 let mut new = self;
85 new.on_disk_payload = Option::Some(Option::Some(value));
86 new
87 }
88 pub fn timeout(self, value: u64) -> Self {
90 let mut new = self;
91 new.timeout = Option::Some(Option::Some(value));
92 new
93 }
94 pub fn vectors_config<VALUE: core::convert::Into<VectorsConfig>>(self, value: VALUE) -> Self {
96 let mut new = self;
97 new.vectors_config = Option::Some(Option::Some(value.into()));
98 new
99 }
100 pub fn replication_factor(self, value: u32) -> Self {
102 let mut new = self;
103 new.replication_factor = Option::Some(Option::Some(value));
104 new
105 }
106 pub fn write_consistency_factor(self, value: u32) -> Self {
108 let mut new = self;
109 new.write_consistency_factor = Option::Some(Option::Some(value));
110 new
111 }
112 pub fn quantization_config<VALUE: core::convert::Into<quantization_config::Quantization>>(
114 self,
115 value: VALUE,
116 ) -> Self {
117 let mut new = self;
118 new.quantization_config = Option::Some(value.into());
119 new
120 }
121 pub fn sharding_method(self, value: i32) -> Self {
123 let mut new = self;
124 new.sharding_method = Option::Some(Option::Some(value));
125 new
126 }
127 pub fn sparse_vectors_config<VALUE: core::convert::Into<SparseVectorConfig>>(
129 self,
130 value: VALUE,
131 ) -> Self {
132 let mut new = self;
133 new.sparse_vectors_config = Option::Some(Option::Some(value.into()));
134 new
135 }
136 pub fn strict_mode_config<VALUE: core::convert::Into<StrictModeConfig>>(
138 self,
139 value: VALUE,
140 ) -> Self {
141 let mut new = self;
142 new.strict_mode_config = Option::Some(Option::Some(value.into()));
143 new
144 }
145 pub fn metadata(self, value: impl Into<MetadataWrapper>) -> Self {
147 let mut new = self;
148 new.metadata = Option::Some(value.into().0);
149 new
150 }
151 pub fn payload<VALUE: core::convert::Into<PayloadStorageParams>>(self, value: VALUE) -> Self {
154 let mut new = self;
155 new.payload = Option::Some(Option::Some(value.into()));
156 new
157 }
158
159 #[allow(deprecated)]
160 fn build_inner(self) -> Result<CreateCollection, std::convert::Infallible> {
161 Ok(CreateCollection {
162 collection_name: match self.collection_name {
163 Some(value) => value,
164 None => core::default::Default::default(),
165 },
166 hnsw_config: match self.hnsw_config {
167 Some(value) => value,
168 None => core::default::Default::default(),
169 },
170 wal_config: match self.wal_config {
171 Some(value) => value,
172 None => core::default::Default::default(),
173 },
174 optimizers_config: match self.optimizers_config {
175 Some(value) => value,
176 None => core::default::Default::default(),
177 },
178 shard_number: match self.shard_number {
179 Some(value) => value,
180 None => core::default::Default::default(),
181 },
182 on_disk_payload: match self.on_disk_payload {
183 Some(value) => value,
184 None => core::default::Default::default(),
185 },
186 timeout: match self.timeout {
187 Some(value) => value,
188 None => core::default::Default::default(),
189 },
190 vectors_config: match self.vectors_config {
191 Some(value) => value,
192 None => core::default::Default::default(),
193 },
194 replication_factor: match self.replication_factor {
195 Some(value) => value,
196 None => core::default::Default::default(),
197 },
198 write_consistency_factor: match self.write_consistency_factor {
199 Some(value) => value,
200 None => core::default::Default::default(),
201 },
202 quantization_config: { convert_option(&self.quantization_config) },
203 sharding_method: match self.sharding_method {
204 Some(value) => value,
205 None => core::default::Default::default(),
206 },
207 sparse_vectors_config: match self.sparse_vectors_config {
208 Some(value) => value,
209 None => core::default::Default::default(),
210 },
211 strict_mode_config: match self.strict_mode_config {
212 Some(value) => value,
213 None => core::default::Default::default(),
214 },
215 metadata: match self.metadata {
216 Some(value) => value,
217 None => core::default::Default::default(),
218 },
219 payload: match self.payload {
220 Some(value) => value,
221 None => core::default::Default::default(),
222 },
223 })
224 }
225 fn create_empty() -> Self {
227 Self {
228 collection_name: core::default::Default::default(),
229 hnsw_config: core::default::Default::default(),
230 wal_config: core::default::Default::default(),
231 optimizers_config: core::default::Default::default(),
232 shard_number: core::default::Default::default(),
233 on_disk_payload: core::default::Default::default(),
234 timeout: core::default::Default::default(),
235 vectors_config: core::default::Default::default(),
236 replication_factor: core::default::Default::default(),
237 write_consistency_factor: core::default::Default::default(),
238 quantization_config: core::default::Default::default(),
239 sharding_method: core::default::Default::default(),
240 sparse_vectors_config: core::default::Default::default(),
241 strict_mode_config: core::default::Default::default(),
242 metadata: core::default::Default::default(),
243 payload: core::default::Default::default(),
244 }
245 }
246}
247
248impl From<CreateCollectionBuilder> for CreateCollection {
249 fn from(value: CreateCollectionBuilder) -> Self {
250 value.build_inner().unwrap_or_else(|_| {
251 panic!(
252 "Failed to convert {0} to {1}",
253 "CreateCollectionBuilder", "CreateCollection"
254 )
255 })
256 }
257}
258
259impl CreateCollectionBuilder {
260 pub fn build(self) -> CreateCollection {
262 self.build_inner().unwrap_or_else(|_| {
263 panic!(
264 "Failed to build {0} into {1}",
265 "CreateCollectionBuilder", "CreateCollection"
266 )
267 })
268 }
269}
270
271impl Default for CreateCollectionBuilder {
272 fn default() -> Self {
273 Self::create_empty()
274 }
275}