Skip to main content

qdrant_client/builders/
update_point_vectors_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct UpdatePointVectorsBuilder {
5    /// name of the collection
6    pub(crate) collection_name: Option<String>,
7    /// Wait until the changes have been applied?
8    pub(crate) wait: Option<Option<bool>>,
9    /// List of points and vectors to update
10    pub(crate) points: Option<Vec<PointVectors>>,
11    /// Write ordering guarantees
12    pub(crate) ordering: Option<Option<WriteOrdering>>,
13    /// Option for custom sharding to specify used shard keys
14    pub(crate) shard_key_selector: Option<Option<ShardKeySelector>>,
15    /// Optional filter to apply to the update operation. If set, only points matching the filter will be updated.
16    pub(crate) update_filter: Option<Option<Filter>>,
17    /// Timeout for the request in seconds
18    pub(crate) timeout: Option<Option<u64>>,
19}
20
21impl UpdatePointVectorsBuilder {
22    /// name of the collection
23    pub fn collection_name(self, value: String) -> Self {
24        let mut new = self;
25        new.collection_name = Option::Some(value);
26        new
27    }
28    /// Wait until the changes have been applied?
29    pub fn wait(self, value: bool) -> Self {
30        let mut new = self;
31        new.wait = Option::Some(Option::Some(value));
32        new
33    }
34    /// List of points and vectors to update
35    pub fn points(self, value: Vec<PointVectors>) -> Self {
36        let mut new = self;
37        new.points = Option::Some(value);
38        new
39    }
40    /// Write ordering guarantees
41    pub fn ordering<VALUE: core::convert::Into<WriteOrdering>>(self, value: VALUE) -> Self {
42        let mut new = self;
43        new.ordering = Option::Some(Option::Some(value.into()));
44        new
45    }
46    /// Option for custom sharding to specify used shard keys
47    pub fn shard_key_selector<VALUE: core::convert::Into<ShardKeySelector>>(
48        self,
49        value: VALUE,
50    ) -> Self {
51        let mut new = self;
52        new.shard_key_selector = Option::Some(Option::Some(value.into()));
53        new
54    }
55    /// Optional filter to apply to the update operation. If set, only points matching the filter will be updated.
56    pub fn update_filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
57        let mut new = self;
58        new.update_filter = Option::Some(Option::Some(value.into()));
59        new
60    }
61    /// Timeout for the request in seconds
62    pub fn timeout(self, value: u64) -> Self {
63        let mut new = self;
64        new.timeout = Option::Some(Option::Some(value));
65        new
66    }
67
68    fn build_inner(self) -> Result<UpdatePointVectors, UpdatePointVectorsBuilderError> {
69        Ok(UpdatePointVectors {
70            collection_name: match self.collection_name {
71                Some(value) => value,
72                None => {
73                    return Result::Err(core::convert::Into::into(
74                        ::derive_builder::UninitializedFieldError::from("collection_name"),
75                    ));
76                }
77            },
78            wait: self.wait.unwrap_or_default(),
79            points: match self.points {
80                Some(value) => value,
81                None => {
82                    return Result::Err(core::convert::Into::into(
83                        ::derive_builder::UninitializedFieldError::from("points"),
84                    ));
85                }
86            },
87            ordering: self.ordering.unwrap_or_default(),
88            shard_key_selector: self.shard_key_selector.unwrap_or_default(),
89            update_filter: self.update_filter.unwrap_or_default(),
90            timeout: self.timeout.unwrap_or_default(),
91        })
92    }
93    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
94    fn create_empty() -> Self {
95        Self {
96            collection_name: core::default::Default::default(),
97            wait: core::default::Default::default(),
98            points: core::default::Default::default(),
99            ordering: core::default::Default::default(),
100            shard_key_selector: core::default::Default::default(),
101            update_filter: core::default::Default::default(),
102            timeout: core::default::Default::default(),
103        }
104    }
105}
106
107impl From<UpdatePointVectorsBuilder> for UpdatePointVectors {
108    fn from(value: UpdatePointVectorsBuilder) -> Self {
109        value.build_inner().unwrap_or_else(|_| {
110            panic!(
111                "Failed to convert {0} to {1}",
112                "UpdatePointVectorsBuilder", "UpdatePointVectors"
113            )
114        })
115    }
116}
117
118impl UpdatePointVectorsBuilder {
119    /// Builds the desired type. Can often be omitted.
120    pub fn build(self) -> UpdatePointVectors {
121        self.build_inner().unwrap_or_else(|_| {
122            panic!(
123                "Failed to build {0} into {1}",
124                "UpdatePointVectorsBuilder", "UpdatePointVectors"
125            )
126        })
127    }
128}
129
130impl UpdatePointVectorsBuilder {
131    pub(crate) fn empty() -> Self {
132        Self::create_empty()
133    }
134}
135
136#[non_exhaustive]
137#[derive(Debug)]
138pub enum UpdatePointVectorsBuilderError {
139    /// Uninitialized field
140    UninitializedField(&'static str),
141    /// Custom validation error
142    ValidationError(String),
143}
144
145// Implementing the Display trait for better error messages
146impl std::fmt::Display for UpdatePointVectorsBuilderError {
147    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
148        match self {
149            Self::UninitializedField(field) => {
150                write!(f, "`{field}` must be initialized")
151            }
152            Self::ValidationError(error) => write!(f, "{error}"),
153        }
154    }
155}
156
157// Implementing the Error trait
158impl std::error::Error for UpdatePointVectorsBuilderError {}
159
160// Implementing From trait for conversion from UninitializedFieldError
161impl From<derive_builder::UninitializedFieldError> for UpdatePointVectorsBuilderError {
162    fn from(error: derive_builder::UninitializedFieldError) -> Self {
163        Self::UninitializedField(error.field_name())
164    }
165}
166
167// Implementing From trait for conversion from String
168impl From<String> for UpdatePointVectorsBuilderError {
169    fn from(error: String) -> Self {
170        Self::ValidationError(error)
171    }
172}