qdrant_client/builders/
dense_vector_creation_config_builder.rs1use crate::qdrant::*;
2
3#[must_use]
7#[derive(Clone)]
8pub struct DenseVectorCreationConfigBuilder {
9 pub(crate) size: Option<u64>,
11 pub(crate) distance: Option<i32>,
13 pub(crate) multivector_config: Option<Option<MultiVectorConfig>>,
15 pub(crate) datatype: Option<Option<i32>>,
17}
18
19impl DenseVectorCreationConfigBuilder {
20 pub fn size(self, value: u64) -> Self {
22 let mut new = self;
23 new.size = Option::Some(value);
24 new
25 }
26
27 pub fn distance<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
29 let mut new = self;
30 new.distance = Option::Some(value.into());
31 new
32 }
33
34 pub fn multivector_config<VALUE: core::convert::Into<MultiVectorConfig>>(
36 self,
37 value: VALUE,
38 ) -> Self {
39 let mut new = self;
40 new.multivector_config = Option::Some(Option::Some(value.into()));
41 new
42 }
43
44 pub fn datatype<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
46 let mut new = self;
47 new.datatype = Option::Some(Option::Some(value.into()));
48 new
49 }
50
51 fn build_inner(
52 self,
53 ) -> Result<DenseVectorCreationConfig, DenseVectorCreationConfigBuilderError> {
54 Ok(DenseVectorCreationConfig {
55 size: match self.size {
56 Some(value) => value,
57 None => {
58 return Result::Err(core::convert::Into::into(
59 ::derive_builder::UninitializedFieldError::from("size"),
60 ));
61 }
62 },
63 distance: match self.distance {
64 Some(value) => value,
65 None => {
66 return Result::Err(core::convert::Into::into(
67 ::derive_builder::UninitializedFieldError::from("distance"),
68 ));
69 }
70 },
71 multivector_config: self.multivector_config.unwrap_or_default(),
72 datatype: self.datatype.unwrap_or_default(),
73 })
74 }
75 fn create_empty() -> Self {
77 Self {
78 size: core::default::Default::default(),
79 distance: core::default::Default::default(),
80 multivector_config: core::default::Default::default(),
81 datatype: core::default::Default::default(),
82 }
83 }
84}
85
86impl From<DenseVectorCreationConfigBuilder> for DenseVectorCreationConfig {
87 fn from(value: DenseVectorCreationConfigBuilder) -> Self {
88 value.build_inner().unwrap_or_else(|_| {
89 panic!(
90 "Failed to convert {0} to {1}",
91 "DenseVectorCreationConfigBuilder", "DenseVectorCreationConfig"
92 )
93 })
94 }
95}
96
97impl DenseVectorCreationConfigBuilder {
98 pub fn build(self) -> DenseVectorCreationConfig {
100 self.build_inner().unwrap_or_else(|_| {
101 panic!(
102 "Failed to build {0} into {1}",
103 "DenseVectorCreationConfigBuilder", "DenseVectorCreationConfig"
104 )
105 })
106 }
107}
108
109impl DenseVectorCreationConfigBuilder {
110 pub(crate) fn empty() -> Self {
111 Self::create_empty()
112 }
113}
114
115#[non_exhaustive]
117#[derive(Debug)]
118pub enum DenseVectorCreationConfigBuilderError {
119 UninitializedField(&'static str),
121 ValidationError(String),
123}
124
125impl std::fmt::Display for DenseVectorCreationConfigBuilderError {
127 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
128 match self {
129 Self::UninitializedField(field) => {
130 write!(f, "`{field}` must be initialized")
131 }
132 Self::ValidationError(error) => write!(f, "{error}"),
133 }
134 }
135}
136
137impl std::error::Error for DenseVectorCreationConfigBuilderError {}
139
140impl From<derive_builder::UninitializedFieldError> for DenseVectorCreationConfigBuilderError {
142 fn from(error: derive_builder::UninitializedFieldError) -> Self {
143 Self::UninitializedField(error.field_name())
144 }
145}
146
147impl From<String> for DenseVectorCreationConfigBuilderError {
149 fn from(error: String) -> Self {
150 Self::ValidationError(error)
151 }
152}