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}
41
42#[allow(clippy::all)]
43#[allow(clippy::derive_partial_eq_without_eq)]
44impl CreateCollectionBuilder {
45 pub fn collection_name<VALUE: Into<String>>(self, value: VALUE) -> Self {
47 let mut new = self;
48 new.collection_name = Option::Some(value.into());
49 new
50 }
51 pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
53 let mut new = self;
54 new.hnsw_config = Option::Some(Option::Some(value.into()));
55 new
56 }
57 pub fn wal_config<VALUE: core::convert::Into<WalConfigDiff>>(self, value: VALUE) -> Self {
59 let mut new = self;
60 new.wal_config = Option::Some(Option::Some(value.into()));
61 new
62 }
63 pub fn optimizers_config<VALUE: core::convert::Into<OptimizersConfigDiff>>(
65 self,
66 value: VALUE,
67 ) -> Self {
68 let mut new = self;
69 new.optimizers_config = Option::Some(Option::Some(value.into()));
70 new
71 }
72 pub fn shard_number(self, value: u32) -> Self {
74 let mut new = self;
75 new.shard_number = Option::Some(Option::Some(value));
76 new
77 }
78 pub fn on_disk_payload(self, value: bool) -> Self {
80 let mut new = self;
81 new.on_disk_payload = Option::Some(Option::Some(value));
82 new
83 }
84 pub fn timeout(self, value: u64) -> Self {
86 let mut new = self;
87 new.timeout = Option::Some(Option::Some(value));
88 new
89 }
90 pub fn vectors_config<VALUE: core::convert::Into<VectorsConfig>>(self, value: VALUE) -> Self {
92 let mut new = self;
93 new.vectors_config = Option::Some(Option::Some(value.into()));
94 new
95 }
96 pub fn replication_factor(self, value: u32) -> Self {
98 let mut new = self;
99 new.replication_factor = Option::Some(Option::Some(value));
100 new
101 }
102 pub fn write_consistency_factor(self, value: u32) -> Self {
104 let mut new = self;
105 new.write_consistency_factor = Option::Some(Option::Some(value));
106 new
107 }
108 pub fn quantization_config<VALUE: core::convert::Into<quantization_config::Quantization>>(
110 self,
111 value: VALUE,
112 ) -> Self {
113 let mut new = self;
114 new.quantization_config = Option::Some(value.into());
115 new
116 }
117 pub fn sharding_method(self, value: i32) -> Self {
119 let mut new = self;
120 new.sharding_method = Option::Some(Option::Some(value));
121 new
122 }
123 pub fn sparse_vectors_config<VALUE: core::convert::Into<SparseVectorConfig>>(
125 self,
126 value: VALUE,
127 ) -> Self {
128 let mut new = self;
129 new.sparse_vectors_config = Option::Some(Option::Some(value.into()));
130 new
131 }
132 pub fn strict_mode_config<VALUE: core::convert::Into<StrictModeConfig>>(
134 self,
135 value: VALUE,
136 ) -> Self {
137 let mut new = self;
138 new.strict_mode_config = Option::Some(Option::Some(value.into()));
139 new
140 }
141 pub fn metadata(self, value: impl Into<MetadataWrapper>) -> Self {
143 let mut new = self;
144 new.metadata = Option::Some(value.into().0);
145 new
146 }
147
148 fn build_inner(self) -> Result<CreateCollection, std::convert::Infallible> {
149 Ok(CreateCollection {
150 collection_name: match self.collection_name {
151 Some(value) => value,
152 None => core::default::Default::default(),
153 },
154 hnsw_config: match self.hnsw_config {
155 Some(value) => value,
156 None => core::default::Default::default(),
157 },
158 wal_config: match self.wal_config {
159 Some(value) => value,
160 None => core::default::Default::default(),
161 },
162 optimizers_config: match self.optimizers_config {
163 Some(value) => value,
164 None => core::default::Default::default(),
165 },
166 shard_number: match self.shard_number {
167 Some(value) => value,
168 None => core::default::Default::default(),
169 },
170 on_disk_payload: match self.on_disk_payload {
171 Some(value) => value,
172 None => core::default::Default::default(),
173 },
174 timeout: match self.timeout {
175 Some(value) => value,
176 None => core::default::Default::default(),
177 },
178 vectors_config: match self.vectors_config {
179 Some(value) => value,
180 None => core::default::Default::default(),
181 },
182 replication_factor: match self.replication_factor {
183 Some(value) => value,
184 None => core::default::Default::default(),
185 },
186 write_consistency_factor: match self.write_consistency_factor {
187 Some(value) => value,
188 None => core::default::Default::default(),
189 },
190 quantization_config: { convert_option(&self.quantization_config) },
191 sharding_method: match self.sharding_method {
192 Some(value) => value,
193 None => core::default::Default::default(),
194 },
195 sparse_vectors_config: match self.sparse_vectors_config {
196 Some(value) => value,
197 None => core::default::Default::default(),
198 },
199 strict_mode_config: match self.strict_mode_config {
200 Some(value) => value,
201 None => core::default::Default::default(),
202 },
203 metadata: match self.metadata {
204 Some(value) => value,
205 None => core::default::Default::default(),
206 },
207 })
208 }
209 fn create_empty() -> Self {
211 Self {
212 collection_name: core::default::Default::default(),
213 hnsw_config: core::default::Default::default(),
214 wal_config: core::default::Default::default(),
215 optimizers_config: core::default::Default::default(),
216 shard_number: core::default::Default::default(),
217 on_disk_payload: core::default::Default::default(),
218 timeout: core::default::Default::default(),
219 vectors_config: core::default::Default::default(),
220 replication_factor: core::default::Default::default(),
221 write_consistency_factor: core::default::Default::default(),
222 quantization_config: core::default::Default::default(),
223 sharding_method: core::default::Default::default(),
224 sparse_vectors_config: core::default::Default::default(),
225 strict_mode_config: core::default::Default::default(),
226 metadata: core::default::Default::default(),
227 }
228 }
229}
230
231impl From<CreateCollectionBuilder> for CreateCollection {
232 fn from(value: CreateCollectionBuilder) -> Self {
233 value.build_inner().unwrap_or_else(|_| {
234 panic!(
235 "Failed to convert {0} to {1}",
236 "CreateCollectionBuilder", "CreateCollection"
237 )
238 })
239 }
240}
241
242impl CreateCollectionBuilder {
243 pub fn build(self) -> CreateCollection {
245 self.build_inner().unwrap_or_else(|_| {
246 panic!(
247 "Failed to build {0} into {1}",
248 "CreateCollectionBuilder", "CreateCollection"
249 )
250 })
251 }
252}
253
254impl Default for CreateCollectionBuilder {
255 fn default() -> Self {
256 Self::create_empty()
257 }
258}