Skip to main content

qdrant_client/builders/
sparse_index_config_builder.rs

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