qdrant_client/builders/
sparse_index_config_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct SparseIndexConfigBuilder {
5    ///
6    /// Prefer a full scan search upto (excluding) this number of vectors.
7    /// Note: this is number of vectors, not KiloBytes.
8    pub(crate) full_scan_threshold: Option<Option<u64>>,
9    ///
10    /// Store inverted index on disk. If set to false, the index will be stored in RAM.
11    pub(crate) on_disk: Option<Option<bool>>,
12    ///
13    /// Datatype used to store weights in the index.
14    pub(crate) datatype: Option<Option<i32>>,
15}
16
17impl SparseIndexConfigBuilder {
18    ///
19    /// Prefer a full scan search upto (excluding) this number of vectors.
20    /// Note: this is number of vectors, not KiloBytes.
21    pub fn full_scan_threshold<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
22        let mut new = self;
23        new.full_scan_threshold = Option::Some(Option::Some(value.into()));
24        new
25    }
26    ///
27    /// Store inverted index on disk. If set to false, the index will be stored in RAM.
28    pub fn on_disk(self, value: bool) -> Self {
29        let mut new = self;
30        new.on_disk = Option::Some(Option::Some(value));
31        new
32    }
33    ///
34    /// Datatype used to store weights in the index.
35    pub fn datatype<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
36        let mut new = self;
37        new.datatype = Option::Some(Option::Some(value.into()));
38        new
39    }
40
41    fn build_inner(self) -> Result<SparseIndexConfig, std::convert::Infallible> {
42        Ok(SparseIndexConfig {
43            full_scan_threshold: self.full_scan_threshold.unwrap_or_default(),
44            on_disk: self.on_disk.unwrap_or_default(),
45            datatype: self.datatype.unwrap_or_default(),
46        })
47    }
48    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
49    fn create_empty() -> Self {
50        Self {
51            full_scan_threshold: core::default::Default::default(),
52            on_disk: core::default::Default::default(),
53            datatype: core::default::Default::default(),
54        }
55    }
56}
57
58impl From<SparseIndexConfigBuilder> for SparseIndexConfig {
59    fn from(value: SparseIndexConfigBuilder) -> Self {
60        value.build_inner().unwrap_or_else(|_| {
61            panic!(
62                "Failed to convert {0} to {1}",
63                "SparseIndexConfigBuilder", "SparseIndexConfig"
64            )
65        })
66    }
67}
68
69impl SparseIndexConfigBuilder {
70    /// Builds the desired type. Can often be omitted.
71    pub fn build(self) -> SparseIndexConfig {
72        self.build_inner().unwrap_or_else(|_| {
73            panic!(
74                "Failed to build {0} into {1}",
75                "SparseIndexConfigBuilder", "SparseIndexConfig"
76            )
77        })
78    }
79}
80
81impl Default for SparseIndexConfigBuilder {
82    fn default() -> Self {
83        Self::create_empty()
84    }
85}