1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct RecommendPointGroupsBuilder {
6 pub(crate) collection_name: Option<String>,
8 pub(crate) positive: Option<Vec<PointId>>,
10 pub(crate) negative: Option<Vec<PointId>>,
12 pub(crate) filter: Option<Option<Filter>>,
14 pub(crate) limit: Option<u32>,
16 with_payload: Option<with_payload_selector::SelectorOptions>,
18 pub(crate) params: Option<Option<SearchParams>>,
20 pub(crate) score_threshold: Option<Option<f32>>,
22 pub(crate) using: Option<Option<String>>,
24 with_vectors: Option<with_vectors_selector::SelectorOptions>,
26 pub(crate) lookup_from: Option<Option<LookupLocation>>,
28 pub(crate) group_by: Option<String>,
30 pub(crate) group_size: Option<u32>,
32 read_consistency: Option<read_consistency::Value>,
34 pub(crate) with_lookup: Option<Option<WithLookup>>,
36 pub(crate) strategy: Option<Option<i32>>,
38 pub(crate) positive_vectors: Option<Vec<Vector>>,
40 pub(crate) negative_vectors: Option<Vec<Vector>>,
42 pub(crate) timeout: Option<Option<u64>>,
44 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
46}
47
48impl RecommendPointGroupsBuilder {
49 #[allow(unused_mut)]
51 pub fn collection_name(self, value: String) -> Self {
52 let mut new = self;
53 new.collection_name = Option::Some(value);
54 new
55 }
56 #[allow(unused_mut)]
58 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
59 let mut new = self;
60 new.filter = Option::Some(Option::Some(value.into()));
61 new
62 }
63 #[allow(unused_mut)]
65 pub fn limit(self, value: u32) -> Self {
66 let mut new = self;
67 new.limit = Option::Some(value);
68 new
69 }
70 #[allow(unused_mut)]
72 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
73 self,
74 value: VALUE,
75 ) -> Self {
76 let mut new = self;
77 new.with_payload = Option::Some(value.into());
78 new
79 }
80 #[allow(unused_mut)]
82 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
83 let mut new = self;
84 new.params = Option::Some(Option::Some(value.into()));
85 new
86 }
87 #[allow(unused_mut)]
89 pub fn score_threshold(self, value: f32) -> Self {
90 let mut new = self;
91 new.score_threshold = Option::Some(Option::Some(value));
92 new
93 }
94 #[allow(unused_mut)]
96 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
97 let mut new = self;
98 new.using = Option::Some(Option::Some(value.into()));
99 new
100 }
101 #[allow(unused_mut)]
103 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
104 self,
105 value: VALUE,
106 ) -> Self {
107 let mut new = self;
108 new.with_vectors = Option::Some(value.into());
109 new
110 }
111 #[allow(unused_mut)]
113 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
114 let mut new = self;
115 new.lookup_from = Option::Some(Option::Some(value.into()));
116 new
117 }
118 #[allow(unused_mut)]
120 pub fn group_by(self, value: String) -> Self {
121 let mut new = self;
122 new.group_by = Option::Some(value);
123 new
124 }
125 #[allow(unused_mut)]
127 pub fn group_size(self, value: u32) -> Self {
128 let mut new = self;
129 new.group_size = Option::Some(value);
130 new
131 }
132 #[allow(unused_mut)]
134 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
135 self,
136 value: VALUE,
137 ) -> Self {
138 let mut new = self;
139 new.read_consistency = Option::Some(value.into());
140 new
141 }
142 #[allow(unused_mut)]
144 pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
145 let mut new = self;
146 new.with_lookup = Option::Some(Option::Some(value.into()));
147 new
148 }
149 #[allow(unused_mut)]
151 pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
152 let mut new = self;
153 new.strategy = Option::Some(Option::Some(value.into()));
154 new
155 }
156 #[allow(unused_mut)]
158 pub fn timeout(self, value: u64) -> Self {
159 let mut new = self;
160 new.timeout = Option::Some(Option::Some(value));
161 new
162 }
163 #[allow(unused_mut)]
165 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
166 self,
167 value: VALUE,
168 ) -> Self {
169 let mut new = self;
170 new.shard_key_selector = Option::Some(Option::Some(value.into()));
171 new
172 }
173
174 fn build_inner(self) -> Result<RecommendPointGroups, RecommendPointGroupsBuilderError> {
175 Ok(RecommendPointGroups {
176 collection_name: match self.collection_name {
177 Some(value) => value,
178 None => {
179 return Result::Err(core::convert::Into::into(
180 ::derive_builder::UninitializedFieldError::from("collection_name"),
181 ));
182 }
183 },
184 positive: self.positive.unwrap_or_default(),
185 negative: self.negative.unwrap_or_default(),
186 filter: self.filter.unwrap_or_default(),
187 limit: match self.limit {
188 Some(value) => value,
189 None => {
190 return Result::Err(core::convert::Into::into(
191 ::derive_builder::UninitializedFieldError::from("limit"),
192 ));
193 }
194 },
195 with_payload: { convert_option(&self.with_payload) },
196 params: self.params.unwrap_or_default(),
197 score_threshold: self.score_threshold.unwrap_or_default(),
198 using: self.using.unwrap_or_default(),
199 with_vectors: { convert_option(&self.with_vectors) },
200 lookup_from: self.lookup_from.unwrap_or_default(),
201 group_by: match self.group_by {
202 Some(value) => value,
203 None => {
204 return Result::Err(core::convert::Into::into(
205 ::derive_builder::UninitializedFieldError::from("group_by"),
206 ));
207 }
208 },
209 group_size: match self.group_size {
210 Some(value) => value,
211 None => {
212 return Result::Err(core::convert::Into::into(
213 ::derive_builder::UninitializedFieldError::from("group_size"),
214 ));
215 }
216 },
217 read_consistency: { convert_option(&self.read_consistency) },
218 with_lookup: self.with_lookup.unwrap_or_default(),
219 strategy: self.strategy.unwrap_or_default(),
220 positive_vectors: self.positive_vectors.unwrap_or_default(),
221 negative_vectors: self.negative_vectors.unwrap_or_default(),
222 timeout: self.timeout.unwrap_or_default(),
223 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
224 })
225 }
226 fn create_empty() -> Self {
228 Self {
229 collection_name: core::default::Default::default(),
230 positive: core::default::Default::default(),
231 negative: core::default::Default::default(),
232 filter: core::default::Default::default(),
233 limit: core::default::Default::default(),
234 with_payload: core::default::Default::default(),
235 params: core::default::Default::default(),
236 score_threshold: core::default::Default::default(),
237 using: core::default::Default::default(),
238 with_vectors: core::default::Default::default(),
239 lookup_from: core::default::Default::default(),
240 group_by: core::default::Default::default(),
241 group_size: core::default::Default::default(),
242 read_consistency: core::default::Default::default(),
243 with_lookup: core::default::Default::default(),
244 strategy: core::default::Default::default(),
245 positive_vectors: core::default::Default::default(),
246 negative_vectors: core::default::Default::default(),
247 timeout: core::default::Default::default(),
248 shard_key_selector: core::default::Default::default(),
249 }
250 }
251}
252
253impl From<RecommendPointGroupsBuilder> for RecommendPointGroups {
254 fn from(value: RecommendPointGroupsBuilder) -> Self {
255 value.build_inner().unwrap_or_else(|_| {
256 panic!(
257 "Failed to convert {0} to {1}",
258 "RecommendPointGroupsBuilder", "RecommendPointGroups"
259 )
260 })
261 }
262}
263
264impl RecommendPointGroupsBuilder {
265 pub fn build(self) -> RecommendPointGroups {
267 self.build_inner().unwrap_or_else(|_| {
268 panic!(
269 "Failed to build {0} into {1}",
270 "RecommendPointGroupsBuilder", "RecommendPointGroups"
271 )
272 })
273 }
274}
275
276impl RecommendPointGroupsBuilder {
277 pub(crate) fn empty() -> Self {
278 Self::create_empty()
279 }
280}
281
282#[non_exhaustive]
284#[derive(Debug)]
285pub enum RecommendPointGroupsBuilderError {
286 UninitializedField(&'static str),
288 ValidationError(String),
290}
291
292impl std::fmt::Display for RecommendPointGroupsBuilderError {
294 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
295 match self {
296 Self::UninitializedField(field) => {
297 write!(f, "`{field}` must be initialized")
298 }
299 Self::ValidationError(error) => write!(f, "{error}"),
300 }
301 }
302}
303
304impl std::error::Error for RecommendPointGroupsBuilderError {}
306
307impl From<derive_builder::UninitializedFieldError> for RecommendPointGroupsBuilderError {
309 fn from(error: derive_builder::UninitializedFieldError) -> Self {
310 Self::UninitializedField(error.field_name())
311 }
312}
313
314impl From<String> for RecommendPointGroupsBuilderError {
316 fn from(error: String) -> Self {
317 Self::ValidationError(error)
318 }
319}