1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct QueryPointGroupsBuilder {
6 pub(crate) collection_name: Option<String>,
8 pub(crate) prefetch: Option<Vec<PrefetchQuery>>,
10 pub(crate) query: Option<Option<Query>>,
12 pub(crate) using: Option<Option<String>>,
14 pub(crate) filter: Option<Option<Filter>>,
16 pub(crate) params: Option<Option<SearchParams>>,
18 pub(crate) score_threshold: Option<Option<f32>>,
20 pub(crate) with_payload: Option<Option<WithPayloadSelector>>,
22 pub(crate) with_vectors: Option<Option<WithVectorsSelector>>,
24 pub(crate) lookup_from: Option<Option<LookupLocation>>,
26 pub(crate) limit: Option<Option<u64>>,
28 pub(crate) group_size: Option<Option<u64>>,
30 pub(crate) group_by: Option<String>,
32 pub(crate) read_consistency: Option<Option<ReadConsistency>>,
34 pub(crate) with_lookup: Option<Option<WithLookup>>,
36 pub(crate) timeout: Option<Option<u64>>,
38 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
40}
41
42impl QueryPointGroupsBuilder {
43 pub fn collection_name(self, value: String) -> Self {
45 let mut new = self;
46 new.collection_name = Option::Some(value);
47 new
48 }
49 pub fn prefetch<VALUE: core::convert::Into<Vec<PrefetchQuery>>>(self, value: VALUE) -> Self {
51 let mut new = self;
52 new.prefetch = Option::Some(value.into());
53 new
54 }
55 pub fn query<VALUE: core::convert::Into<Query>>(self, value: VALUE) -> Self {
57 let mut new = self;
58 new.query = Option::Some(Option::Some(value.into()));
59 new
60 }
61 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
63 let mut new = self;
64 new.using = Option::Some(Option::Some(value.into()));
65 new
66 }
67 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
69 let mut new = self;
70 new.filter = Option::Some(Option::Some(value.into()));
71 new
72 }
73 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
75 let mut new = self;
76 new.params = Option::Some(Option::Some(value.into()));
77 new
78 }
79 pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
81 let mut new = self;
82 new.score_threshold = Option::Some(Option::Some(value.into()));
83 new
84 }
85 pub fn with_payload<VALUE: core::convert::Into<WithPayloadSelector>>(
87 self,
88 value: VALUE,
89 ) -> Self {
90 let mut new = self;
91 new.with_payload = Option::Some(Option::Some(value.into()));
92 new
93 }
94 pub fn with_vectors<VALUE: core::convert::Into<WithVectorsSelector>>(
96 self,
97 value: VALUE,
98 ) -> Self {
99 let mut new = self;
100 new.with_vectors = Option::Some(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 limit<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
111 let mut new = self;
112 new.limit = Option::Some(Option::Some(value.into()));
113 new
114 }
115 pub fn group_size<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
117 let mut new = self;
118 new.group_size = Option::Some(Option::Some(value.into()));
119 new
120 }
121 pub fn group_by(self, value: String) -> Self {
123 let mut new = self;
124 new.group_by = Option::Some(value);
125 new
126 }
127 pub fn read_consistency<VALUE: core::convert::Into<ReadConsistency>>(
129 self,
130 value: VALUE,
131 ) -> Self {
132 let mut new = self;
133 new.read_consistency = Option::Some(Option::Some(value.into()));
134 new
135 }
136 pub fn with_lookup<VALUE: core::convert::Into<WithLookup>>(self, value: VALUE) -> Self {
138 let mut new = self;
139 new.with_lookup = Option::Some(Option::Some(value.into()));
140 new
141 }
142 pub fn timeout<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
144 let mut new = self;
145 new.timeout = Option::Some(Option::Some(value.into()));
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<QueryPointGroups, QueryPointGroupsBuilderError> {
159 Ok(QueryPointGroups {
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 prefetch: self.prefetch.unwrap_or_default(),
169 query: self.query.unwrap_or_default(),
170 using: self.using.unwrap_or_default(),
171 filter: self.filter.unwrap_or_default(),
172 params: self.params.unwrap_or_default(),
173 score_threshold: self.score_threshold.unwrap_or_default(),
174 with_payload: self.with_payload.unwrap_or_default(),
175 with_vectors: self.with_vectors.unwrap_or_default(),
176 lookup_from: self.lookup_from.unwrap_or_default(),
177 limit: self.limit.unwrap_or_default(),
178 group_size: self.group_size.unwrap_or_default(),
179 group_by: match self.group_by {
180 Some(value) => value,
181 None => {
182 return Result::Err(core::convert::Into::into(
183 ::derive_builder::UninitializedFieldError::from("group_by"),
184 ));
185 }
186 },
187 read_consistency: self.read_consistency.unwrap_or_default(),
188 with_lookup: self.with_lookup.unwrap_or_default(),
189 timeout: self.timeout.unwrap_or_default(),
190 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
191 })
192 }
193 fn create_empty() -> Self {
195 Self {
196 collection_name: core::default::Default::default(),
197 prefetch: core::default::Default::default(),
198 query: core::default::Default::default(),
199 using: core::default::Default::default(),
200 filter: core::default::Default::default(),
201 params: core::default::Default::default(),
202 score_threshold: core::default::Default::default(),
203 with_payload: core::default::Default::default(),
204 with_vectors: core::default::Default::default(),
205 lookup_from: core::default::Default::default(),
206 limit: core::default::Default::default(),
207 group_size: core::default::Default::default(),
208 group_by: core::default::Default::default(),
209 read_consistency: core::default::Default::default(),
210 with_lookup: core::default::Default::default(),
211 timeout: core::default::Default::default(),
212 shard_key_selector: core::default::Default::default(),
213 }
214 }
215}
216
217impl From<QueryPointGroupsBuilder> for QueryPointGroups {
218 fn from(value: QueryPointGroupsBuilder) -> Self {
219 value.build_inner().unwrap_or_else(|_| {
220 panic!(
221 "Failed to convert {0} to {1}",
222 "QueryPointGroupsBuilder", "QueryPointGroups"
223 )
224 })
225 }
226}
227
228impl QueryPointGroupsBuilder {
229 pub fn build(self) -> QueryPointGroups {
231 self.build_inner().unwrap_or_else(|_| {
232 panic!(
233 "Failed to build {0} into {1}",
234 "QueryPointGroupsBuilder", "QueryPointGroups"
235 )
236 })
237 }
238}
239
240impl QueryPointGroupsBuilder {
241 pub(crate) fn empty() -> Self {
242 Self::create_empty()
243 }
244}
245
246#[non_exhaustive]
248#[derive(Debug)]
249pub enum QueryPointGroupsBuilderError {
250 UninitializedField(&'static str),
252 ValidationError(String),
254}
255
256impl std::fmt::Display for QueryPointGroupsBuilderError {
258 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
259 match self {
260 Self::UninitializedField(field) => {
261 write!(f, "`{field}` must be initialized")
262 }
263 Self::ValidationError(error) => write!(f, "{error}"),
264 }
265 }
266}
267
268impl std::error::Error for QueryPointGroupsBuilderError {}
270
271impl From<derive_builder::UninitializedFieldError> for QueryPointGroupsBuilderError {
273 fn from(error: derive_builder::UninitializedFieldError) -> Self {
274 Self::UninitializedField(error.field_name())
275 }
276}
277
278impl From<String> for QueryPointGroupsBuilderError {
280 fn from(error: String) -> Self {
281 Self::ValidationError(error)
282 }
283}