Skip to main content

qdrant_client/builders/
get_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[derive(Clone)]
5pub struct GetPointsBuilder {
6    /// name of the collection
7    pub(crate) collection_name: Option<String>,
8    /// List of points to retrieve
9    pub(crate) ids: Option<Vec<PointId>>,
10    /// Options for specifying which payload to include or not
11    with_payload: Option<with_payload_selector::SelectorOptions>,
12    /// Options for specifying which vectors to include into response
13    with_vectors: Option<with_vectors_selector::SelectorOptions>,
14    /// Options for specifying read consistency guarantees
15    read_consistency: Option<read_consistency::Value>,
16    /// Specify in which shards to look for the points, if not specified - look in all shards
17    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
18    /// If set, overrides global timeout setting for this request. Unit is seconds.
19    pub(crate) timeout: Option<Option<u64>>,
20}
21
22impl GetPointsBuilder {
23    /// name of the collection
24    pub fn collection_name(self, value: String) -> Self {
25        let mut new = self;
26        new.collection_name = Option::Some(value);
27        new
28    }
29    /// List of points to retrieve
30    pub fn ids(self, value: Vec<PointId>) -> Self {
31        let mut new = self;
32        new.ids = Option::Some(value);
33        new
34    }
35    /// Options for specifying which payload to include or not
36    pub fn with_payload<VALUE: core::convert::Into<with_payload_selector::SelectorOptions>>(
37        self,
38        value: VALUE,
39    ) -> Self {
40        let mut new = self;
41        new.with_payload = Option::Some(value.into());
42        new
43    }
44    /// Options for specifying which vectors to include into response
45    pub fn with_vectors<VALUE: core::convert::Into<with_vectors_selector::SelectorOptions>>(
46        self,
47        value: VALUE,
48    ) -> Self {
49        let mut new = self;
50        new.with_vectors = Option::Some(value.into());
51        new
52    }
53    /// Options for specifying read consistency guarantees
54    pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
55        self,
56        value: VALUE,
57    ) -> Self {
58        let mut new = self;
59        new.read_consistency = Option::Some(value.into());
60        new
61    }
62    /// Specify in which shards to look for the points, if not specified - look in all shards
63    pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
64        self,
65        value: VALUE,
66    ) -> Self {
67        let mut new = self;
68        new.shard_key_selector = Option::Some(Option::Some(value.into()));
69        new
70    }
71    /// If set, overrides global timeout setting for this request. Unit is seconds.
72    pub fn timeout(self, value: u64) -> Self {
73        let mut new = self;
74        new.timeout = Option::Some(Option::Some(value));
75        new
76    }
77
78    fn build_inner(self) -> Result<GetPoints, GetPointsBuilderError> {
79        Ok(GetPoints {
80            collection_name: match self.collection_name {
81                Some(value) => value,
82                None => {
83                    return Result::Err(core::convert::Into::into(
84                        ::derive_builder::UninitializedFieldError::from("collection_name"),
85                    ));
86                }
87            },
88            ids: match self.ids {
89                Some(value) => value,
90                None => {
91                    return Result::Err(core::convert::Into::into(
92                        ::derive_builder::UninitializedFieldError::from("ids"),
93                    ));
94                }
95            },
96            with_payload: { convert_option(&self.with_payload) },
97            with_vectors: { convert_option(&self.with_vectors) },
98            read_consistency: { convert_option(&self.read_consistency) },
99            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
100            timeout: self.timeout.unwrap_or_default(),
101        })
102    }
103    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
104    fn create_empty() -> Self {
105        Self {
106            collection_name: core::default::Default::default(),
107            ids: core::default::Default::default(),
108            with_payload: core::default::Default::default(),
109            with_vectors: core::default::Default::default(),
110            read_consistency: core::default::Default::default(),
111            shard_key_selector: core::default::Default::default(),
112            timeout: core::default::Default::default(),
113        }
114    }
115}
116
117impl From<GetPointsBuilder> for GetPoints {
118    fn from(value: GetPointsBuilder) -> Self {
119        value.build_inner().unwrap_or_else(|_| {
120            panic!(
121                "Failed to convert {0} to {1}",
122                "GetPointsBuilder", "GetPoints"
123            )
124        })
125    }
126}
127
128impl GetPointsBuilder {
129    /// Builds the desired type. Can often be omitted.
130    pub fn build(self) -> GetPoints {
131        self.build_inner().unwrap_or_else(|_| {
132            panic!(
133                "Failed to build {0} into {1}",
134                "GetPointsBuilder", "GetPoints"
135            )
136        })
137    }
138}
139
140impl GetPointsBuilder {
141    pub(crate) fn empty() -> Self {
142        Self::create_empty()
143    }
144}
145
146/// Error type for GetPointsBuilder
147#[non_exhaustive]
148#[derive(Debug)]
149pub enum GetPointsBuilderError {
150    /// Uninitialized field
151    UninitializedField(&'static str),
152    /// Custom validation error
153    ValidationError(String),
154}
155
156// Implementing the From trait for conversion from UninitializedFieldError
157impl From<derive_builder::UninitializedFieldError> for GetPointsBuilderError {
158    fn from(s: derive_builder::UninitializedFieldError) -> Self {
159        Self::UninitializedField(s.field_name())
160    }
161}
162
163// Implementing the From trait for conversion from String
164impl From<String> for GetPointsBuilderError {
165    fn from(s: String) -> Self {
166        Self::ValidationError(s)
167    }
168}
169
170// Implementing the Display trait for better error messages
171impl std::fmt::Display for GetPointsBuilderError {
172    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
173        match self {
174            Self::UninitializedField(ref field) => {
175                write!(f, "`{field}` must be initialized")
176            }
177            Self::ValidationError(ref error) => {
178                write!(f, "{error}")
179            }
180        }
181    }
182}
183
184// Implementing the Error trait
185impl std::error::Error for GetPointsBuilderError {}