Skip to main content

qdrant_client/builders/
update_point_vectors_builder.rs

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