Skip to main content

qdrant_client/builders/
query_batch_points_builder.rs

1use crate::grpc_macros::convert_option;
2use crate::qdrant::*;
3
4#[must_use]
5#[derive(Clone)]
6pub struct QueryBatchPointsBuilder {
7    pub(crate) collection_name: Option<String>,
8    pub(crate) query_points: Option<Vec<QueryPoints>>,
9    /// Options for specifying read consistency guarantees
10    read_consistency: Option<read_consistency::Value>,
11    /// If set, overrides global timeout setting for this request. Unit is seconds.
12    pub(crate) timeout: Option<Option<u64>>,
13}
14
15impl QueryBatchPointsBuilder {
16    pub fn collection_name(self, value: String) -> Self {
17        let mut new = self;
18        new.collection_name = Option::Some(value);
19        new
20    }
21    pub fn query_points(self, value: Vec<QueryPoints>) -> Self {
22        let mut new = self;
23        new.query_points = Option::Some(value);
24        new
25    }
26    /// Options for specifying read consistency guarantees
27    pub fn read_consistency<VALUE: core::convert::Into<read_consistency::Value>>(
28        self,
29        value: VALUE,
30    ) -> Self {
31        let mut new = self;
32        new.read_consistency = Option::Some(value.into());
33        new
34    }
35    /// If set, overrides global timeout setting for this request. Unit is seconds.
36    pub fn timeout(self, value: u64) -> Self {
37        let mut new = self;
38        new.timeout = Option::Some(Option::Some(value));
39        new
40    }
41
42    fn build_inner(self) -> Result<QueryBatchPoints, QueryBatchPointsBuilderError> {
43        Ok(QueryBatchPoints {
44            collection_name: match self.collection_name {
45                Some(value) => value,
46                None => {
47                    return Result::Err(core::convert::Into::into(
48                        ::derive_builder::UninitializedFieldError::from("collection_name"),
49                    ));
50                }
51            },
52            query_points: match self.query_points {
53                Some(value) => value,
54                None => {
55                    return Result::Err(core::convert::Into::into(
56                        ::derive_builder::UninitializedFieldError::from("query_points"),
57                    ));
58                }
59            },
60            read_consistency: { convert_option(&self.read_consistency) },
61            timeout: self.timeout.unwrap_or_default(),
62        })
63    }
64    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
65    fn create_empty() -> Self {
66        Self {
67            collection_name: core::default::Default::default(),
68            query_points: core::default::Default::default(),
69            read_consistency: core::default::Default::default(),
70            timeout: core::default::Default::default(),
71        }
72    }
73}
74
75impl From<QueryBatchPointsBuilder> for QueryBatchPoints {
76    fn from(value: QueryBatchPointsBuilder) -> Self {
77        value.build_inner().unwrap_or_else(|_| {
78            panic!(
79                "Failed to convert {0} to {1}",
80                "QueryBatchPointsBuilder", "QueryBatchPoints"
81            )
82        })
83    }
84}
85
86impl QueryBatchPointsBuilder {
87    /// Builds the desired type. Can often be omitted.
88    pub fn build(self) -> QueryBatchPoints {
89        self.build_inner().unwrap_or_else(|_| {
90            panic!(
91                "Failed to build {0} into {1}",
92                "QueryBatchPointsBuilder", "QueryBatchPoints"
93            )
94        })
95    }
96}
97
98impl QueryBatchPointsBuilder {
99    pub(crate) fn empty() -> Self {
100        Self::create_empty()
101    }
102}
103
104/// Error type for QueryBatchPointsBuilder
105#[non_exhaustive]
106#[derive(Debug)]
107pub enum QueryBatchPointsBuilderError {
108    /// Uninitialized field
109    UninitializedField(&'static str),
110    /// Custom validation error
111    ValidationError(String),
112}
113
114// Implementing the Display trait for better error messages
115impl std::fmt::Display for QueryBatchPointsBuilderError {
116    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
117        match self {
118            Self::UninitializedField(field) => {
119                write!(f, "`{field}` must be initialized")
120            }
121            Self::ValidationError(error) => write!(f, "{error}"),
122        }
123    }
124}
125
126// Implementing the Error trait
127impl std::error::Error for QueryBatchPointsBuilderError {}
128
129// Implementing From trait for conversion from UninitializedFieldError
130impl From<derive_builder::UninitializedFieldError> for QueryBatchPointsBuilderError {
131    fn from(error: derive_builder::UninitializedFieldError) -> Self {
132        Self::UninitializedField(error.field_name())
133    }
134}
135
136// Implementing From trait for conversion from String
137impl From<String> for QueryBatchPointsBuilderError {
138    fn from(error: String) -> Self {
139        Self::ValidationError(error)
140    }
141}