qdrant_client/builders/
hnsw_config_diff_builder.rs

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