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