Skip to main content

qdrant_client/builders/
sparse_vector_creation_config_builder.rs

1use crate::qdrant::*;
2
3/// Sparse vector creation parameters.
4/// Only includes immutable properties that define the vector space.
5#[must_use]
6#[derive(Clone)]
7pub struct SparseVectorCreationConfigBuilder {
8    /// If set - apply modifier to the vector values (e.g., IDF)
9    pub(crate) modifier: Option<Option<i32>>,
10    /// Data type used to store weights in the index
11    pub(crate) datatype: Option<Option<i32>>,
12}
13
14impl SparseVectorCreationConfigBuilder {
15    /// If set - apply modifier to the vector values (e.g., IDF)
16    pub fn modifier<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
17        let mut new = self;
18        new.modifier = Option::Some(Option::Some(value.into()));
19        new
20    }
21
22    /// Data type used to store weights in the index
23    pub fn datatype<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
24        let mut new = self;
25        new.datatype = Option::Some(Option::Some(value.into()));
26        new
27    }
28
29    fn build_inner(self) -> Result<SparseVectorCreationConfig, std::convert::Infallible> {
30        Ok(SparseVectorCreationConfig {
31            modifier: self.modifier.unwrap_or_default(),
32            datatype: self.datatype.unwrap_or_default(),
33        })
34    }
35
36    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
37    fn create_empty() -> Self {
38        Self {
39            modifier: core::default::Default::default(),
40            datatype: core::default::Default::default(),
41        }
42    }
43}
44
45impl From<SparseVectorCreationConfigBuilder> for SparseVectorCreationConfig {
46    fn from(value: SparseVectorCreationConfigBuilder) -> Self {
47        value.build_inner().unwrap_or_else(|_| {
48            panic!(
49                "Failed to convert {0} to {1}",
50                "SparseVectorCreationConfigBuilder", "SparseVectorCreationConfig"
51            )
52        })
53    }
54}
55
56impl SparseVectorCreationConfigBuilder {
57    /// Builds the desired type. Can often be omitted.
58    pub fn build(self) -> SparseVectorCreationConfig {
59        self.build_inner().unwrap_or_else(|_| {
60            panic!(
61                "Failed to build {0} into {1}",
62                "SparseVectorCreationConfigBuilder", "SparseVectorCreationConfig"
63            )
64        })
65    }
66}
67
68impl SparseVectorCreationConfigBuilder {
69    pub(crate) fn empty() -> Self {
70        Self::create_empty()
71    }
72}
73
74impl Default for SparseVectorCreationConfigBuilder {
75    fn default() -> Self {
76        Self::create_empty()
77    }
78}