qdrant_client/builders/
sparse_vector_params_builder.rs

1use crate::qdrant::*;
2
3pub struct SparseVectorParamsBuilder {
4    /// Configuration of sparse index
5    pub(crate) index: Option<Option<SparseIndexConfig>>,
6    /// If set - apply modifier to the vector values
7    pub(crate) modifier: Option<Option<i32>>,
8}
9
10impl SparseVectorParamsBuilder {
11    /// Configuration of sparse index
12    #[allow(unused_mut)]
13    pub fn index<VALUE: core::convert::Into<SparseIndexConfig>>(self, value: VALUE) -> Self {
14        let mut new = self;
15        new.index = Option::Some(Option::Some(value.into()));
16        new
17    }
18    /// If set - apply modifier to the vector values
19    #[allow(unused_mut)]
20    pub fn modifier<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
21        let mut new = self;
22        new.modifier = Option::Some(Option::Some(value.into()));
23        new
24    }
25
26    fn build_inner(self) -> Result<SparseVectorParams, std::convert::Infallible> {
27        Ok(SparseVectorParams {
28            index: self.index.unwrap_or_default(),
29            modifier: self.modifier.unwrap_or_default(),
30        })
31    }
32    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
33    fn create_empty() -> Self {
34        Self {
35            index: core::default::Default::default(),
36            modifier: core::default::Default::default(),
37        }
38    }
39}
40
41impl From<SparseVectorParamsBuilder> for SparseVectorParams {
42    fn from(value: SparseVectorParamsBuilder) -> Self {
43        value.build_inner().unwrap_or_else(|_| {
44            panic!(
45                "Failed to convert {0} to {1}",
46                "SparseVectorParamsBuilder", "SparseVectorParams"
47            )
48        })
49    }
50}
51
52impl SparseVectorParamsBuilder {
53    /// Builds the desired type. Can often be omitted.
54    pub fn build(self) -> SparseVectorParams {
55        self.build_inner().unwrap_or_else(|_| {
56            panic!(
57                "Failed to build {0} into {1}",
58                "SparseVectorParamsBuilder", "SparseVectorParams"
59            )
60        })
61    }
62}
63
64impl Default for SparseVectorParamsBuilder {
65    fn default() -> Self {
66        Self::create_empty()
67    }
68}