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    /// Memory placement of the index.
18    pub(crate) memory: Option<Option<i32>>,
19}
20
21impl SparseIndexConfigBuilder {
22    ///
23    /// Prefer a full scan search upto (excluding) this number of vectors.
24    /// Note: this is number of vectors, not KiloBytes.
25    pub fn full_scan_threshold<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
26        let mut new = self;
27        new.full_scan_threshold = Option::Some(Option::Some(value.into()));
28        new
29    }
30    ///
31    /// Store inverted index on disk. If set to false, the index will be stored in RAM.
32    ///
33    /// Deprecated since 1.19.0, use [`memory`](Self::memory) instead.
34    pub fn on_disk(self, value: bool) -> Self {
35        let mut new = self;
36        new.on_disk = Option::Some(Option::Some(value));
37        new
38    }
39    ///
40    /// Datatype used to store weights in the index.
41    pub fn datatype<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
42        let mut new = self;
43        new.datatype = Option::Some(Option::Some(value.into()));
44        new
45    }
46    ///
47    /// Memory placement of the index.
48    /// Overrides the deprecated `on_disk` flag if both are set.
49    pub fn memory<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
50        let mut new = self;
51        new.memory = Option::Some(Option::Some(value.into()));
52        new
53    }
54
55    #[allow(deprecated)]
56    fn build_inner(self) -> Result<SparseIndexConfig, std::convert::Infallible> {
57        Ok(SparseIndexConfig {
58            full_scan_threshold: self.full_scan_threshold.unwrap_or_default(),
59            on_disk: self.on_disk.unwrap_or_default(),
60            datatype: self.datatype.unwrap_or_default(),
61            memory: self.memory.unwrap_or_default(),
62        })
63    }
64    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
65    fn create_empty() -> Self {
66        Self {
67            full_scan_threshold: core::default::Default::default(),
68            on_disk: core::default::Default::default(),
69            datatype: core::default::Default::default(),
70            memory: core::default::Default::default(),
71        }
72    }
73}
74
75impl From<SparseIndexConfigBuilder> for SparseIndexConfig {
76    fn from(value: SparseIndexConfigBuilder) -> Self {
77        value.build_inner().unwrap_or_else(|_| {
78            panic!(
79                "Failed to convert {0} to {1}",
80                "SparseIndexConfigBuilder", "SparseIndexConfig"
81            )
82        })
83    }
84}
85
86impl SparseIndexConfigBuilder {
87    /// Builds the desired type. Can often be omitted.
88    pub fn build(self) -> SparseIndexConfig {
89        self.build_inner().unwrap_or_else(|_| {
90            panic!(
91                "Failed to build {0} into {1}",
92                "SparseIndexConfigBuilder", "SparseIndexConfig"
93            )
94        })
95    }
96}
97
98impl Default for SparseIndexConfigBuilder {
99    fn default() -> Self {
100        Self::create_empty()
101    }
102}