qdrant_client/builders/
discover_points_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct DiscoverPointsBuilder {
6 pub(crate) collection_name: Option<String>,
8 pub(crate) target: Option<Option<TargetVector>>,
10 pub(crate) context: Option<Vec<ContextExamplePair>>,
12 pub(crate) filter: Option<Option<Filter>>,
14 pub(crate) limit: Option<u64>,
16 with_payload: Option<with_payload_selector::SelectorOptions>,
18 pub(crate) params: Option<Option<SearchParams>>,
20 pub(crate) offset: Option<Option<u64>>,
22 pub(crate) using: Option<Option<String>>,
24 with_vectors: Option<with_vectors_selector::SelectorOptions>,
26 pub(crate) lookup_from: Option<Option<LookupLocation>>,
28 read_consistency: Option<read_consistency::Value>,
30 pub(crate) timeout: Option<Option<u64>>,
32 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
34}
35
36impl DiscoverPointsBuilder {
37 #[allow(unused_mut)]
39 pub fn collection_name(self, value: String) -> Self {
40 let mut new = self;
41 new.collection_name = Option::Some(value);
42 new
43 }
44 #[allow(unused_mut)]
46 pub fn target<VALUE: core::convert::Into<TargetVector>>(self, value: VALUE) -> Self {
47 let mut new = self;
48 new.target = Option::Some(Option::Some(value.into()));
49 new
50 }
51 #[allow(unused_mut)]
53 pub fn context(self, value: Vec<ContextExamplePair>) -> Self {
54 let mut new = self;
55 new.context = Option::Some(value);
56 new
57 }
58 #[allow(unused_mut)]
60 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
61 let mut new = self;
62 new.filter = Option::Some(Option::Some(value.into()));
63 new
64 }
65 #[allow(unused_mut)]
67 pub fn limit(self, value: u64) -> Self {
68 let mut new = self;
69 new.limit = Option::Some(value);
70 new
71 }
72 #[allow(unused_mut)]
74 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
75 self,
76 value: VALUE,
77 ) -> Self {
78 let mut new = self;
79 new.with_payload = Option::Some(value.into());
80 new
81 }
82 #[allow(unused_mut)]
84 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
85 let mut new = self;
86 new.params = Option::Some(Option::Some(value.into()));
87 new
88 }
89 #[allow(unused_mut)]
91 pub fn offset(self, value: u64) -> Self {
92 let mut new = self;
93 new.offset = Option::Some(Option::Some(value));
94 new
95 }
96 #[allow(unused_mut)]
98 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
99 let mut new = self;
100 new.using = Option::Some(Option::Some(value.into()));
101 new
102 }
103 #[allow(unused_mut)]
105 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
106 self,
107 value: VALUE,
108 ) -> Self {
109 let mut new = self;
110 new.with_vectors = Option::Some(value.into());
111 new
112 }
113 #[allow(unused_mut)]
115 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
116 let mut new = self;
117 new.lookup_from = Option::Some(Option::Some(value.into()));
118 new
119 }
120 #[allow(unused_mut)]
122 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
123 self,
124 value: VALUE,
125 ) -> Self {
126 let mut new = self;
127 new.read_consistency = Option::Some(value.into());
128 new
129 }
130 #[allow(unused_mut)]
132 pub fn timeout(self, value: u64) -> Self {
133 let mut new = self;
134 new.timeout = Option::Some(Option::Some(value));
135 new
136 }
137 #[allow(unused_mut)]
139 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
140 self,
141 value: VALUE,
142 ) -> Self {
143 let mut new = self;
144 new.shard_key_selector = Option::Some(Option::Some(value.into()));
145 new
146 }
147
148 fn build_inner(self) -> Result<DiscoverPoints, DiscoverPointsBuilderError> {
149 Ok(DiscoverPoints {
150 collection_name: match self.collection_name {
151 Some(value) => value,
152 None => {
153 return Result::Err(core::convert::Into::into(
154 ::derive_builder::UninitializedFieldError::from("collection_name"),
155 ));
156 }
157 },
158 target: self.target.unwrap_or_default(),
159 context: match self.context {
160 Some(value) => value,
161 None => {
162 return Result::Err(core::convert::Into::into(
163 ::derive_builder::UninitializedFieldError::from("context"),
164 ));
165 }
166 },
167 filter: self.filter.unwrap_or_default(),
168 limit: match self.limit {
169 Some(value) => value,
170 None => {
171 return Result::Err(core::convert::Into::into(
172 ::derive_builder::UninitializedFieldError::from("limit"),
173 ));
174 }
175 },
176 with_payload: { convert_option(&self.with_payload) },
177 params: self.params.unwrap_or_default(),
178 offset: self.offset.unwrap_or_default(),
179 using: self.using.unwrap_or_default(),
180 with_vectors: { convert_option(&self.with_vectors) },
181 lookup_from: self.lookup_from.unwrap_or_default(),
182 read_consistency: { convert_option(&self.read_consistency) },
183 timeout: self.timeout.unwrap_or_default(),
184 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
185 })
186 }
187 fn create_empty() -> Self {
189 Self {
190 collection_name: core::default::Default::default(),
191 target: core::default::Default::default(),
192 context: core::default::Default::default(),
193 filter: core::default::Default::default(),
194 limit: core::default::Default::default(),
195 with_payload: core::default::Default::default(),
196 params: core::default::Default::default(),
197 offset: core::default::Default::default(),
198 using: core::default::Default::default(),
199 with_vectors: core::default::Default::default(),
200 lookup_from: core::default::Default::default(),
201 read_consistency: core::default::Default::default(),
202 timeout: core::default::Default::default(),
203 shard_key_selector: core::default::Default::default(),
204 }
205 }
206}
207
208impl From<DiscoverPointsBuilder> for DiscoverPoints {
209 fn from(value: DiscoverPointsBuilder) -> Self {
210 value.build_inner().unwrap_or_else(|_| {
211 panic!(
212 "Failed to convert {0} to {1}",
213 "DiscoverPointsBuilder", "DiscoverPoints"
214 )
215 })
216 }
217}
218
219impl DiscoverPointsBuilder {
220 pub fn build(self) -> DiscoverPoints {
222 self.build_inner().unwrap_or_else(|_| {
223 panic!(
224 "Failed to build {0} into {1}",
225 "DiscoverPointsBuilder", "DiscoverPoints"
226 )
227 })
228 }
229}
230
231impl DiscoverPointsBuilder {
232 pub(crate) fn empty() -> Self {
233 Self::create_empty()
234 }
235}
236
237#[non_exhaustive]
239#[derive(Debug)]
240pub enum DiscoverPointsBuilderError {
241 UninitializedField(&'static str),
243 ValidationError(String),
245}
246
247impl std::fmt::Display for DiscoverPointsBuilderError {
249 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
250 match self {
251 Self::UninitializedField(field) => {
252 write!(f, "`{field}` must be initialized")
253 }
254 Self::ValidationError(error) => write!(f, "{error}"),
255 }
256 }
257}
258
259impl std::error::Error for DiscoverPointsBuilderError {}
261
262impl From<derive_builder::UninitializedFieldError> for DiscoverPointsBuilderError {
264 fn from(error: derive_builder::UninitializedFieldError) -> Self {
265 Self::UninitializedField(error.field_name())
266 }
267}
268
269impl From<String> for DiscoverPointsBuilderError {
271 fn from(error: String) -> Self {
272 Self::ValidationError(error)
273 }
274}