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