qdrant_client/builders/
update_collection_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct UpdateCollectionBuilder {
6 pub(crate) collection_name: Option<String>,
8 pub(crate) optimizers_config: Option<Option<OptimizersConfigDiff>>,
10 pub(crate) timeout: Option<Option<u64>>,
12 pub(crate) params: Option<Option<CollectionParamsDiff>>,
14 pub(crate) hnsw_config: Option<Option<HnswConfigDiff>>,
16 pub(crate) vectors_config: Option<Option<VectorsConfigDiff>>,
18 quantization_config: Option<quantization_config_diff::Quantization>,
20 pub(crate) sparse_vectors_config: Option<Option<SparseVectorConfig>>,
22 pub(crate) strict_mode_config: Option<Option<StrictModeConfig>>,
24}
25
26impl UpdateCollectionBuilder {
27 #[allow(unused_mut)]
29 pub fn collection_name(self, value: String) -> Self {
30 let mut new = self;
31 new.collection_name = Option::Some(value);
32 new
33 }
34 #[allow(unused_mut)]
36 pub fn optimizers_config<VALUE: core::convert::Into<OptimizersConfigDiff>>(
37 self,
38 value: VALUE,
39 ) -> Self {
40 let mut new = self;
41 new.optimizers_config = Option::Some(Option::Some(value.into()));
42 new
43 }
44 #[allow(unused_mut)]
46 pub fn timeout(self, value: u64) -> Self {
47 let mut new = self;
48 new.timeout = Option::Some(Option::Some(value));
49 new
50 }
51 #[allow(unused_mut)]
53 pub fn params<VALUE: core::convert::Into<CollectionParamsDiff>>(self, value: VALUE) -> Self {
54 let mut new = self;
55 new.params = Option::Some(Option::Some(value.into()));
56 new
57 }
58 #[allow(unused_mut)]
60 pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
61 let mut new = self;
62 new.hnsw_config = Option::Some(Option::Some(value.into()));
63 new
64 }
65 #[allow(unused_mut)]
67 pub fn vectors_config<VALUE: core::convert::Into<VectorsConfigDiff>>(
68 self,
69 value: VALUE,
70 ) -> Self {
71 let mut new = self;
72 new.vectors_config = Option::Some(Option::Some(value.into()));
73 new
74 }
75 #[allow(unused_mut)]
77 pub fn quantization_config<
78 VALUE: core::convert::Into<quantization_config_diff::Quantization>,
79 >(
80 self,
81 value: VALUE,
82 ) -> Self {
83 let mut new = self;
84 new.quantization_config = Option::Some(value.into());
85 new
86 }
87 #[allow(unused_mut)]
89 pub fn sparse_vectors_config<VALUE: core::convert::Into<SparseVectorConfig>>(
90 self,
91 value: VALUE,
92 ) -> Self {
93 let mut new = self;
94 new.sparse_vectors_config = Option::Some(Option::Some(value.into()));
95 new
96 }
97 #[allow(unused_mut)]
99 pub fn strict_mode_config<VALUE: core::convert::Into<StrictModeConfig>>(
100 self,
101 value: VALUE,
102 ) -> Self {
103 let mut new = self;
104 new.strict_mode_config = Option::Some(Option::Some(value.into()));
105 new
106 }
107
108 fn build_inner(self) -> Result<UpdateCollection, UpdateCollectionBuilderError> {
109 Ok(UpdateCollection {
110 collection_name: match self.collection_name {
111 Some(value) => value,
112 None => {
113 return Result::Err(core::convert::Into::into(
114 ::derive_builder::UninitializedFieldError::from("collection_name"),
115 ));
116 }
117 },
118 optimizers_config: self.optimizers_config.unwrap_or_default(),
119 timeout: self.timeout.unwrap_or_default(),
120 params: self.params.unwrap_or_default(),
121 hnsw_config: self.hnsw_config.unwrap_or_default(),
122 vectors_config: self.vectors_config.unwrap_or_default(),
123 quantization_config: { convert_option(&self.quantization_config) },
124 sparse_vectors_config: self.sparse_vectors_config.unwrap_or_default(),
125 strict_mode_config: self.strict_mode_config.unwrap_or_default(),
126 })
127 }
128 fn create_empty() -> Self {
130 Self {
131 collection_name: core::default::Default::default(),
132 optimizers_config: core::default::Default::default(),
133 timeout: core::default::Default::default(),
134 params: core::default::Default::default(),
135 hnsw_config: core::default::Default::default(),
136 vectors_config: core::default::Default::default(),
137 quantization_config: core::default::Default::default(),
138 sparse_vectors_config: core::default::Default::default(),
139 strict_mode_config: core::default::Default::default(),
140 }
141 }
142}
143
144impl From<UpdateCollectionBuilder> for UpdateCollection {
145 fn from(value: UpdateCollectionBuilder) -> Self {
146 value.build_inner().unwrap_or_else(|_| {
147 panic!(
148 "Failed to convert {0} to {1}",
149 "UpdateCollectionBuilder", "UpdateCollection"
150 )
151 })
152 }
153}
154
155impl UpdateCollectionBuilder {
156 pub fn build(self) -> UpdateCollection {
158 self.build_inner().unwrap_or_else(|_| {
159 panic!(
160 "Failed to build {0} into {1}",
161 "UpdateCollectionBuilder", "UpdateCollection"
162 )
163 })
164 }
165}
166
167impl UpdateCollectionBuilder {
168 pub(crate) fn empty() -> Self {
169 Self::create_empty()
170 }
171}
172
173#[non_exhaustive]
174#[derive(Debug)]
175pub enum UpdateCollectionBuilderError {
176 UninitializedField(&'static str),
178 ValidationError(String),
180}
181
182impl std::fmt::Display for UpdateCollectionBuilderError {
184 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
185 match self {
186 Self::UninitializedField(field) => {
187 write!(f, "`{field}` must be initialized")
188 }
189 Self::ValidationError(error) => write!(f, "{error}"),
190 }
191 }
192}
193
194impl std::error::Error for UpdateCollectionBuilderError {}
196
197impl From<derive_builder::UninitializedFieldError> for UpdateCollectionBuilderError {
199 fn from(error: derive_builder::UninitializedFieldError) -> Self {
200 Self::UninitializedField(error.field_name())
201 }
202}
203
204impl From<String> for UpdateCollectionBuilderError {
206 fn from(error: String) -> Self {
207 Self::ValidationError(error)
208 }
209}