qdrant_client/builders/
update_collection_builder.rs1use crate::grpc_conversions::metadata::MetadataWrapper;
2use crate::grpc_macros::convert_option;
3use crate::qdrant::*;
4
5#[derive(Clone)]
6pub struct UpdateCollectionBuilder {
7 pub(crate) collection_name: Option<String>,
9 pub(crate) optimizers_config: Option<Option<OptimizersConfigDiff>>,
11 pub(crate) timeout: Option<Option<u64>>,
13 pub(crate) params: Option<Option<CollectionParamsDiff>>,
15 pub(crate) hnsw_config: Option<Option<HnswConfigDiff>>,
17 pub(crate) vectors_config: Option<Option<VectorsConfigDiff>>,
19 quantization_config: Option<quantization_config_diff::Quantization>,
21 pub(crate) sparse_vectors_config: Option<Option<SparseVectorConfig>>,
23 pub(crate) strict_mode_config: Option<Option<StrictModeConfig>>,
25 pub(crate) metadata: Option<std::collections::HashMap<String, Value>>,
27}
28
29impl UpdateCollectionBuilder {
30 pub fn collection_name(self, value: String) -> Self {
32 let mut new = self;
33 new.collection_name = Option::Some(value);
34 new
35 }
36 pub fn optimizers_config<VALUE: core::convert::Into<OptimizersConfigDiff>>(
38 self,
39 value: VALUE,
40 ) -> Self {
41 let mut new = self;
42 new.optimizers_config = Option::Some(Option::Some(value.into()));
43 new
44 }
45 pub fn timeout(self, value: u64) -> Self {
47 let mut new = self;
48 new.timeout = Option::Some(Option::Some(value));
49 new
50 }
51 pub fn params<VALUE: core::convert::Into<CollectionParamsDiff>>(self, value: VALUE) -> Self {
53 let mut new = self;
54 new.params = Option::Some(Option::Some(value.into()));
55 new
56 }
57 pub fn hnsw_config<VALUE: core::convert::Into<HnswConfigDiff>>(self, value: VALUE) -> Self {
59 let mut new = self;
60 new.hnsw_config = Option::Some(Option::Some(value.into()));
61 new
62 }
63 pub fn vectors_config<VALUE: core::convert::Into<VectorsConfigDiff>>(
65 self,
66 value: VALUE,
67 ) -> Self {
68 let mut new = self;
69 new.vectors_config = Option::Some(Option::Some(value.into()));
70 new
71 }
72 pub fn quantization_config<
74 VALUE: core::convert::Into<quantization_config_diff::Quantization>,
75 >(
76 self,
77 value: VALUE,
78 ) -> Self {
79 let mut new = self;
80 new.quantization_config = Option::Some(value.into());
81 new
82 }
83 pub fn sparse_vectors_config<VALUE: core::convert::Into<SparseVectorConfig>>(
85 self,
86 value: VALUE,
87 ) -> Self {
88 let mut new = self;
89 new.sparse_vectors_config = Option::Some(Option::Some(value.into()));
90 new
91 }
92 pub fn strict_mode_config<VALUE: core::convert::Into<StrictModeConfig>>(
94 self,
95 value: VALUE,
96 ) -> Self {
97 let mut new = self;
98 new.strict_mode_config = Option::Some(Option::Some(value.into()));
99 new
100 }
101 pub fn metadata(self, value: impl Into<MetadataWrapper>) -> Self {
103 let mut new = self;
104 new.metadata = Option::Some(value.into().0);
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 metadata: self.metadata.unwrap_or_default(),
127 })
128 }
129 fn create_empty() -> Self {
131 Self {
132 collection_name: core::default::Default::default(),
133 optimizers_config: core::default::Default::default(),
134 timeout: core::default::Default::default(),
135 params: core::default::Default::default(),
136 hnsw_config: core::default::Default::default(),
137 vectors_config: core::default::Default::default(),
138 quantization_config: core::default::Default::default(),
139 sparse_vectors_config: core::default::Default::default(),
140 strict_mode_config: core::default::Default::default(),
141 metadata: core::default::Default::default(),
142 }
143 }
144}
145
146impl From<UpdateCollectionBuilder> for UpdateCollection {
147 fn from(value: UpdateCollectionBuilder) -> Self {
148 value.build_inner().unwrap_or_else(|_| {
149 panic!(
150 "Failed to convert {0} to {1}",
151 "UpdateCollectionBuilder", "UpdateCollection"
152 )
153 })
154 }
155}
156
157impl UpdateCollectionBuilder {
158 pub fn build(self) -> UpdateCollection {
160 self.build_inner().unwrap_or_else(|_| {
161 panic!(
162 "Failed to build {0} into {1}",
163 "UpdateCollectionBuilder", "UpdateCollection"
164 )
165 })
166 }
167}
168
169impl UpdateCollectionBuilder {
170 pub(crate) fn empty() -> Self {
171 Self::create_empty()
172 }
173}
174
175#[non_exhaustive]
176#[derive(Debug)]
177pub enum UpdateCollectionBuilderError {
178 UninitializedField(&'static str),
180 ValidationError(String),
182}
183
184impl std::fmt::Display for UpdateCollectionBuilderError {
186 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
187 match self {
188 Self::UninitializedField(field) => {
189 write!(f, "`{field}` must be initialized")
190 }
191 Self::ValidationError(error) => write!(f, "{error}"),
192 }
193 }
194}
195
196impl std::error::Error for UpdateCollectionBuilderError {}
198
199impl From<derive_builder::UninitializedFieldError> for UpdateCollectionBuilderError {
201 fn from(error: derive_builder::UninitializedFieldError) -> Self {
202 Self::UninitializedField(error.field_name())
203 }
204}
205
206impl From<String> for UpdateCollectionBuilderError {
208 fn from(error: String) -> Self {
209 Self::ValidationError(error)
210 }
211}