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 pub fn collection_name(self, value: String) -> Self {
41 let mut new = self;
42 new.collection_name = Option::Some(value);
43 new
44 }
45 pub fn prefetch<VALUE: core::convert::Into<Vec<PrefetchQuery>>>(self, value: VALUE) -> Self {
47 let mut new = self;
48 new.prefetch = Option::Some(value.into());
49 new
50 }
51 pub fn query<VALUE: core::convert::Into<Query>>(self, value: VALUE) -> Self {
53 let mut new = self;
54 new.query = Option::Some(Option::Some(value.into()));
55 new
56 }
57 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
59 let mut new = self;
60 new.using = Option::Some(Option::Some(value.into()));
61 new
62 }
63 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
65 let mut new = self;
66 new.filter = Option::Some(Option::Some(value.into()));
67 new
68 }
69 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
71 let mut new = self;
72 new.params = Option::Some(Option::Some(value.into()));
73 new
74 }
75 pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
77 let mut new = self;
78 new.score_threshold = Option::Some(Option::Some(value.into()));
79 new
80 }
81 pub fn limit(self, value: u64) -> Self {
83 let mut new = self;
84 new.limit = Option::Some(Option::Some(value));
85 new
86 }
87 pub fn offset(self, value: u64) -> Self {
89 let mut new = self;
90 new.offset = Option::Some(Option::Some(value));
91 new
92 }
93 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
95 self,
96 value: VALUE,
97 ) -> Self {
98 let mut new = self;
99 new.with_vectors = Option::Some(value.into());
100 new
101 }
102 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
104 self,
105 value: VALUE,
106 ) -> Self {
107 let mut new = self;
108 new.with_payload = Option::Some(value.into());
109 new
110 }
111 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
113 self,
114 value: VALUE,
115 ) -> Self {
116 let mut new = self;
117 new.read_consistency = Option::Some(value.into());
118 new
119 }
120 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
122 self,
123 value: VALUE,
124 ) -> Self {
125 let mut new = self;
126 new.shard_key_selector = Option::Some(Option::Some(value.into()));
127 new
128 }
129 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
131 let mut new = self;
132 new.lookup_from = Option::Some(Option::Some(value.into()));
133 new
134 }
135 pub fn timeout(self, value: u64) -> Self {
137 let mut new = self;
138 new.timeout = Option::Some(Option::Some(value));
139 new
140 }
141
142 fn build_inner(self) -> Result<QueryPoints, QueryPointsBuilderError> {
143 Ok(QueryPoints {
144 collection_name: match self.collection_name {
145 Some(value) => value,
146 None => {
147 return Result::Err(core::convert::Into::into(
148 ::derive_builder::UninitializedFieldError::from("collection_name"),
149 ));
150 }
151 },
152 prefetch: self.prefetch.unwrap_or_default(),
153 query: self.query.unwrap_or_default(),
154 using: self.using.unwrap_or_default(),
155 filter: self.filter.unwrap_or_default(),
156 params: self.params.unwrap_or_default(),
157 score_threshold: self.score_threshold.unwrap_or_default(),
158 limit: self.limit.unwrap_or_default(),
159 offset: self.offset.unwrap_or_default(),
160 with_vectors: { convert_option(&self.with_vectors) },
161 with_payload: { convert_option(&self.with_payload) },
162 read_consistency: { convert_option(&self.read_consistency) },
163 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
164 lookup_from: self.lookup_from.unwrap_or_default(),
165 timeout: self.timeout.unwrap_or_default(),
166 })
167 }
168 fn create_empty() -> Self {
170 Self {
171 collection_name: core::default::Default::default(),
172 prefetch: core::default::Default::default(),
173 query: core::default::Default::default(),
174 using: core::default::Default::default(),
175 filter: core::default::Default::default(),
176 params: core::default::Default::default(),
177 score_threshold: core::default::Default::default(),
178 limit: core::default::Default::default(),
179 offset: core::default::Default::default(),
180 with_vectors: core::default::Default::default(),
181 with_payload: core::default::Default::default(),
182 read_consistency: core::default::Default::default(),
183 shard_key_selector: core::default::Default::default(),
184 lookup_from: core::default::Default::default(),
185 timeout: core::default::Default::default(),
186 }
187 }
188}
189
190impl From<QueryPointsBuilder> for QueryPoints {
191 fn from(value: QueryPointsBuilder) -> Self {
192 value.build_inner().unwrap_or_else(|_| {
193 panic!(
194 "Failed to convert {0} to {1}",
195 "QueryPointsBuilder", "QueryPoints"
196 )
197 })
198 }
199}
200
201impl QueryPointsBuilder {
202 pub fn build(self) -> QueryPoints {
204 self.build_inner().unwrap_or_else(|_| {
205 panic!(
206 "Failed to build {0} into {1}",
207 "QueryPointsBuilder", "QueryPoints"
208 )
209 })
210 }
211}
212
213impl QueryPointsBuilder {
214 pub(crate) fn empty() -> Self {
215 Self::create_empty()
216 }
217}
218
219#[non_exhaustive]
221#[derive(Debug)]
222pub enum QueryPointsBuilderError {
223 UninitializedField(&'static str),
225 ValidationError(String),
227}
228
229impl From<derive_builder::UninitializedFieldError> for QueryPointsBuilderError {
231 fn from(error: derive_builder::UninitializedFieldError) -> Self {
232 Self::UninitializedField(error.field_name())
233 }
234}
235
236impl From<String> for QueryPointsBuilderError {
238 fn from(error: String) -> Self {
239 Self::ValidationError(error)
240 }
241}
242
243impl std::fmt::Display for QueryPointsBuilderError {
245 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
246 match self {
247 Self::UninitializedField(field) => {
248 write!(f, "`{field}` must be initialized")
249 }
250 Self::ValidationError(error) => write!(f, "{error}"),
251 }
252 }
253}
254
255impl std::error::Error for QueryPointsBuilderError {}