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 pub fn collection_name(self, value: String) -> Self {
47 let mut new = self;
48 new.collection_name = Option::Some(value);
49 new
50 }
51 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
53 let mut new = self;
54 new.filter = Option::Some(Option::Some(value.into()));
55 new
56 }
57 pub fn limit(self, value: u64) -> Self {
59 let mut new = self;
60 new.limit = Option::Some(value);
61 new
62 }
63 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
65 self,
66 value: VALUE,
67 ) -> Self {
68 let mut new = self;
69 new.with_payload = Option::Some(value.into());
70 new
71 }
72 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
74 let mut new = self;
75 new.params = Option::Some(Option::Some(value.into()));
76 new
77 }
78 pub fn score_threshold(self, value: f32) -> Self {
80 let mut new = self;
81 new.score_threshold = Option::Some(Option::Some(value));
82 new
83 }
84 pub fn offset(self, value: u64) -> Self {
86 let mut new = self;
87 new.offset = Option::Some(Option::Some(value));
88 new
89 }
90 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
92 let mut new = self;
93 new.using = Option::Some(Option::Some(value.into()));
94 new
95 }
96 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
98 self,
99 value: VALUE,
100 ) -> Self {
101 let mut new = self;
102 new.with_vectors = Option::Some(value.into());
103 new
104 }
105 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
107 let mut new = self;
108 new.lookup_from = Option::Some(Option::Some(value.into()));
109 new
110 }
111 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
113 self,
114 value: VALUE,
115 ) -> Self {
116 let mut new = self;
117 new.read_consistency = Option::Some(value.into());
118 new
119 }
120 pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
122 let mut new = self;
123 new.strategy = Option::Some(Option::Some(value.into()));
124 new
125 }
126 pub fn timeout(self, value: u64) -> Self {
128 let mut new = self;
129 new.timeout = Option::Some(Option::Some(value));
130 new
131 }
132 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
134 self,
135 value: VALUE,
136 ) -> Self {
137 let mut new = self;
138 new.shard_key_selector = Option::Some(Option::Some(value.into()));
139 new
140 }
141
142 fn build_inner(self) -> Result<RecommendPoints, RecommendPointsBuilderError> {
143 Ok(RecommendPoints {
144 collection_name: match self.collection_name {
145 Some(value) => value,
146 None => {
147 return Result::Err(core::convert::Into::into(
148 ::derive_builder::UninitializedFieldError::from("collection_name"),
149 ));
150 }
151 },
152 positive: self.positive.unwrap_or_default(),
153 negative: self.negative.unwrap_or_default(),
154 filter: self.filter.unwrap_or_default(),
155 limit: match self.limit {
156 Some(value) => value,
157 None => {
158 return Result::Err(core::convert::Into::into(
159 ::derive_builder::UninitializedFieldError::from("limit"),
160 ));
161 }
162 },
163 with_payload: { convert_option(&self.with_payload) },
164 params: self.params.unwrap_or_default(),
165 score_threshold: self.score_threshold.unwrap_or_default(),
166 offset: self.offset.unwrap_or_default(),
167 using: self.using.unwrap_or_default(),
168 with_vectors: { convert_option(&self.with_vectors) },
169 lookup_from: self.lookup_from.unwrap_or_default(),
170 read_consistency: { convert_option(&self.read_consistency) },
171 strategy: self.strategy.unwrap_or_default(),
172 positive_vectors: self.positive_vectors.unwrap_or_default(),
173 negative_vectors: self.negative_vectors.unwrap_or_default(),
174 timeout: self.timeout.unwrap_or_default(),
175 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
176 })
177 }
178 fn create_empty() -> Self {
180 Self {
181 collection_name: core::default::Default::default(),
182 positive: core::default::Default::default(),
183 negative: core::default::Default::default(),
184 filter: core::default::Default::default(),
185 limit: core::default::Default::default(),
186 with_payload: core::default::Default::default(),
187 params: core::default::Default::default(),
188 score_threshold: core::default::Default::default(),
189 offset: core::default::Default::default(),
190 using: core::default::Default::default(),
191 with_vectors: core::default::Default::default(),
192 lookup_from: core::default::Default::default(),
193 read_consistency: core::default::Default::default(),
194 strategy: core::default::Default::default(),
195 positive_vectors: core::default::Default::default(),
196 negative_vectors: core::default::Default::default(),
197 timeout: core::default::Default::default(),
198 shard_key_selector: core::default::Default::default(),
199 }
200 }
201}
202
203impl From<RecommendPointsBuilder> for RecommendPoints {
204 fn from(value: RecommendPointsBuilder) -> Self {
205 value.build_inner().unwrap_or_else(|_| {
206 panic!(
207 "Failed to convert {0} to {1}",
208 "RecommendPointsBuilder", "RecommendPoints"
209 )
210 })
211 }
212}
213
214impl RecommendPointsBuilder {
215 pub fn build(self) -> RecommendPoints {
217 self.build_inner().unwrap_or_else(|_| {
218 panic!(
219 "Failed to build {0} into {1}",
220 "RecommendPointsBuilder", "RecommendPoints"
221 )
222 })
223 }
224}
225
226impl RecommendPointsBuilder {
227 pub(crate) fn empty() -> Self {
228 Self::create_empty()
229 }
230}
231
232#[non_exhaustive]
234#[derive(Debug)]
235pub enum RecommendPointsBuilderError {
236 UninitializedField(&'static str),
238 ValidationError(String),
240}
241
242impl std::fmt::Display for RecommendPointsBuilderError {
244 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
245 match self {
246 Self::UninitializedField(field) => {
247 write!(f, "`{field}` must be initialized")
248 }
249 Self::ValidationError(error) => write!(f, "{error}"),
250 }
251 }
252}
253
254impl std::error::Error for RecommendPointsBuilderError {}
256
257impl From<derive_builder::UninitializedFieldError> for RecommendPointsBuilderError {
259 fn from(error: derive_builder::UninitializedFieldError) -> Self {
260 Self::UninitializedField(error.field_name())
261 }
262}
263
264impl From<String> for RecommendPointsBuilderError {
266 fn from(error: String) -> Self {
267 Self::ValidationError(error)
268 }
269}