1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct SearchPointGroupsBuilder {
7 pub(crate) collection_name: Option<String>,
9 pub(crate) vector: Option<Vec<f32>>,
11 pub(crate) filter: Option<Option<Filter>>,
13 pub(crate) limit: Option<u32>,
15 with_payload: Option<with_payload_selector::SelectorOptions>,
17 pub(crate) params: Option<Option<SearchParams>>,
19 pub(crate) score_threshold: Option<Option<f32>>,
21 pub(crate) vector_name: Option<Option<String>>,
23 with_vectors: Option<with_vectors_selector::SelectorOptions>,
25 pub(crate) group_by: Option<String>,
27 pub(crate) group_size: Option<u32>,
29 read_consistency: Option<read_consistency::Value>,
31 pub(crate) with_lookup: Option<Option<WithLookup>>,
33 pub(crate) timeout: Option<Option<u64>>,
35 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
37 pub(crate) sparse_indices: Option<Option<SparseIndices>>,
38}
39
40impl SearchPointGroupsBuilder {
41 pub fn collection_name(self, value: String) -> Self {
43 let mut new = self;
44 new.collection_name = Option::Some(value);
45 new
46 }
47 pub fn vector(self, value: Vec<f32>) -> Self {
49 let mut new = self;
50 new.vector = Option::Some(value);
51 new
52 }
53 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
55 let mut new = self;
56 new.filter = Option::Some(Option::Some(value.into()));
57 new
58 }
59 pub fn limit(self, value: u32) -> Self {
61 let mut new = self;
62 new.limit = Option::Some(value);
63 new
64 }
65 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
67 self,
68 value: VALUE,
69 ) -> Self {
70 let mut new = self;
71 new.with_payload = Option::Some(value.into());
72 new
73 }
74 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
76 let mut new = self;
77 new.params = Option::Some(Option::Some(value.into()));
78 new
79 }
80 pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
82 let mut new = self;
83 new.score_threshold = Option::Some(Option::Some(value.into()));
84 new
85 }
86 pub fn vector_name<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
88 let mut new = self;
89 new.vector_name = Option::Some(Option::Some(value.into()));
90 new
91 }
92 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
94 self,
95 value: VALUE,
96 ) -> Self {
97 let mut new = self;
98 new.with_vectors = Option::Some(value.into());
99 new
100 }
101 pub fn group_by(self, value: String) -> Self {
103 let mut new = self;
104 new.group_by = Option::Some(value);
105 new
106 }
107 pub fn group_size(self, value: u32) -> Self {
109 let mut new = self;
110 new.group_size = Option::Some(value);
111 new
112 }
113 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
115 self,
116 value: VALUE,
117 ) -> Self {
118 let mut new = self;
119 new.read_consistency = Option::Some(value.into());
120 new
121 }
122 pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
124 let mut new = self;
125 new.with_lookup = Option::Some(Option::Some(value.into()));
126 new
127 }
128 pub fn timeout<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
130 let mut new = self;
131 new.timeout = Option::Some(Option::Some(value.into()));
132 new
133 }
134 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
136 self,
137 value: VALUE,
138 ) -> Self {
139 let mut new = self;
140 new.shard_key_selector = Option::Some(Option::Some(value.into()));
141 new
142 }
143 pub fn sparse_indices<VALUE: core::convert::Into<SparseIndices>>(self, value: VALUE) -> Self {
144 let mut new = self;
145 new.sparse_indices = Option::Some(Option::Some(value.into()));
146 new
147 }
148
149 fn build_inner(self) -> Result<SearchPointGroups, SearchPointGroupsBuilderError> {
150 Ok(SearchPointGroups {
151 collection_name: match self.collection_name {
152 Some(value) => value,
153 None => {
154 return Result::Err(core::convert::Into::into(
155 ::derive_builder::UninitializedFieldError::from("collection_name"),
156 ));
157 }
158 },
159 vector: match self.vector {
160 Some(value) => value,
161 None => {
162 return Result::Err(core::convert::Into::into(
163 ::derive_builder::UninitializedFieldError::from("vector"),
164 ));
165 }
166 },
167 filter: self.filter.unwrap_or_default(),
168 limit: match self.limit {
169 Some(value) => value,
170 None => {
171 return Result::Err(core::convert::Into::into(
172 ::derive_builder::UninitializedFieldError::from("limit"),
173 ));
174 }
175 },
176 with_payload: { convert_option(&self.with_payload) },
177 params: self.params.unwrap_or_default(),
178 score_threshold: self.score_threshold.unwrap_or_default(),
179 vector_name: self.vector_name.unwrap_or_default(),
180 with_vectors: { convert_option(&self.with_vectors) },
181 group_by: match self.group_by {
182 Some(value) => value,
183 None => {
184 return Result::Err(core::convert::Into::into(
185 ::derive_builder::UninitializedFieldError::from("group_by"),
186 ));
187 }
188 },
189 group_size: match self.group_size {
190 Some(value) => value,
191 None => {
192 return Result::Err(core::convert::Into::into(
193 ::derive_builder::UninitializedFieldError::from("group_size"),
194 ));
195 }
196 },
197 read_consistency: { convert_option(&self.read_consistency) },
198 with_lookup: self.with_lookup.unwrap_or_default(),
199 timeout: self.timeout.unwrap_or_default(),
200 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
201 sparse_indices: self.sparse_indices.unwrap_or_default(),
202 })
203 }
204 fn create_empty() -> Self {
206 Self {
207 collection_name: core::default::Default::default(),
208 vector: core::default::Default::default(),
209 filter: core::default::Default::default(),
210 limit: core::default::Default::default(),
211 with_payload: core::default::Default::default(),
212 params: core::default::Default::default(),
213 score_threshold: core::default::Default::default(),
214 vector_name: core::default::Default::default(),
215 with_vectors: core::default::Default::default(),
216 group_by: core::default::Default::default(),
217 group_size: core::default::Default::default(),
218 read_consistency: core::default::Default::default(),
219 with_lookup: core::default::Default::default(),
220 timeout: core::default::Default::default(),
221 shard_key_selector: core::default::Default::default(),
222 sparse_indices: core::default::Default::default(),
223 }
224 }
225}
226
227impl From<SearchPointGroupsBuilder> for SearchPointGroups {
228 fn from(value: SearchPointGroupsBuilder) -> Self {
229 value.build_inner().unwrap_or_else(|_| {
230 panic!(
231 "Failed to convert {0} to {1}",
232 "SearchPointGroupsBuilder", "SearchPointGroups"
233 )
234 })
235 }
236}
237
238impl SearchPointGroupsBuilder {
239 pub fn build(self) -> SearchPointGroups {
241 self.build_inner().unwrap_or_else(|_| {
242 panic!(
243 "Failed to build {0} into {1}",
244 "SearchPointGroupsBuilder", "SearchPointGroups"
245 )
246 })
247 }
248}
249
250impl SearchPointGroupsBuilder {
251 pub(crate) fn empty() -> Self {
252 Self::create_empty()
253 }
254}
255
256#[non_exhaustive]
259#[derive(Debug)]
260pub enum SearchPointGroupsBuilderError {
261 UninitializedField(&'static str),
263 ValidationError(String),
265}
266
267impl std::fmt::Display for SearchPointGroupsBuilderError {
269 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
270 match self {
271 Self::UninitializedField(field) => {
272 write!(f, "`{field}` must be initialized")
273 }
274 Self::ValidationError(error) => write!(f, "{error}"),
275 }
276 }
277}
278
279impl std::error::Error for SearchPointGroupsBuilderError {}
281
282impl From<derive_builder::UninitializedFieldError> for SearchPointGroupsBuilderError {
284 fn from(error: derive_builder::UninitializedFieldError) -> Self {
285 Self::UninitializedField(error.field_name())
286 }
287}
288
289impl From<String> for SearchPointGroupsBuilderError {
291 fn from(error: String) -> Self {
292 Self::ValidationError(error)
293 }
294}