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 pub fn collection_name(self, value: String) -> Self {
44 let mut new = self;
45 new.collection_name = Option::Some(value);
46 new
47 }
48 pub fn prefetch<VALUE: core::convert::Into<Vec<PrefetchQuery>>>(self, value: VALUE) -> Self {
50 let mut new = self;
51 new.prefetch = Option::Some(value.into());
52 new
53 }
54 pub fn query<VALUE: core::convert::Into<Query>>(self, value: VALUE) -> Self {
56 let mut new = self;
57 new.query = Option::Some(Option::Some(value.into()));
58 new
59 }
60 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
62 let mut new = self;
63 new.using = Option::Some(Option::Some(value.into()));
64 new
65 }
66 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
68 let mut new = self;
69 new.filter = Option::Some(Option::Some(value.into()));
70 new
71 }
72 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
74 let mut new = self;
75 new.params = Option::Some(Option::Some(value.into()));
76 new
77 }
78 pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
80 let mut new = self;
81 new.score_threshold = Option::Some(Option::Some(value.into()));
82 new
83 }
84 pub fn with_payload<VALUE: core::convert::Into<WithPayloadSelector>>(
86 self,
87 value: VALUE,
88 ) -> Self {
89 let mut new = self;
90 new.with_payload = Option::Some(Option::Some(value.into()));
91 new
92 }
93 pub fn with_vectors<VALUE: core::convert::Into<WithVectorsSelector>>(
95 self,
96 value: VALUE,
97 ) -> Self {
98 let mut new = self;
99 new.with_vectors = Option::Some(Option::Some(value.into()));
100 new
101 }
102 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
104 let mut new = self;
105 new.lookup_from = Option::Some(Option::Some(value.into()));
106 new
107 }
108 pub fn limit<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
110 let mut new = self;
111 new.limit = Option::Some(Option::Some(value.into()));
112 new
113 }
114 pub fn group_size<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
116 let mut new = self;
117 new.group_size = Option::Some(Option::Some(value.into()));
118 new
119 }
120 pub fn group_by(self, value: String) -> Self {
122 let mut new = self;
123 new.group_by = Option::Some(value);
124 new
125 }
126 pub fn read_consistency<VALUE: core::convert::Into<ReadConsistency>>(
128 self,
129 value: VALUE,
130 ) -> Self {
131 let mut new = self;
132 new.read_consistency = Option::Some(Option::Some(value.into()));
133 new
134 }
135 pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
137 let mut new = self;
138 new.with_lookup = Option::Some(Option::Some(value.into()));
139 new
140 }
141 pub fn timeout<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
143 let mut new = self;
144 new.timeout = Option::Some(Option::Some(value.into()));
145 new
146 }
147 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
149 self,
150 value: VALUE,
151 ) -> Self {
152 let mut new = self;
153 new.shard_key_selector = Option::Some(Option::Some(value.into()));
154 new
155 }
156
157 fn build_inner(self) -> Result<QueryPointGroups, QueryPointGroupsBuilderError> {
158 Ok(QueryPointGroups {
159 collection_name: match self.collection_name {
160 Some(value) => value,
161 None => {
162 return Result::Err(core::convert::Into::into(
163 ::derive_builder::UninitializedFieldError::from("collection_name"),
164 ));
165 }
166 },
167 prefetch: self.prefetch.unwrap_or_default(),
168 query: self.query.unwrap_or_default(),
169 using: self.using.unwrap_or_default(),
170 filter: self.filter.unwrap_or_default(),
171 params: self.params.unwrap_or_default(),
172 score_threshold: self.score_threshold.unwrap_or_default(),
173 with_payload: self.with_payload.unwrap_or_default(),
174 with_vectors: self.with_vectors.unwrap_or_default(),
175 lookup_from: self.lookup_from.unwrap_or_default(),
176 limit: self.limit.unwrap_or_default(),
177 group_size: self.group_size.unwrap_or_default(),
178 group_by: match self.group_by {
179 Some(value) => value,
180 None => {
181 return Result::Err(core::convert::Into::into(
182 ::derive_builder::UninitializedFieldError::from("group_by"),
183 ));
184 }
185 },
186 read_consistency: self.read_consistency.unwrap_or_default(),
187 with_lookup: self.with_lookup.unwrap_or_default(),
188 timeout: self.timeout.unwrap_or_default(),
189 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
190 })
191 }
192 fn create_empty() -> Self {
194 Self {
195 collection_name: core::default::Default::default(),
196 prefetch: core::default::Default::default(),
197 query: core::default::Default::default(),
198 using: core::default::Default::default(),
199 filter: core::default::Default::default(),
200 params: core::default::Default::default(),
201 score_threshold: core::default::Default::default(),
202 with_payload: core::default::Default::default(),
203 with_vectors: core::default::Default::default(),
204 lookup_from: core::default::Default::default(),
205 limit: core::default::Default::default(),
206 group_size: core::default::Default::default(),
207 group_by: core::default::Default::default(),
208 read_consistency: core::default::Default::default(),
209 with_lookup: core::default::Default::default(),
210 timeout: core::default::Default::default(),
211 shard_key_selector: core::default::Default::default(),
212 }
213 }
214}
215
216impl From<QueryPointGroupsBuilder> for QueryPointGroups {
217 fn from(value: QueryPointGroupsBuilder) -> Self {
218 value.build_inner().unwrap_or_else(|_| {
219 panic!(
220 "Failed to convert {0} to {1}",
221 "QueryPointGroupsBuilder", "QueryPointGroups"
222 )
223 })
224 }
225}
226
227impl QueryPointGroupsBuilder {
228 pub fn build(self) -> QueryPointGroups {
230 self.build_inner().unwrap_or_else(|_| {
231 panic!(
232 "Failed to build {0} into {1}",
233 "QueryPointGroupsBuilder", "QueryPointGroups"
234 )
235 })
236 }
237}
238
239impl QueryPointGroupsBuilder {
240 pub(crate) fn empty() -> Self {
241 Self::create_empty()
242 }
243}
244
245#[non_exhaustive]
247#[derive(Debug)]
248pub enum QueryPointGroupsBuilderError {
249 UninitializedField(&'static str),
251 ValidationError(String),
253}
254
255impl std::fmt::Display for QueryPointGroupsBuilderError {
257 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
258 match self {
259 Self::UninitializedField(field) => {
260 write!(f, "`{field}` must be initialized")
261 }
262 Self::ValidationError(error) => write!(f, "{error}"),
263 }
264 }
265}
266
267impl std::error::Error for QueryPointGroupsBuilderError {}
269
270impl From<derive_builder::UninitializedFieldError> for QueryPointGroupsBuilderError {
272 fn from(error: derive_builder::UninitializedFieldError) -> Self {
273 Self::UninitializedField(error.field_name())
274 }
275}
276
277impl From<String> for QueryPointGroupsBuilderError {
279 fn from(error: String) -> Self {
280 Self::ValidationError(error)
281 }
282}