qdrant_client/builders/
create_collection_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Debug, Clone)]
5pub struct CreateCollectionBuilder {
6    /// Name of the collection
7    pub(crate) collection_name: Option<String>,
8    /// Configuration of vector index
9    pub(crate) hnsw_config: Option<Option<HnswConfigDiff>>,
10    /// Configuration of the Write-Ahead-Log
11    pub(crate) wal_config: Option<Option<WalConfigDiff>>,
12    /// Configuration of the optimizers
13    pub(crate) optimizers_config: Option<Option<OptimizersConfigDiff>>,
14    /// Number of shards in the collection, default is 1 for standalone, otherwise equal to the number of nodes. Minimum is 1
15    pub(crate) shard_number: Option<Option<u32>>,
16    /// If true - point's payload will not be stored in memory
17    pub(crate) on_disk_payload: Option<Option<bool>>,
18    /// Wait timeout for operation commit in seconds, if not specified - default value will be supplied
19    pub(crate) timeout: Option<Option<u64>>,
20    /// Configuration for vectors
21    pub(crate) vectors_config: Option<Option<VectorsConfig>>,
22    /// Number of replicas of each shard that network tries to maintain, default = 1
23    pub(crate) replication_factor: Option<Option<u32>>,
24    /// How many replicas should apply the operation for us to consider it successful, default = 1
25    pub(crate) write_consistency_factor: Option<Option<u32>>,
26    /// Specify name of the other collection to copy data from
27    pub(crate) init_from_collection: Option<Option<String>>,
28    /// Quantization configuration of vector
29    quantization_config: Option<quantization_config::Quantization>,
30    /// Sharding method
31    pub(crate) sharding_method: Option<Option<i32>>,
32    /// Configuration for sparse vectors
33    pub(crate) sparse_vectors_config: Option<Option<SparseVectorConfig>>,
34    /// Configuration for strict mode
35    pub(crate) strict_mode_config: Option<Option<StrictModeConfig>>,
36}
37#[allow(clippy::all)]
38#[allow(clippy::derive_partial_eq_without_eq)]
39impl CreateCollectionBuilder {
40    /// Name of the collection
41    #[allow(unused_mut)]
42    pub fn collection_name<VALUE: Into<String>>(self, value: VALUE) -> Self {
43        let mut new = self;
44        new.collection_name = Option::Some(value.into());
45        new
46    }
47    /// Configuration of vector index
48    #[allow(unused_mut)]
49    pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
50        let mut new = self;
51        new.hnsw_config = Option::Some(Option::Some(value.into()));
52        new
53    }
54    /// Configuration of the Write-Ahead-Log
55    #[allow(unused_mut)]
56    pub fn wal_config<VALUE: core::convert::Into<WalConfigDiff>>(self, value: VALUE) -> Self {
57        let mut new = self;
58        new.wal_config = Option::Some(Option::Some(value.into()));
59        new
60    }
61    /// Configuration of the optimizers
62    #[allow(unused_mut)]
63    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    /// Number of shards in the collection, default is 1 for standalone, otherwise equal to the number of nodes. Minimum is 1
72    #[allow(unused_mut)]
73    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    /// If true - point's payload will not be stored in memory
79    #[allow(unused_mut)]
80    pub fn on_disk_payload(self, value: bool) -> Self {
81        let mut new = self;
82        new.on_disk_payload = Option::Some(Option::Some(value));
83        new
84    }
85    /// Wait timeout for operation commit in seconds, if not specified - default value will be supplied
86    #[allow(unused_mut)]
87    pub fn timeout(self, value: u64) -> Self {
88        let mut new = self;
89        new.timeout = Option::Some(Option::Some(value));
90        new
91    }
92    /// Configuration for vectors
93    #[allow(unused_mut)]
94    pub fn vectors_config<VALUE: core::convert::Into<VectorsConfig>>(self, value: VALUE) -> Self {
95        let mut new = self;
96        new.vectors_config = Option::Some(Option::Some(value.into()));
97        new
98    }
99    /// Number of replicas of each shard that network tries to maintain, default = 1
100    #[allow(unused_mut)]
101    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    /// How many replicas should apply the operation for us to consider it successful, default = 1
107    #[allow(unused_mut)]
108    pub fn write_consistency_factor(self, value: u32) -> Self {
109        let mut new = self;
110        new.write_consistency_factor = Option::Some(Option::Some(value));
111        new
112    }
113    /// Specify name of the other collection to copy data from
114    #[allow(unused_mut)]
115    pub fn init_from_collection<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
116        let mut new = self;
117        new.init_from_collection = Option::Some(Option::Some(value.into()));
118        new
119    }
120    /// Quantization configuration of vector
121    #[allow(unused_mut)]
122    pub fn quantization_config<VALUE: core::convert::Into<quantization_config::Quantization>>(
123        self,
124        value: VALUE,
125    ) -> Self {
126        let mut new = self;
127        new.quantization_config = Option::Some(value.into());
128        new
129    }
130    /// Sharding method
131    #[allow(unused_mut)]
132    pub fn sharding_method(self, value: i32) -> Self {
133        let mut new = self;
134        new.sharding_method = Option::Some(Option::Some(value));
135        new
136    }
137    /// Configuration for sparse vectors
138    #[allow(unused_mut)]
139    pub fn sparse_vectors_config<VALUE: core::convert::Into<SparseVectorConfig>>(
140        self,
141        value: VALUE,
142    ) -> Self {
143        let mut new = self;
144        new.sparse_vectors_config = Option::Some(Option::Some(value.into()));
145        new
146    }
147    /// Configuration for strict mode
148    #[allow(unused_mut)]
149    pub fn strict_mode_config<VALUE: core::convert::Into<StrictModeConfig>>(
150        self,
151        value: VALUE,
152    ) -> Self {
153        let mut new = self;
154        new.strict_mode_config = Option::Some(Option::Some(value.into()));
155        new
156    }
157
158    fn build_inner(self) -> Result<CreateCollection, std::convert::Infallible> {
159        Ok(CreateCollection {
160            collection_name: match self.collection_name {
161                Some(value) => value,
162                None => core::default::Default::default(),
163            },
164            hnsw_config: match self.hnsw_config {
165                Some(value) => value,
166                None => core::default::Default::default(),
167            },
168            wal_config: match self.wal_config {
169                Some(value) => value,
170                None => core::default::Default::default(),
171            },
172            optimizers_config: match self.optimizers_config {
173                Some(value) => value,
174                None => core::default::Default::default(),
175            },
176            shard_number: match self.shard_number {
177                Some(value) => value,
178                None => core::default::Default::default(),
179            },
180            on_disk_payload: match self.on_disk_payload {
181                Some(value) => value,
182                None => core::default::Default::default(),
183            },
184            timeout: match self.timeout {
185                Some(value) => value,
186                None => core::default::Default::default(),
187            },
188            vectors_config: match self.vectors_config {
189                Some(value) => value,
190                None => core::default::Default::default(),
191            },
192            replication_factor: match self.replication_factor {
193                Some(value) => value,
194                None => core::default::Default::default(),
195            },
196            write_consistency_factor: match self.write_consistency_factor {
197                Some(value) => value,
198                None => core::default::Default::default(),
199            },
200            init_from_collection: match self.init_from_collection {
201                Some(value) => value,
202                None => core::default::Default::default(),
203            },
204            quantization_config: { convert_option(&self.quantization_config) },
205            sharding_method: match self.sharding_method {
206                Some(value) => value,
207                None => core::default::Default::default(),
208            },
209            sparse_vectors_config: match self.sparse_vectors_config {
210                Some(value) => value,
211                None => core::default::Default::default(),
212            },
213            strict_mode_config: match self.strict_mode_config {
214                Some(value) => value,
215                None => core::default::Default::default(),
216            },
217        })
218    }
219    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
220    fn create_empty() -> Self {
221        Self {
222            collection_name: core::default::Default::default(),
223            hnsw_config: core::default::Default::default(),
224            wal_config: core::default::Default::default(),
225            optimizers_config: core::default::Default::default(),
226            shard_number: core::default::Default::default(),
227            on_disk_payload: core::default::Default::default(),
228            timeout: core::default::Default::default(),
229            vectors_config: core::default::Default::default(),
230            replication_factor: core::default::Default::default(),
231            write_consistency_factor: core::default::Default::default(),
232            init_from_collection: core::default::Default::default(),
233            quantization_config: core::default::Default::default(),
234            sharding_method: core::default::Default::default(),
235            sparse_vectors_config: core::default::Default::default(),
236            strict_mode_config: core::default::Default::default(),
237        }
238    }
239}
240
241impl From<CreateCollectionBuilder> for CreateCollection {
242    fn from(value: CreateCollectionBuilder) -> Self {
243        value.build_inner().unwrap_or_else(|_| {
244            panic!(
245                "Failed to convert {0} to {1}",
246                "CreateCollectionBuilder", "CreateCollection"
247            )
248        })
249    }
250}
251
252impl CreateCollectionBuilder {
253    /// Builds the desired type. Can often be omitted.
254    pub fn build(self) -> CreateCollection {
255        self.build_inner().unwrap_or_else(|_| {
256            panic!(
257                "Failed to build {0} into {1}",
258                "CreateCollectionBuilder", "CreateCollection"
259            )
260        })
261    }
262}
263
264impl Default for CreateCollectionBuilder {
265    fn default() -> Self {
266        Self::create_empty()
267    }
268}