1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct RecommendPointsBuilder {
7 pub(crate) collection_name: Option<String>,
9 pub(crate) positive: Option<Vec<PointId>>,
11 pub(crate) negative: Option<Vec<PointId>>,
13 pub(crate) filter: Option<Option<Filter>>,
15 pub(crate) limit: Option<u64>,
17 with_payload: Option<with_payload_selector::SelectorOptions>,
19 pub(crate) params: Option<Option<SearchParams>>,
21 pub(crate) score_threshold: Option<Option<f32>>,
23 pub(crate) offset: Option<Option<u64>>,
25 pub(crate) using: Option<Option<String>>,
27 with_vectors: Option<with_vectors_selector::SelectorOptions>,
29 pub(crate) lookup_from: Option<Option<LookupLocation>>,
31 read_consistency: Option<read_consistency::Value>,
33 pub(crate) strategy: Option<Option<i32>>,
35 pub(crate) positive_vectors: Option<Vec<Vector>>,
37 pub(crate) negative_vectors: Option<Vec<Vector>>,
39 pub(crate) timeout: Option<Option<u64>>,
41 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
43}
44
45impl RecommendPointsBuilder {
46 pub fn collection_name(self, value: String) -> Self {
48 let mut new = self;
49 new.collection_name = Option::Some(value);
50 new
51 }
52 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
54 let mut new = self;
55 new.filter = Option::Some(Option::Some(value.into()));
56 new
57 }
58 pub fn limit(self, value: u64) -> Self {
60 let mut new = self;
61 new.limit = Option::Some(value);
62 new
63 }
64 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
66 self,
67 value: VALUE,
68 ) -> Self {
69 let mut new = self;
70 new.with_payload = Option::Some(value.into());
71 new
72 }
73 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
75 let mut new = self;
76 new.params = Option::Some(Option::Some(value.into()));
77 new
78 }
79 pub fn score_threshold(self, value: f32) -> Self {
81 let mut new = self;
82 new.score_threshold = Option::Some(Option::Some(value));
83 new
84 }
85 pub fn offset(self, value: u64) -> Self {
87 let mut new = self;
88 new.offset = Option::Some(Option::Some(value));
89 new
90 }
91 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
93 let mut new = self;
94 new.using = Option::Some(Option::Some(value.into()));
95 new
96 }
97 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
99 self,
100 value: VALUE,
101 ) -> Self {
102 let mut new = self;
103 new.with_vectors = Option::Some(value.into());
104 new
105 }
106 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
108 let mut new = self;
109 new.lookup_from = Option::Some(Option::Some(value.into()));
110 new
111 }
112 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
114 self,
115 value: VALUE,
116 ) -> Self {
117 let mut new = self;
118 new.read_consistency = Option::Some(value.into());
119 new
120 }
121 pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
123 let mut new = self;
124 new.strategy = Option::Some(Option::Some(value.into()));
125 new
126 }
127 pub fn timeout(self, value: u64) -> Self {
129 let mut new = self;
130 new.timeout = Option::Some(Option::Some(value));
131 new
132 }
133 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
135 self,
136 value: VALUE,
137 ) -> Self {
138 let mut new = self;
139 new.shard_key_selector = Option::Some(Option::Some(value.into()));
140 new
141 }
142
143 fn build_inner(self) -> Result<RecommendPoints, RecommendPointsBuilderError> {
144 Ok(RecommendPoints {
145 collection_name: match self.collection_name {
146 Some(value) => value,
147 None => {
148 return Result::Err(core::convert::Into::into(
149 ::derive_builder::UninitializedFieldError::from("collection_name"),
150 ));
151 }
152 },
153 positive: self.positive.unwrap_or_default(),
154 negative: self.negative.unwrap_or_default(),
155 filter: self.filter.unwrap_or_default(),
156 limit: match self.limit {
157 Some(value) => value,
158 None => {
159 return Result::Err(core::convert::Into::into(
160 ::derive_builder::UninitializedFieldError::from("limit"),
161 ));
162 }
163 },
164 with_payload: { convert_option(&self.with_payload) },
165 params: self.params.unwrap_or_default(),
166 score_threshold: self.score_threshold.unwrap_or_default(),
167 offset: self.offset.unwrap_or_default(),
168 using: self.using.unwrap_or_default(),
169 with_vectors: { convert_option(&self.with_vectors) },
170 lookup_from: self.lookup_from.unwrap_or_default(),
171 read_consistency: { convert_option(&self.read_consistency) },
172 strategy: self.strategy.unwrap_or_default(),
173 positive_vectors: self.positive_vectors.unwrap_or_default(),
174 negative_vectors: self.negative_vectors.unwrap_or_default(),
175 timeout: self.timeout.unwrap_or_default(),
176 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
177 })
178 }
179 fn create_empty() -> Self {
181 Self {
182 collection_name: core::default::Default::default(),
183 positive: core::default::Default::default(),
184 negative: core::default::Default::default(),
185 filter: core::default::Default::default(),
186 limit: core::default::Default::default(),
187 with_payload: core::default::Default::default(),
188 params: core::default::Default::default(),
189 score_threshold: core::default::Default::default(),
190 offset: core::default::Default::default(),
191 using: core::default::Default::default(),
192 with_vectors: core::default::Default::default(),
193 lookup_from: core::default::Default::default(),
194 read_consistency: core::default::Default::default(),
195 strategy: core::default::Default::default(),
196 positive_vectors: core::default::Default::default(),
197 negative_vectors: core::default::Default::default(),
198 timeout: core::default::Default::default(),
199 shard_key_selector: core::default::Default::default(),
200 }
201 }
202}
203
204impl From<RecommendPointsBuilder> for RecommendPoints {
205 fn from(value: RecommendPointsBuilder) -> Self {
206 value.build_inner().unwrap_or_else(|_| {
207 panic!(
208 "Failed to convert {0} to {1}",
209 "RecommendPointsBuilder", "RecommendPoints"
210 )
211 })
212 }
213}
214
215impl RecommendPointsBuilder {
216 pub fn build(self) -> RecommendPoints {
218 self.build_inner().unwrap_or_else(|_| {
219 panic!(
220 "Failed to build {0} into {1}",
221 "RecommendPointsBuilder", "RecommendPoints"
222 )
223 })
224 }
225}
226
227impl RecommendPointsBuilder {
228 pub(crate) fn empty() -> Self {
229 Self::create_empty()
230 }
231}
232
233#[non_exhaustive]
235#[derive(Debug)]
236pub enum RecommendPointsBuilderError {
237 UninitializedField(&'static str),
239 ValidationError(String),
241}
242
243impl std::fmt::Display for RecommendPointsBuilderError {
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 RecommendPointsBuilderError {}
257
258impl From<derive_builder::UninitializedFieldError> for RecommendPointsBuilderError {
260 fn from(error: derive_builder::UninitializedFieldError) -> Self {
261 Self::UninitializedField(error.field_name())
262 }
263}
264
265impl From<String> for RecommendPointsBuilderError {
267 fn from(error: String) -> Self {
268 Self::ValidationError(error)
269 }
270}