1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct QueryPointGroupsBuilder {
5 pub(crate) collection_name: Option<String>,
7 pub(crate) prefetch: Option<Vec<PrefetchQuery>>,
9 pub(crate) query: Option<Option<Query>>,
11 pub(crate) using: Option<Option<String>>,
13 pub(crate) filter: Option<Option<Filter>>,
15 pub(crate) params: Option<Option<SearchParams>>,
17 pub(crate) score_threshold: Option<Option<f32>>,
19 pub(crate) with_payload: Option<Option<WithPayloadSelector>>,
21 pub(crate) with_vectors: Option<Option<WithVectorsSelector>>,
23 pub(crate) lookup_from: Option<Option<LookupLocation>>,
25 pub(crate) limit: Option<Option<u64>>,
27 pub(crate) group_size: Option<Option<u64>>,
29 pub(crate) group_by: Option<String>,
31 pub(crate) read_consistency: Option<Option<ReadConsistency>>,
33 pub(crate) with_lookup: Option<Option<WithLookup>>,
35 pub(crate) timeout: Option<Option<u64>>,
37 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
39}
40
41impl QueryPointGroupsBuilder {
42 #[allow(unused_mut)]
44 pub fn collection_name(self, value: String) -> Self {
45 let mut new = self;
46 new.collection_name = Option::Some(value);
47 new
48 }
49 #[allow(unused_mut)]
51 pub fn prefetch<VALUE: core::convert::Into<Vec<PrefetchQuery>>>(self, value: VALUE) -> Self {
52 let mut new = self;
53 new.prefetch = Option::Some(value.into());
54 new
55 }
56 #[allow(unused_mut)]
58 pub fn query<VALUE: core::convert::Into<Query>>(self, value: VALUE) -> Self {
59 let mut new = self;
60 new.query = Option::Some(Option::Some(value.into()));
61 new
62 }
63 #[allow(unused_mut)]
65 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
66 let mut new = self;
67 new.using = Option::Some(Option::Some(value.into()));
68 new
69 }
70 #[allow(unused_mut)]
72 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
73 let mut new = self;
74 new.filter = Option::Some(Option::Some(value.into()));
75 new
76 }
77 #[allow(unused_mut)]
79 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
80 let mut new = self;
81 new.params = Option::Some(Option::Some(value.into()));
82 new
83 }
84 #[allow(unused_mut)]
86 pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
87 let mut new = self;
88 new.score_threshold = Option::Some(Option::Some(value.into()));
89 new
90 }
91 #[allow(unused_mut)]
93 pub fn with_payload<VALUE: core::convert::Into<WithPayloadSelector>>(
94 self,
95 value: VALUE,
96 ) -> Self {
97 let mut new = self;
98 new.with_payload = Option::Some(Option::Some(value.into()));
99 new
100 }
101 #[allow(unused_mut)]
103 pub fn with_vectors<VALUE: core::convert::Into<WithVectorsSelector>>(
104 self,
105 value: VALUE,
106 ) -> Self {
107 let mut new = self;
108 new.with_vectors = Option::Some(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 limit<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
121 let mut new = self;
122 new.limit = Option::Some(Option::Some(value.into()));
123 new
124 }
125 #[allow(unused_mut)]
127 pub fn group_size<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
128 let mut new = self;
129 new.group_size = Option::Some(Option::Some(value.into()));
130 new
131 }
132 #[allow(unused_mut)]
134 pub fn group_by(self, value: String) -> Self {
135 let mut new = self;
136 new.group_by = Option::Some(value);
137 new
138 }
139 #[allow(unused_mut)]
141 pub fn read_consistency<VALUE: core::convert::Into<ReadConsistency>>(
142 self,
143 value: VALUE,
144 ) -> Self {
145 let mut new = self;
146 new.read_consistency = Option::Some(Option::Some(value.into()));
147 new
148 }
149 #[allow(unused_mut)]
151 pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
152 let mut new = self;
153 new.with_lookup = Option::Some(Option::Some(value.into()));
154 new
155 }
156 #[allow(unused_mut)]
158 pub fn timeout<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
159 let mut new = self;
160 new.timeout = Option::Some(Option::Some(value.into()));
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<QueryPointGroups, QueryPointGroupsBuilderError> {
175 Ok(QueryPointGroups {
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 prefetch: self.prefetch.unwrap_or_default(),
185 query: self.query.unwrap_or_default(),
186 using: self.using.unwrap_or_default(),
187 filter: self.filter.unwrap_or_default(),
188 params: self.params.unwrap_or_default(),
189 score_threshold: self.score_threshold.unwrap_or_default(),
190 with_payload: self.with_payload.unwrap_or_default(),
191 with_vectors: self.with_vectors.unwrap_or_default(),
192 lookup_from: self.lookup_from.unwrap_or_default(),
193 limit: self.limit.unwrap_or_default(),
194 group_size: self.group_size.unwrap_or_default(),
195 group_by: match self.group_by {
196 Some(value) => value,
197 None => {
198 return Result::Err(core::convert::Into::into(
199 ::derive_builder::UninitializedFieldError::from("group_by"),
200 ));
201 }
202 },
203 read_consistency: self.read_consistency.unwrap_or_default(),
204 with_lookup: self.with_lookup.unwrap_or_default(),
205 timeout: self.timeout.unwrap_or_default(),
206 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
207 })
208 }
209 fn create_empty() -> Self {
211 Self {
212 collection_name: core::default::Default::default(),
213 prefetch: core::default::Default::default(),
214 query: core::default::Default::default(),
215 using: core::default::Default::default(),
216 filter: core::default::Default::default(),
217 params: core::default::Default::default(),
218 score_threshold: core::default::Default::default(),
219 with_payload: core::default::Default::default(),
220 with_vectors: core::default::Default::default(),
221 lookup_from: core::default::Default::default(),
222 limit: core::default::Default::default(),
223 group_size: core::default::Default::default(),
224 group_by: core::default::Default::default(),
225 read_consistency: core::default::Default::default(),
226 with_lookup: core::default::Default::default(),
227 timeout: core::default::Default::default(),
228 shard_key_selector: core::default::Default::default(),
229 }
230 }
231}
232
233impl From<QueryPointGroupsBuilder> for QueryPointGroups {
234 fn from(value: QueryPointGroupsBuilder) -> Self {
235 value.build_inner().unwrap_or_else(|_| {
236 panic!(
237 "Failed to convert {0} to {1}",
238 "QueryPointGroupsBuilder", "QueryPointGroups"
239 )
240 })
241 }
242}
243
244impl QueryPointGroupsBuilder {
245 pub fn build(self) -> QueryPointGroups {
247 self.build_inner().unwrap_or_else(|_| {
248 panic!(
249 "Failed to build {0} into {1}",
250 "QueryPointGroupsBuilder", "QueryPointGroups"
251 )
252 })
253 }
254}
255
256impl QueryPointGroupsBuilder {
257 pub(crate) fn empty() -> Self {
258 Self::create_empty()
259 }
260}
261
262#[non_exhaustive]
264#[derive(Debug)]
265pub enum QueryPointGroupsBuilderError {
266 UninitializedField(&'static str),
268 ValidationError(String),
270}
271
272impl std::fmt::Display for QueryPointGroupsBuilderError {
274 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
275 match self {
276 Self::UninitializedField(field) => {
277 write!(f, "`{field}` must be initialized")
278 }
279 Self::ValidationError(error) => write!(f, "{error}"),
280 }
281 }
282}
283
284impl std::error::Error for QueryPointGroupsBuilderError {}
286
287impl From<derive_builder::UninitializedFieldError> for QueryPointGroupsBuilderError {
289 fn from(error: derive_builder::UninitializedFieldError) -> Self {
290 Self::UninitializedField(error.field_name())
291 }
292}
293
294impl From<String> for QueryPointGroupsBuilderError {
296 fn from(error: String) -> Self {
297 Self::ValidationError(error)
298 }
299}