Skip to main content

qdrant_client/builders/
scroll_points_builder.rs

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