qdrant_client/builders/
discover_points_builder.rs1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct DiscoverPointsBuilder {
7 pub(crate) collection_name: Option<String>,
9 pub(crate) target: Option<Option<TargetVector>>,
11 pub(crate) context: Option<Vec<ContextExamplePair>>,
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) offset: Option<Option<u64>>,
23 pub(crate) using: Option<Option<String>>,
25 with_vectors: Option<with_vectors_selector::SelectorOptions>,
27 pub(crate) lookup_from: Option<Option<LookupLocation>>,
29 read_consistency: Option<read_consistency::Value>,
31 pub(crate) timeout: Option<Option<u64>>,
33 pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
35}
36
37impl DiscoverPointsBuilder {
38 pub fn collection_name(self, value: String) -> Self {
40 let mut new = self;
41 new.collection_name = Option::Some(value);
42 new
43 }
44 pub fn target<VALUE: core::convert::Into<TargetVector>>(self, value: VALUE) -> Self {
46 let mut new = self;
47 new.target = Option::Some(Option::Some(value.into()));
48 new
49 }
50 pub fn context(self, value: Vec<ContextExamplePair>) -> Self {
52 let mut new = self;
53 new.context = Option::Some(value);
54 new
55 }
56 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
58 let mut new = self;
59 new.filter = Option::Some(Option::Some(value.into()));
60 new
61 }
62 pub fn limit(self, value: u64) -> Self {
64 let mut new = self;
65 new.limit = Option::Some(value);
66 new
67 }
68 pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
70 self,
71 value: VALUE,
72 ) -> Self {
73 let mut new = self;
74 new.with_payload = Option::Some(value.into());
75 new
76 }
77 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 pub fn offset(self, value: u64) -> Self {
85 let mut new = self;
86 new.offset = Option::Some(Option::Some(value));
87 new
88 }
89 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
91 let mut new = self;
92 new.using = Option::Some(Option::Some(value.into()));
93 new
94 }
95 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
97 self,
98 value: VALUE,
99 ) -> Self {
100 let mut new = self;
101 new.with_vectors = Option::Some(value.into());
102 new
103 }
104 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
106 let mut new = self;
107 new.lookup_from = Option::Some(Option::Some(value.into()));
108 new
109 }
110 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
112 self,
113 value: VALUE,
114 ) -> Self {
115 let mut new = self;
116 new.read_consistency = Option::Some(value.into());
117 new
118 }
119 pub fn timeout(self, value: u64) -> Self {
121 let mut new = self;
122 new.timeout = Option::Some(Option::Some(value));
123 new
124 }
125 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
127 self,
128 value: VALUE,
129 ) -> Self {
130 let mut new = self;
131 new.shard_key_selector = Option::Some(Option::Some(value.into()));
132 new
133 }
134
135 fn build_inner(self) -> Result<DiscoverPoints, DiscoverPointsBuilderError> {
136 Ok(DiscoverPoints {
137 collection_name: match self.collection_name {
138 Some(value) => value,
139 None => {
140 return Result::Err(core::convert::Into::into(
141 ::derive_builder::UninitializedFieldError::from("collection_name"),
142 ));
143 }
144 },
145 target: self.target.unwrap_or_default(),
146 context: match self.context {
147 Some(value) => value,
148 None => {
149 return Result::Err(core::convert::Into::into(
150 ::derive_builder::UninitializedFieldError::from("context"),
151 ));
152 }
153 },
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 offset: self.offset.unwrap_or_default(),
166 using: self.using.unwrap_or_default(),
167 with_vectors: { convert_option(&self.with_vectors) },
168 lookup_from: self.lookup_from.unwrap_or_default(),
169 read_consistency: { convert_option(&self.read_consistency) },
170 timeout: self.timeout.unwrap_or_default(),
171 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
172 })
173 }
174 fn create_empty() -> Self {
176 Self {
177 collection_name: core::default::Default::default(),
178 target: core::default::Default::default(),
179 context: core::default::Default::default(),
180 filter: core::default::Default::default(),
181 limit: core::default::Default::default(),
182 with_payload: core::default::Default::default(),
183 params: core::default::Default::default(),
184 offset: core::default::Default::default(),
185 using: core::default::Default::default(),
186 with_vectors: core::default::Default::default(),
187 lookup_from: core::default::Default::default(),
188 read_consistency: core::default::Default::default(),
189 timeout: core::default::Default::default(),
190 shard_key_selector: core::default::Default::default(),
191 }
192 }
193}
194
195impl From<DiscoverPointsBuilder> for DiscoverPoints {
196 fn from(value: DiscoverPointsBuilder) -> Self {
197 value.build_inner().unwrap_or_else(|_| {
198 panic!(
199 "Failed to convert {0} to {1}",
200 "DiscoverPointsBuilder", "DiscoverPoints"
201 )
202 })
203 }
204}
205
206impl DiscoverPointsBuilder {
207 pub fn build(self) -> DiscoverPoints {
209 self.build_inner().unwrap_or_else(|_| {
210 panic!(
211 "Failed to build {0} into {1}",
212 "DiscoverPointsBuilder", "DiscoverPoints"
213 )
214 })
215 }
216}
217
218impl DiscoverPointsBuilder {
219 pub(crate) fn empty() -> Self {
220 Self::create_empty()
221 }
222}
223
224#[non_exhaustive]
226#[derive(Debug)]
227pub enum DiscoverPointsBuilderError {
228 UninitializedField(&'static str),
230 ValidationError(String),
232}
233
234impl std::fmt::Display for DiscoverPointsBuilderError {
236 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
237 match self {
238 Self::UninitializedField(field) => {
239 write!(f, "`{field}` must be initialized")
240 }
241 Self::ValidationError(error) => write!(f, "{error}"),
242 }
243 }
244}
245
246impl std::error::Error for DiscoverPointsBuilderError {}
248
249impl From<derive_builder::UninitializedFieldError> for DiscoverPointsBuilderError {
251 fn from(error: derive_builder::UninitializedFieldError) -> Self {
252 Self::UninitializedField(error.field_name())
253 }
254}
255
256impl From<String> for DiscoverPointsBuilderError {
258 fn from(error: String) -> Self {
259 Self::ValidationError(error)
260 }
261}