qdrant_client/builders/
query_points_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct QueryPointsBuilder {
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) limit: Option<Option<u64>>,
22 pub(crate) offset: Option<Option<u64>>,
24 with_vectors: Option<with_vectors_selector::SelectorOptions>,
26 with_payload: Option<with_payload_selector::SelectorOptions>,
28 read_consistency: Option<read_consistency::Value>,
30 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
32 pub(crate) lookup_from: Option<Option<LookupLocation>>,
34 pub(crate) timeout: Option<Option<u64>>,
36}
37
38impl QueryPointsBuilder {
39 #[allow(unused_mut)]
41 pub fn collection_name(self, value: String) -> Self {
42 let mut new = self;
43 new.collection_name = Option::Some(value);
44 new
45 }
46 #[allow(unused_mut)]
48 pub fn prefetch<VALUE: core::convert::Into<Vec<PrefetchQuery>>>(self, value: VALUE) -> Self {
49 let mut new = self;
50 new.prefetch = Option::Some(value.into());
51 new
52 }
53 #[allow(unused_mut)]
55 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 #[allow(unused_mut)]
62 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 #[allow(unused_mut)]
69 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
70 let mut new = self;
71 new.filter = Option::Some(Option::Some(value.into()));
72 new
73 }
74 #[allow(unused_mut)]
76 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
77 let mut new = self;
78 new.params = Option::Some(Option::Some(value.into()));
79 new
80 }
81 #[allow(unused_mut)]
83 pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
84 let mut new = self;
85 new.score_threshold = Option::Some(Option::Some(value.into()));
86 new
87 }
88 #[allow(unused_mut)]
90 pub fn limit(self, value: u64) -> Self {
91 let mut new = self;
92 new.limit = Option::Some(Option::Some(value));
93 new
94 }
95 #[allow(unused_mut)]
97 pub fn offset(self, value: u64) -> Self {
98 let mut new = self;
99 new.offset = Option::Some(Option::Some(value));
100 new
101 }
102 #[allow(unused_mut)]
104 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
105 self,
106 value: VALUE,
107 ) -> Self {
108 let mut new = self;
109 new.with_vectors = Option::Some(value.into());
110 new
111 }
112 #[allow(unused_mut)]
114 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
115 self,
116 value: VALUE,
117 ) -> Self {
118 let mut new = self;
119 new.with_payload = Option::Some(value.into());
120 new
121 }
122 #[allow(unused_mut)]
124 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
125 self,
126 value: VALUE,
127 ) -> Self {
128 let mut new = self;
129 new.read_consistency = Option::Some(value.into());
130 new
131 }
132 #[allow(unused_mut)]
134 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
135 self,
136 value: VALUE,
137 ) -> Self {
138 let mut new = self;
139 new.shard_key_selector = Option::Some(Option::Some(value.into()));
140 new
141 }
142 #[allow(unused_mut)]
144 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
145 let mut new = self;
146 new.lookup_from = Option::Some(Option::Some(value.into()));
147 new
148 }
149 #[allow(unused_mut)]
151 pub fn timeout(self, value: u64) -> Self {
152 let mut new = self;
153 new.timeout = Option::Some(Option::Some(value));
154 new
155 }
156
157 fn build_inner(self) -> Result<QueryPoints, QueryPointsBuilderError> {
158 Ok(QueryPoints {
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 limit: self.limit.unwrap_or_default(),
174 offset: self.offset.unwrap_or_default(),
175 with_vectors: { convert_option(&self.with_vectors) },
176 with_payload: { convert_option(&self.with_payload) },
177 read_consistency: { convert_option(&self.read_consistency) },
178 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
179 lookup_from: self.lookup_from.unwrap_or_default(),
180 timeout: self.timeout.unwrap_or_default(),
181 })
182 }
183 fn create_empty() -> Self {
185 Self {
186 collection_name: core::default::Default::default(),
187 prefetch: core::default::Default::default(),
188 query: core::default::Default::default(),
189 using: core::default::Default::default(),
190 filter: core::default::Default::default(),
191 params: core::default::Default::default(),
192 score_threshold: core::default::Default::default(),
193 limit: core::default::Default::default(),
194 offset: core::default::Default::default(),
195 with_vectors: core::default::Default::default(),
196 with_payload: core::default::Default::default(),
197 read_consistency: core::default::Default::default(),
198 shard_key_selector: core::default::Default::default(),
199 lookup_from: core::default::Default::default(),
200 timeout: core::default::Default::default(),
201 }
202 }
203}
204
205impl From<QueryPointsBuilder> for QueryPoints {
206 fn from(value: QueryPointsBuilder) -> Self {
207 value.build_inner().unwrap_or_else(|_| {
208 panic!(
209 "Failed to convert {0} to {1}",
210 "QueryPointsBuilder", "QueryPoints"
211 )
212 })
213 }
214}
215
216impl QueryPointsBuilder {
217 pub fn build(self) -> QueryPoints {
219 self.build_inner().unwrap_or_else(|_| {
220 panic!(
221 "Failed to build {0} into {1}",
222 "QueryPointsBuilder", "QueryPoints"
223 )
224 })
225 }
226}
227
228impl QueryPointsBuilder {
229 pub(crate) fn empty() -> Self {
230 Self::create_empty()
231 }
232}
233
234#[non_exhaustive]
236#[derive(Debug)]
237pub enum QueryPointsBuilderError {
238 UninitializedField(&'static str),
240 ValidationError(String),
242}
243
244impl From<derive_builder::UninitializedFieldError> for QueryPointsBuilderError {
246 fn from(error: derive_builder::UninitializedFieldError) -> Self {
247 Self::UninitializedField(error.field_name())
248 }
249}
250
251impl From<String> for QueryPointsBuilderError {
253 fn from(error: String) -> Self {
254 Self::ValidationError(error)
255 }
256}
257
258impl std::fmt::Display for QueryPointsBuilderError {
260 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
261 match self {
262 Self::UninitializedField(field) => {
263 write!(f, "`{field}` must be initialized")
264 }
265 Self::ValidationError(error) => write!(f, "{error}"),
266 }
267 }
268}
269
270impl std::error::Error for QueryPointsBuilderError {}