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 pub fn collection_name(self, value: String) -> Self {
51 let mut new = self;
52 new.collection_name = Option::Some(value);
53 new
54 }
55 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
57 let mut new = self;
58 new.filter = Option::Some(Option::Some(value.into()));
59 new
60 }
61 pub fn limit(self, value: u32) -> Self {
63 let mut new = self;
64 new.limit = Option::Some(value);
65 new
66 }
67 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
69 self,
70 value: VALUE,
71 ) -> Self {
72 let mut new = self;
73 new.with_payload = Option::Some(value.into());
74 new
75 }
76 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
78 let mut new = self;
79 new.params = Option::Some(Option::Some(value.into()));
80 new
81 }
82 pub fn score_threshold(self, value: f32) -> Self {
84 let mut new = self;
85 new.score_threshold = Option::Some(Option::Some(value));
86 new
87 }
88 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
90 let mut new = self;
91 new.using = Option::Some(Option::Some(value.into()));
92 new
93 }
94 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
96 self,
97 value: VALUE,
98 ) -> Self {
99 let mut new = self;
100 new.with_vectors = Option::Some(value.into());
101 new
102 }
103 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
105 let mut new = self;
106 new.lookup_from = Option::Some(Option::Some(value.into()));
107 new
108 }
109 pub fn group_by(self, value: String) -> Self {
111 let mut new = self;
112 new.group_by = Option::Some(value);
113 new
114 }
115 pub fn group_size(self, value: u32) -> Self {
117 let mut new = self;
118 new.group_size = Option::Some(value);
119 new
120 }
121 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
123 self,
124 value: VALUE,
125 ) -> Self {
126 let mut new = self;
127 new.read_consistency = Option::Some(value.into());
128 new
129 }
130 pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
132 let mut new = self;
133 new.with_lookup = Option::Some(Option::Some(value.into()));
134 new
135 }
136 pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
138 let mut new = self;
139 new.strategy = Option::Some(Option::Some(value.into()));
140 new
141 }
142 pub fn timeout(self, value: u64) -> Self {
144 let mut new = self;
145 new.timeout = Option::Some(Option::Some(value));
146 new
147 }
148 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
150 self,
151 value: VALUE,
152 ) -> Self {
153 let mut new = self;
154 new.shard_key_selector = Option::Some(Option::Some(value.into()));
155 new
156 }
157
158 fn build_inner(self) -> Result<RecommendPointGroups, RecommendPointGroupsBuilderError> {
159 Ok(RecommendPointGroups {
160 collection_name: match self.collection_name {
161 Some(value) => value,
162 None => {
163 return Result::Err(core::convert::Into::into(
164 ::derive_builder::UninitializedFieldError::from("collection_name"),
165 ));
166 }
167 },
168 positive: self.positive.unwrap_or_default(),
169 negative: self.negative.unwrap_or_default(),
170 filter: self.filter.unwrap_or_default(),
171 limit: match self.limit {
172 Some(value) => value,
173 None => {
174 return Result::Err(core::convert::Into::into(
175 ::derive_builder::UninitializedFieldError::from("limit"),
176 ));
177 }
178 },
179 with_payload: { convert_option(&self.with_payload) },
180 params: self.params.unwrap_or_default(),
181 score_threshold: self.score_threshold.unwrap_or_default(),
182 using: self.using.unwrap_or_default(),
183 with_vectors: { convert_option(&self.with_vectors) },
184 lookup_from: self.lookup_from.unwrap_or_default(),
185 group_by: match self.group_by {
186 Some(value) => value,
187 None => {
188 return Result::Err(core::convert::Into::into(
189 ::derive_builder::UninitializedFieldError::from("group_by"),
190 ));
191 }
192 },
193 group_size: match self.group_size {
194 Some(value) => value,
195 None => {
196 return Result::Err(core::convert::Into::into(
197 ::derive_builder::UninitializedFieldError::from("group_size"),
198 ));
199 }
200 },
201 read_consistency: { convert_option(&self.read_consistency) },
202 with_lookup: self.with_lookup.unwrap_or_default(),
203 strategy: self.strategy.unwrap_or_default(),
204 positive_vectors: self.positive_vectors.unwrap_or_default(),
205 negative_vectors: self.negative_vectors.unwrap_or_default(),
206 timeout: self.timeout.unwrap_or_default(),
207 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
208 })
209 }
210 fn create_empty() -> Self {
212 Self {
213 collection_name: core::default::Default::default(),
214 positive: core::default::Default::default(),
215 negative: core::default::Default::default(),
216 filter: core::default::Default::default(),
217 limit: core::default::Default::default(),
218 with_payload: core::default::Default::default(),
219 params: core::default::Default::default(),
220 score_threshold: core::default::Default::default(),
221 using: core::default::Default::default(),
222 with_vectors: core::default::Default::default(),
223 lookup_from: core::default::Default::default(),
224 group_by: core::default::Default::default(),
225 group_size: core::default::Default::default(),
226 read_consistency: core::default::Default::default(),
227 with_lookup: core::default::Default::default(),
228 strategy: core::default::Default::default(),
229 positive_vectors: core::default::Default::default(),
230 negative_vectors: core::default::Default::default(),
231 timeout: core::default::Default::default(),
232 shard_key_selector: core::default::Default::default(),
233 }
234 }
235}
236
237impl From<RecommendPointGroupsBuilder> for RecommendPointGroups {
238 fn from(value: RecommendPointGroupsBuilder) -> Self {
239 value.build_inner().unwrap_or_else(|_| {
240 panic!(
241 "Failed to convert {0} to {1}",
242 "RecommendPointGroupsBuilder", "RecommendPointGroups"
243 )
244 })
245 }
246}
247
248impl RecommendPointGroupsBuilder {
249 pub fn build(self) -> RecommendPointGroups {
251 self.build_inner().unwrap_or_else(|_| {
252 panic!(
253 "Failed to build {0} into {1}",
254 "RecommendPointGroupsBuilder", "RecommendPointGroups"
255 )
256 })
257 }
258}
259
260impl RecommendPointGroupsBuilder {
261 pub(crate) fn empty() -> Self {
262 Self::create_empty()
263 }
264}
265
266#[non_exhaustive]
268#[derive(Debug)]
269pub enum RecommendPointGroupsBuilderError {
270 UninitializedField(&'static str),
272 ValidationError(String),
274}
275
276impl std::fmt::Display for RecommendPointGroupsBuilderError {
278 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
279 match self {
280 Self::UninitializedField(field) => {
281 write!(f, "`{field}` must be initialized")
282 }
283 Self::ValidationError(error) => write!(f, "{error}"),
284 }
285 }
286}
287
288impl std::error::Error for RecommendPointGroupsBuilderError {}
290
291impl From<derive_builder::UninitializedFieldError> for RecommendPointGroupsBuilderError {
293 fn from(error: derive_builder::UninitializedFieldError) -> Self {
294 Self::UninitializedField(error.field_name())
295 }
296}
297
298impl From<String> for RecommendPointGroupsBuilderError {
300 fn from(error: String) -> Self {
301 Self::ValidationError(error)
302 }
303}