Skip to main content

qdrant_client/builders/
scroll_points_builder.rs

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