Skip to main content

qdrant_client/builders/
search_matrix_points_builder.rs

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