qdrant_client/builders/
search_matrix_points_builder.rs

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