qdrant_client/builders/
query_points_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct QueryPointsBuilder {
7 pub(crate) collection_name: Option<String>,
9 pub(crate) prefetch: Option<Vec<PrefetchQuery>>,
11 pub(crate) query: Option<Option<Query>>,
13 pub(crate) using: Option<Option<String>>,
15 pub(crate) filter: Option<Option<Filter>>,
17 pub(crate) params: Option<Option<SearchParams>>,
19 pub(crate) score_threshold: Option<Option<f32>>,
21 pub(crate) limit: Option<Option<u64>>,
23 pub(crate) offset: Option<Option<u64>>,
25 with_vectors: Option<with_vectors_selector::SelectorOptions>,
27 with_payload: Option<with_payload_selector::SelectorOptions>,
29 read_consistency: Option<read_consistency::Value>,
31 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
33 pub(crate) lookup_from: Option<Option<LookupLocation>>,
35 pub(crate) timeout: Option<Option<u64>>,
37}
38
39impl QueryPointsBuilder {
40 pub fn collection_name(self, value: String) -> Self {
42 let mut new = self;
43 new.collection_name = Option::Some(value);
44 new
45 }
46 pub fn prefetch<VALUE: core::convert::Into<Vec<PrefetchQuery>>>(self, value: VALUE) -> Self {
48 let mut new = self;
49 new.prefetch = Option::Some(value.into());
50 new
51 }
52 pub fn query<VALUE: core::convert::Into<Query>>(self, value: VALUE) -> Self {
54 let mut new = self;
55 new.query = Option::Some(Option::Some(value.into()));
56 new
57 }
58 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
60 let mut new = self;
61 new.using = Option::Some(Option::Some(value.into()));
62 new
63 }
64 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
66 let mut new = self;
67 new.filter = Option::Some(Option::Some(value.into()));
68 new
69 }
70 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
72 let mut new = self;
73 new.params = Option::Some(Option::Some(value.into()));
74 new
75 }
76 pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
78 let mut new = self;
79 new.score_threshold = Option::Some(Option::Some(value.into()));
80 new
81 }
82 pub fn limit(self, value: u64) -> Self {
84 let mut new = self;
85 new.limit = Option::Some(Option::Some(value));
86 new
87 }
88 pub fn offset(self, value: u64) -> Self {
90 let mut new = self;
91 new.offset = Option::Some(Option::Some(value));
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 with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
105 self,
106 value: VALUE,
107 ) -> Self {
108 let mut new = self;
109 new.with_payload = Option::Some(value.into());
110 new
111 }
112 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
114 self,
115 value: VALUE,
116 ) -> Self {
117 let mut new = self;
118 new.read_consistency = Option::Some(value.into());
119 new
120 }
121 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
123 self,
124 value: VALUE,
125 ) -> Self {
126 let mut new = self;
127 new.shard_key_selector = Option::Some(Option::Some(value.into()));
128 new
129 }
130 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
132 let mut new = self;
133 new.lookup_from = Option::Some(Option::Some(value.into()));
134 new
135 }
136 pub fn timeout(self, value: u64) -> Self {
138 let mut new = self;
139 new.timeout = Option::Some(Option::Some(value));
140 new
141 }
142
143 fn build_inner(self) -> Result<QueryPoints, QueryPointsBuilderError> {
144 Ok(QueryPoints {
145 collection_name: match self.collection_name {
146 Some(value) => value,
147 None => {
148 return Result::Err(core::convert::Into::into(
149 ::derive_builder::UninitializedFieldError::from("collection_name"),
150 ));
151 }
152 },
153 prefetch: self.prefetch.unwrap_or_default(),
154 query: self.query.unwrap_or_default(),
155 using: self.using.unwrap_or_default(),
156 filter: self.filter.unwrap_or_default(),
157 params: self.params.unwrap_or_default(),
158 score_threshold: self.score_threshold.unwrap_or_default(),
159 limit: self.limit.unwrap_or_default(),
160 offset: self.offset.unwrap_or_default(),
161 with_vectors: { convert_option(&self.with_vectors) },
162 with_payload: { convert_option(&self.with_payload) },
163 read_consistency: { convert_option(&self.read_consistency) },
164 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
165 lookup_from: self.lookup_from.unwrap_or_default(),
166 timeout: self.timeout.unwrap_or_default(),
167 })
168 }
169 fn create_empty() -> Self {
171 Self {
172 collection_name: core::default::Default::default(),
173 prefetch: core::default::Default::default(),
174 query: core::default::Default::default(),
175 using: core::default::Default::default(),
176 filter: core::default::Default::default(),
177 params: core::default::Default::default(),
178 score_threshold: core::default::Default::default(),
179 limit: core::default::Default::default(),
180 offset: core::default::Default::default(),
181 with_vectors: core::default::Default::default(),
182 with_payload: core::default::Default::default(),
183 read_consistency: core::default::Default::default(),
184 shard_key_selector: core::default::Default::default(),
185 lookup_from: core::default::Default::default(),
186 timeout: core::default::Default::default(),
187 }
188 }
189}
190
191impl From<QueryPointsBuilder> for QueryPoints {
192 fn from(value: QueryPointsBuilder) -> Self {
193 value.build_inner().unwrap_or_else(|_| {
194 panic!(
195 "Failed to convert {0} to {1}",
196 "QueryPointsBuilder", "QueryPoints"
197 )
198 })
199 }
200}
201
202impl QueryPointsBuilder {
203 pub fn build(self) -> QueryPoints {
205 self.build_inner().unwrap_or_else(|_| {
206 panic!(
207 "Failed to build {0} into {1}",
208 "QueryPointsBuilder", "QueryPoints"
209 )
210 })
211 }
212}
213
214impl QueryPointsBuilder {
215 pub(crate) fn empty() -> Self {
216 Self::create_empty()
217 }
218}
219
220#[non_exhaustive]
222#[derive(Debug)]
223pub enum QueryPointsBuilderError {
224 UninitializedField(&'static str),
226 ValidationError(String),
228}
229
230impl From<derive_builder::UninitializedFieldError> for QueryPointsBuilderError {
232 fn from(error: derive_builder::UninitializedFieldError) -> Self {
233 Self::UninitializedField(error.field_name())
234 }
235}
236
237impl From<String> for QueryPointsBuilderError {
239 fn from(error: String) -> Self {
240 Self::ValidationError(error)
241 }
242}
243
244impl std::fmt::Display for QueryPointsBuilderError {
246 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
247 match self {
248 Self::UninitializedField(field) => {
249 write!(f, "`{field}` must be initialized")
250 }
251 Self::ValidationError(error) => write!(f, "{error}"),
252 }
253 }
254}
255
256impl std::error::Error for QueryPointsBuilderError {}