1use std::collections::HashMap;
2
3use crate::grpc_conversions::metadata::MetadataWrapper;
4use crate::grpc_macros::convert_option;
5use crate::qdrant::*;
6
7#[derive(Debug, Clone)]
8pub struct CreateCollectionBuilder {
9 pub(crate) collection_name: Option<String>,
11 pub(crate) hnsw_config: Option<Option<HnswConfigDiff>>,
13 pub(crate) wal_config: Option<Option<WalConfigDiff>>,
15 pub(crate) optimizers_config: Option<Option<OptimizersConfigDiff>>,
17 pub(crate) shard_number: Option<Option<u32>>,
19 pub(crate) on_disk_payload: Option<Option<bool>>,
21 pub(crate) timeout: Option<Option<u64>>,
23 pub(crate) vectors_config: Option<Option<VectorsConfig>>,
25 pub(crate) replication_factor: Option<Option<u32>>,
27 pub(crate) write_consistency_factor: Option<Option<u32>>,
29 quantization_config: Option<quantization_config::Quantization>,
31 pub(crate) sharding_method: Option<Option<i32>>,
33 pub(crate) sparse_vectors_config: Option<Option<SparseVectorConfig>>,
35 pub(crate) strict_mode_config: Option<Option<StrictModeConfig>>,
37 pub(crate) metadata: Option<HashMap<String, Value>>,
39}
40
41#[allow(clippy::all)]
42#[allow(clippy::derive_partial_eq_without_eq)]
43impl CreateCollectionBuilder {
44 pub fn collection_name<VALUE: Into<String>>(self, value: VALUE) -> Self {
46 let mut new = self;
47 new.collection_name = Option::Some(value.into());
48 new
49 }
50 pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
52 let mut new = self;
53 new.hnsw_config = Option::Some(Option::Some(value.into()));
54 new
55 }
56 pub fn wal_config<VALUE: core::convert::Into<WalConfigDiff>>(self, value: VALUE) -> Self {
58 let mut new = self;
59 new.wal_config = Option::Some(Option::Some(value.into()));
60 new
61 }
62 pub fn optimizers_config<VALUE: core::convert::Into<OptimizersConfigDiff>>(
64 self,
65 value: VALUE,
66 ) -> Self {
67 let mut new = self;
68 new.optimizers_config = Option::Some(Option::Some(value.into()));
69 new
70 }
71 pub fn shard_number(self, value: u32) -> Self {
73 let mut new = self;
74 new.shard_number = Option::Some(Option::Some(value));
75 new
76 }
77 pub fn on_disk_payload(self, value: bool) -> Self {
79 let mut new = self;
80 new.on_disk_payload = Option::Some(Option::Some(value));
81 new
82 }
83 pub fn timeout(self, value: u64) -> Self {
85 let mut new = self;
86 new.timeout = Option::Some(Option::Some(value));
87 new
88 }
89 pub fn vectors_config<VALUE: core::convert::Into<VectorsConfig>>(self, value: VALUE) -> Self {
91 let mut new = self;
92 new.vectors_config = Option::Some(Option::Some(value.into()));
93 new
94 }
95 pub fn replication_factor(self, value: u32) -> Self {
97 let mut new = self;
98 new.replication_factor = Option::Some(Option::Some(value));
99 new
100 }
101 pub fn write_consistency_factor(self, value: u32) -> Self {
103 let mut new = self;
104 new.write_consistency_factor = Option::Some(Option::Some(value));
105 new
106 }
107 pub fn quantization_config<VALUE: core::convert::Into<quantization_config::Quantization>>(
109 self,
110 value: VALUE,
111 ) -> Self {
112 let mut new = self;
113 new.quantization_config = Option::Some(value.into());
114 new
115 }
116 pub fn sharding_method(self, value: i32) -> Self {
118 let mut new = self;
119 new.sharding_method = Option::Some(Option::Some(value));
120 new
121 }
122 pub fn sparse_vectors_config<VALUE: core::convert::Into<SparseVectorConfig>>(
124 self,
125 value: VALUE,
126 ) -> Self {
127 let mut new = self;
128 new.sparse_vectors_config = Option::Some(Option::Some(value.into()));
129 new
130 }
131 pub fn strict_mode_config<VALUE: core::convert::Into<StrictModeConfig>>(
133 self,
134 value: VALUE,
135 ) -> Self {
136 let mut new = self;
137 new.strict_mode_config = Option::Some(Option::Some(value.into()));
138 new
139 }
140 pub fn metadata(self, value: impl Into<MetadataWrapper>) -> Self {
142 let mut new = self;
143 new.metadata = Option::Some(value.into().0);
144 new
145 }
146
147 fn build_inner(self) -> Result<CreateCollection, std::convert::Infallible> {
148 Ok(CreateCollection {
149 collection_name: match self.collection_name {
150 Some(value) => value,
151 None => core::default::Default::default(),
152 },
153 hnsw_config: match self.hnsw_config {
154 Some(value) => value,
155 None => core::default::Default::default(),
156 },
157 wal_config: match self.wal_config {
158 Some(value) => value,
159 None => core::default::Default::default(),
160 },
161 optimizers_config: match self.optimizers_config {
162 Some(value) => value,
163 None => core::default::Default::default(),
164 },
165 shard_number: match self.shard_number {
166 Some(value) => value,
167 None => core::default::Default::default(),
168 },
169 on_disk_payload: match self.on_disk_payload {
170 Some(value) => value,
171 None => core::default::Default::default(),
172 },
173 timeout: match self.timeout {
174 Some(value) => value,
175 None => core::default::Default::default(),
176 },
177 vectors_config: match self.vectors_config {
178 Some(value) => value,
179 None => core::default::Default::default(),
180 },
181 replication_factor: match self.replication_factor {
182 Some(value) => value,
183 None => core::default::Default::default(),
184 },
185 write_consistency_factor: match self.write_consistency_factor {
186 Some(value) => value,
187 None => core::default::Default::default(),
188 },
189 quantization_config: { convert_option(&self.quantization_config) },
190 sharding_method: match self.sharding_method {
191 Some(value) => value,
192 None => core::default::Default::default(),
193 },
194 sparse_vectors_config: match self.sparse_vectors_config {
195 Some(value) => value,
196 None => core::default::Default::default(),
197 },
198 strict_mode_config: match self.strict_mode_config {
199 Some(value) => value,
200 None => core::default::Default::default(),
201 },
202 metadata: match self.metadata {
203 Some(value) => value,
204 None => core::default::Default::default(),
205 },
206 })
207 }
208 fn create_empty() -> Self {
210 Self {
211 collection_name: core::default::Default::default(),
212 hnsw_config: core::default::Default::default(),
213 wal_config: core::default::Default::default(),
214 optimizers_config: core::default::Default::default(),
215 shard_number: core::default::Default::default(),
216 on_disk_payload: core::default::Default::default(),
217 timeout: core::default::Default::default(),
218 vectors_config: core::default::Default::default(),
219 replication_factor: core::default::Default::default(),
220 write_consistency_factor: core::default::Default::default(),
221 quantization_config: core::default::Default::default(),
222 sharding_method: core::default::Default::default(),
223 sparse_vectors_config: core::default::Default::default(),
224 strict_mode_config: core::default::Default::default(),
225 metadata: core::default::Default::default(),
226 }
227 }
228}
229
230impl From<CreateCollectionBuilder> for CreateCollection {
231 fn from(value: CreateCollectionBuilder) -> Self {
232 value.build_inner().unwrap_or_else(|_| {
233 panic!(
234 "Failed to convert {0} to {1}",
235 "CreateCollectionBuilder", "CreateCollection"
236 )
237 })
238 }
239}
240
241impl CreateCollectionBuilder {
242 pub fn build(self) -> CreateCollection {
244 self.build_inner().unwrap_or_else(|_| {
245 panic!(
246 "Failed to build {0} into {1}",
247 "CreateCollectionBuilder", "CreateCollection"
248 )
249 })
250 }
251}
252
253impl Default for CreateCollectionBuilder {
254 fn default() -> Self {
255 Self::create_empty()
256 }
257}