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