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