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