1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct RecommendPointsBuilder {
6 pub(crate) collection_name: Option<String>,
8 pub(crate) positive: Option<Vec<PointId>>,
10 pub(crate) negative: Option<Vec<PointId>>,
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) score_threshold: Option<Option<f32>>,
22 pub(crate) offset: Option<Option<u64>>,
24 pub(crate) using: Option<Option<String>>,
26 with_vectors: Option<with_vectors_selector::SelectorOptions>,
28 pub(crate) lookup_from: Option<Option<LookupLocation>>,
30 read_consistency: Option<read_consistency::Value>,
32 pub(crate) strategy: Option<Option<i32>>,
34 pub(crate) positive_vectors: Option<Vec<Vector>>,
36 pub(crate) negative_vectors: Option<Vec<Vector>>,
38 pub(crate) timeout: Option<Option<u64>>,
40 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
42}
43
44impl RecommendPointsBuilder {
45 #[allow(unused_mut)]
47 pub fn collection_name(self, value: String) -> Self {
48 let mut new = self;
49 new.collection_name = Option::Some(value);
50 new
51 }
52 #[allow(unused_mut)]
54 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
55 let mut new = self;
56 new.filter = Option::Some(Option::Some(value.into()));
57 new
58 }
59 #[allow(unused_mut)]
61 pub fn limit(self, value: u64) -> Self {
62 let mut new = self;
63 new.limit = Option::Some(value);
64 new
65 }
66 #[allow(unused_mut)]
68 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
69 self,
70 value: VALUE,
71 ) -> Self {
72 let mut new = self;
73 new.with_payload = Option::Some(value.into());
74 new
75 }
76 #[allow(unused_mut)]
78 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
79 let mut new = self;
80 new.params = Option::Some(Option::Some(value.into()));
81 new
82 }
83 #[allow(unused_mut)]
85 pub fn score_threshold(self, value: f32) -> Self {
86 let mut new = self;
87 new.score_threshold = Option::Some(Option::Some(value));
88 new
89 }
90 #[allow(unused_mut)]
92 pub fn offset(self, value: u64) -> Self {
93 let mut new = self;
94 new.offset = Option::Some(Option::Some(value));
95 new
96 }
97 #[allow(unused_mut)]
99 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
100 let mut new = self;
101 new.using = Option::Some(Option::Some(value.into()));
102 new
103 }
104 #[allow(unused_mut)]
106 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
107 self,
108 value: VALUE,
109 ) -> Self {
110 let mut new = self;
111 new.with_vectors = Option::Some(value.into());
112 new
113 }
114 #[allow(unused_mut)]
116 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
117 let mut new = self;
118 new.lookup_from = Option::Some(Option::Some(value.into()));
119 new
120 }
121 #[allow(unused_mut)]
123 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
124 self,
125 value: VALUE,
126 ) -> Self {
127 let mut new = self;
128 new.read_consistency = Option::Some(value.into());
129 new
130 }
131 #[allow(unused_mut)]
133 pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
134 let mut new = self;
135 new.strategy = Option::Some(Option::Some(value.into()));
136 new
137 }
138 #[allow(unused_mut)]
140 pub fn timeout(self, value: u64) -> Self {
141 let mut new = self;
142 new.timeout = Option::Some(Option::Some(value));
143 new
144 }
145 #[allow(unused_mut)]
147 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
148 self,
149 value: VALUE,
150 ) -> Self {
151 let mut new = self;
152 new.shard_key_selector = Option::Some(Option::Some(value.into()));
153 new
154 }
155
156 fn build_inner(self) -> Result<RecommendPoints, RecommendPointsBuilderError> {
157 Ok(RecommendPoints {
158 collection_name: match self.collection_name {
159 Some(value) => value,
160 None => {
161 return Result::Err(core::convert::Into::into(
162 ::derive_builder::UninitializedFieldError::from("collection_name"),
163 ));
164 }
165 },
166 positive: self.positive.unwrap_or_default(),
167 negative: self.negative.unwrap_or_default(),
168 filter: self.filter.unwrap_or_default(),
169 limit: match self.limit {
170 Some(value) => value,
171 None => {
172 return Result::Err(core::convert::Into::into(
173 ::derive_builder::UninitializedFieldError::from("limit"),
174 ));
175 }
176 },
177 with_payload: { convert_option(&self.with_payload) },
178 params: self.params.unwrap_or_default(),
179 score_threshold: self.score_threshold.unwrap_or_default(),
180 offset: self.offset.unwrap_or_default(),
181 using: self.using.unwrap_or_default(),
182 with_vectors: { convert_option(&self.with_vectors) },
183 lookup_from: self.lookup_from.unwrap_or_default(),
184 read_consistency: { convert_option(&self.read_consistency) },
185 strategy: self.strategy.unwrap_or_default(),
186 positive_vectors: self.positive_vectors.unwrap_or_default(),
187 negative_vectors: self.negative_vectors.unwrap_or_default(),
188 timeout: self.timeout.unwrap_or_default(),
189 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
190 })
191 }
192 fn create_empty() -> Self {
194 Self {
195 collection_name: core::default::Default::default(),
196 positive: core::default::Default::default(),
197 negative: core::default::Default::default(),
198 filter: core::default::Default::default(),
199 limit: core::default::Default::default(),
200 with_payload: core::default::Default::default(),
201 params: core::default::Default::default(),
202 score_threshold: core::default::Default::default(),
203 offset: core::default::Default::default(),
204 using: core::default::Default::default(),
205 with_vectors: core::default::Default::default(),
206 lookup_from: core::default::Default::default(),
207 read_consistency: core::default::Default::default(),
208 strategy: core::default::Default::default(),
209 positive_vectors: core::default::Default::default(),
210 negative_vectors: core::default::Default::default(),
211 timeout: core::default::Default::default(),
212 shard_key_selector: core::default::Default::default(),
213 }
214 }
215}
216
217impl From<RecommendPointsBuilder> for RecommendPoints {
218 fn from(value: RecommendPointsBuilder) -> Self {
219 value.build_inner().unwrap_or_else(|_| {
220 panic!(
221 "Failed to convert {0} to {1}",
222 "RecommendPointsBuilder", "RecommendPoints"
223 )
224 })
225 }
226}
227
228impl RecommendPointsBuilder {
229 pub fn build(self) -> RecommendPoints {
231 self.build_inner().unwrap_or_else(|_| {
232 panic!(
233 "Failed to build {0} into {1}",
234 "RecommendPointsBuilder", "RecommendPoints"
235 )
236 })
237 }
238}
239
240impl RecommendPointsBuilder {
241 pub(crate) fn empty() -> Self {
242 Self::create_empty()
243 }
244}
245
246#[non_exhaustive]
248#[derive(Debug)]
249pub enum RecommendPointsBuilderError {
250 UninitializedField(&'static str),
252 ValidationError(String),
254}
255
256impl std::fmt::Display for RecommendPointsBuilderError {
258 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
259 match self {
260 Self::UninitializedField(field) => {
261 write!(f, "`{field}` must be initialized")
262 }
263 Self::ValidationError(error) => write!(f, "{error}"),
264 }
265 }
266}
267
268impl std::error::Error for RecommendPointsBuilderError {}
270
271impl From<derive_builder::UninitializedFieldError> for RecommendPointsBuilderError {
273 fn from(error: derive_builder::UninitializedFieldError) -> Self {
274 Self::UninitializedField(error.field_name())
275 }
276}
277
278impl From<String> for RecommendPointsBuilderError {
280 fn from(error: String) -> Self {
281 Self::ValidationError(error)
282 }
283}