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 pub fn collection_name(self, value: String) -> Self {
39 let mut new = self;
40 new.collection_name = Option::Some(value);
41 new
42 }
43 pub fn target<VALUE: core::convert::Into<TargetVector>>(self, value: VALUE) -> Self {
45 let mut new = self;
46 new.target = Option::Some(Option::Some(value.into()));
47 new
48 }
49 pub fn context(self, value: Vec<ContextExamplePair>) -> Self {
51 let mut new = self;
52 new.context = Option::Some(value);
53 new
54 }
55 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
57 let mut new = self;
58 new.filter = Option::Some(Option::Some(value.into()));
59 new
60 }
61 pub fn limit(self, value: u64) -> Self {
63 let mut new = self;
64 new.limit = Option::Some(value);
65 new
66 }
67 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 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
78 let mut new = self;
79 new.params = Option::Some(Option::Some(value.into()));
80 new
81 }
82 pub fn offset(self, value: u64) -> Self {
84 let mut new = self;
85 new.offset = Option::Some(Option::Some(value));
86 new
87 }
88 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
90 let mut new = self;
91 new.using = Option::Some(Option::Some(value.into()));
92 new
93 }
94 pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
96 self,
97 value: VALUE,
98 ) -> Self {
99 let mut new = self;
100 new.with_vectors = Option::Some(value.into());
101 new
102 }
103 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
105 let mut new = self;
106 new.lookup_from = Option::Some(Option::Some(value.into()));
107 new
108 }
109 pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
111 self,
112 value: VALUE,
113 ) -> Self {
114 let mut new = self;
115 new.read_consistency = Option::Some(value.into());
116 new
117 }
118 pub fn timeout(self, value: u64) -> Self {
120 let mut new = self;
121 new.timeout = Option::Some(Option::Some(value));
122 new
123 }
124 pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
126 self,
127 value: VALUE,
128 ) -> Self {
129 let mut new = self;
130 new.shard_key_selector = Option::Some(Option::Some(value.into()));
131 new
132 }
133
134 fn build_inner(self) -> Result<DiscoverPoints, DiscoverPointsBuilderError> {
135 Ok(DiscoverPoints {
136 collection_name: match self.collection_name {
137 Some(value) => value,
138 None => {
139 return Result::Err(core::convert::Into::into(
140 ::derive_builder::UninitializedFieldError::from("collection_name"),
141 ));
142 }
143 },
144 target: self.target.unwrap_or_default(),
145 context: match self.context {
146 Some(value) => value,
147 None => {
148 return Result::Err(core::convert::Into::into(
149 ::derive_builder::UninitializedFieldError::from("context"),
150 ));
151 }
152 },
153 filter: self.filter.unwrap_or_default(),
154 limit: match self.limit {
155 Some(value) => value,
156 None => {
157 return Result::Err(core::convert::Into::into(
158 ::derive_builder::UninitializedFieldError::from("limit"),
159 ));
160 }
161 },
162 with_payload: { convert_option(&self.with_payload) },
163 params: self.params.unwrap_or_default(),
164 offset: self.offset.unwrap_or_default(),
165 using: self.using.unwrap_or_default(),
166 with_vectors: { convert_option(&self.with_vectors) },
167 lookup_from: self.lookup_from.unwrap_or_default(),
168 read_consistency: { convert_option(&self.read_consistency) },
169 timeout: self.timeout.unwrap_or_default(),
170 shard_key_selector: self.shard_key_selector.unwrap_or_default(),
171 })
172 }
173 fn create_empty() -> Self {
175 Self {
176 collection_name: core::default::Default::default(),
177 target: core::default::Default::default(),
178 context: core::default::Default::default(),
179 filter: core::default::Default::default(),
180 limit: core::default::Default::default(),
181 with_payload: core::default::Default::default(),
182 params: core::default::Default::default(),
183 offset: core::default::Default::default(),
184 using: core::default::Default::default(),
185 with_vectors: core::default::Default::default(),
186 lookup_from: core::default::Default::default(),
187 read_consistency: core::default::Default::default(),
188 timeout: core::default::Default::default(),
189 shard_key_selector: core::default::Default::default(),
190 }
191 }
192}
193
194impl From<DiscoverPointsBuilder> for DiscoverPoints {
195 fn from(value: DiscoverPointsBuilder) -> Self {
196 value.build_inner().unwrap_or_else(|_| {
197 panic!(
198 "Failed to convert {0} to {1}",
199 "DiscoverPointsBuilder", "DiscoverPoints"
200 )
201 })
202 }
203}
204
205impl DiscoverPointsBuilder {
206 pub fn build(self) -> DiscoverPoints {
208 self.build_inner().unwrap_or_else(|_| {
209 panic!(
210 "Failed to build {0} into {1}",
211 "DiscoverPointsBuilder", "DiscoverPoints"
212 )
213 })
214 }
215}
216
217impl DiscoverPointsBuilder {
218 pub(crate) fn empty() -> Self {
219 Self::create_empty()
220 }
221}
222
223#[non_exhaustive]
225#[derive(Debug)]
226pub enum DiscoverPointsBuilderError {
227 UninitializedField(&'static str),
229 ValidationError(String),
231}
232
233impl std::fmt::Display for DiscoverPointsBuilderError {
235 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
236 match self {
237 Self::UninitializedField(field) => {
238 write!(f, "`{field}` must be initialized")
239 }
240 Self::ValidationError(error) => write!(f, "{error}"),
241 }
242 }
243}
244
245impl std::error::Error for DiscoverPointsBuilderError {}
247
248impl From<derive_builder::UninitializedFieldError> for DiscoverPointsBuilderError {
250 fn from(error: derive_builder::UninitializedFieldError) -> Self {
251 Self::UninitializedField(error.field_name())
252 }
253}
254
255impl From<String> for DiscoverPointsBuilderError {
257 fn from(error: String) -> Self {
258 Self::ValidationError(error)
259 }
260}