qdrant_client/builders/
hnsw_config_diff_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct HnswConfigDiffBuilder {
5    ///
6    /// Number of edges per node in the index graph. Larger the value - more accurate the search, more space required.
7    pub(crate) m: Option<Option<u64>>,
8    ///
9    /// Number of neighbours to consider during the index building. Larger the value - more accurate the search, more time required to build the index.
10    pub(crate) ef_construct: Option<Option<u64>>,
11    ///
12    /// Minimal size (in KiloBytes) of vectors for additional payload-based indexing.
13    /// If the payload chunk is smaller than `full_scan_threshold` additional indexing won't be used -
14    /// in this case full-scan search should be preferred by query planner and additional indexing is not required.
15    /// Note: 1 Kb = 1 vector of size 256
16    pub(crate) full_scan_threshold: Option<Option<u64>>,
17    ///
18    /// Number of parallel threads used for background index building.
19    /// If 0 - automatically select from 8 to 16.
20    /// Best to keep between 8 and 16 to prevent likelihood of building broken/inefficient HNSW graphs.
21    /// On small CPUs, less threads are used.
22    pub(crate) max_indexing_threads: Option<Option<u64>>,
23    ///
24    /// Store HNSW index on disk. If set to false, the index will be stored in RAM.
25    pub(crate) on_disk: Option<Option<bool>>,
26    ///
27    /// Number of additional payload-aware links per node in the index graph. If not set - regular M parameter will be used.
28    pub(crate) payload_m: Option<Option<u64>>,
29}
30#[allow(clippy::all)]
31#[allow(clippy::derive_partial_eq_without_eq)]
32impl HnswConfigDiffBuilder {
33    ///
34    /// Number of edges per node in the index graph. Larger the value - more accurate the search, more space required.
35    #[allow(unused_mut)]
36    pub fn m(self, value: u64) -> Self {
37        let mut new = self;
38        new.m = Option::Some(Option::Some(value));
39        new
40    }
41    ///
42    /// Number of neighbours to consider during the index building. Larger the value - more accurate the search, more time required to build the index.
43    #[allow(unused_mut)]
44    pub fn ef_construct(self, value: u64) -> Self {
45        let mut new = self;
46        new.ef_construct = Option::Some(Option::Some(value));
47        new
48    }
49    ///
50    /// Minimal size (in KiloBytes) of vectors for additional payload-based indexing.
51    /// If the payload chunk is smaller than `full_scan_threshold` additional indexing won't be used -
52    /// in this case full-scan search should be preferred by query planner and additional indexing is not required.
53    /// Note: 1 Kb = 1 vector of size 256
54    #[allow(unused_mut)]
55    pub fn full_scan_threshold(self, value: u64) -> Self {
56        let mut new = self;
57        new.full_scan_threshold = Option::Some(Option::Some(value));
58        new
59    }
60    ///
61    /// Number of parallel threads used for background index building.
62    /// If 0 - automatically select from 8 to 16.
63    /// Best to keep between 8 and 16 to prevent likelihood of building broken/inefficient HNSW graphs.
64    /// On small CPUs, less threads are used.
65    #[allow(unused_mut)]
66    pub fn max_indexing_threads(self, value: u64) -> Self {
67        let mut new = self;
68        new.max_indexing_threads = Option::Some(Option::Some(value));
69        new
70    }
71    ///
72    /// Store HNSW index on disk. If set to false, the index will be stored in RAM.
73    #[allow(unused_mut)]
74    pub fn on_disk(self, value: bool) -> Self {
75        let mut new = self;
76        new.on_disk = Option::Some(Option::Some(value));
77        new
78    }
79    ///
80    /// Number of additional payload-aware links per node in the index graph. If not set - regular M parameter will be used.
81    #[allow(unused_mut)]
82    pub fn payload_m(self, value: u64) -> Self {
83        let mut new = self;
84        new.payload_m = Option::Some(Option::Some(value));
85        new
86    }
87
88    fn build_inner(self) -> Result<HnswConfigDiff, std::convert::Infallible> {
89        Ok(HnswConfigDiff {
90            m: match self.m {
91                Some(value) => value,
92                None => core::default::Default::default(),
93            },
94            ef_construct: match self.ef_construct {
95                Some(value) => value,
96                None => core::default::Default::default(),
97            },
98            full_scan_threshold: match self.full_scan_threshold {
99                Some(value) => value,
100                None => core::default::Default::default(),
101            },
102            max_indexing_threads: match self.max_indexing_threads {
103                Some(value) => value,
104                None => core::default::Default::default(),
105            },
106            on_disk: match self.on_disk {
107                Some(value) => value,
108                None => core::default::Default::default(),
109            },
110            payload_m: match self.payload_m {
111                Some(value) => value,
112                None => core::default::Default::default(),
113            },
114        })
115    }
116    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
117    fn create_empty() -> Self {
118        Self {
119            m: core::default::Default::default(),
120            ef_construct: core::default::Default::default(),
121            full_scan_threshold: core::default::Default::default(),
122            max_indexing_threads: core::default::Default::default(),
123            on_disk: core::default::Default::default(),
124            payload_m: core::default::Default::default(),
125        }
126    }
127}
128
129impl From<HnswConfigDiffBuilder> for HnswConfigDiff {
130    fn from(value: HnswConfigDiffBuilder) -> Self {
131        value.build_inner().unwrap_or_else(|_| {
132            panic!(
133                "Failed to convert {0} to {1}",
134                "HnswConfigDiffBuilder", "HnswConfigDiff"
135            )
136        })
137    }
138}
139
140impl HnswConfigDiffBuilder {
141    /// Builds the desired type. Can often be omitted.
142    pub fn build(self) -> HnswConfigDiff {
143        self.build_inner().unwrap_or_else(|_| {
144            panic!(
145                "Failed to build {0} into {1}",
146                "HnswConfigDiffBuilder", "HnswConfigDiff"
147            )
148        })
149    }
150}
151
152impl Default for HnswConfigDiffBuilder {
153    fn default() -> Self {
154        Self::create_empty()
155    }
156}