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 /// Store copies of original and quantized vectors within the HNSW index file. Default: false.
31 /// Enabling this option will trade the search speed for disk usage by reducing amount of
32 /// random seeks during the search.
33 /// Requires quantized vectors to be enabled. Multi-vectors are not supported.
34 pub(crate) inline_storage: Option<Option<bool>>,
35}
36#[allow(clippy::all)]
37#[allow(clippy::derive_partial_eq_without_eq)]
38impl HnswConfigDiffBuilder {
39 ///
40 /// Number of edges per node in the index graph. Larger the value - more accurate the search, more space required.
41 pub fn m(self, value: u64) -> Self {
42 let mut new = self;
43 new.m = Option::Some(Option::Some(value));
44 new
45 }
46 ///
47 /// Number of neighbours to consider during the index building. Larger the value - more accurate the search, more time required to build the index.
48 pub fn ef_construct(self, value: u64) -> Self {
49 let mut new = self;
50 new.ef_construct = Option::Some(Option::Some(value));
51 new
52 }
53 ///
54 /// Minimal size (in KiloBytes) of vectors for additional payload-based indexing.
55 /// If the payload chunk is smaller than `full_scan_threshold` additional indexing won't be used -
56 /// in this case full-scan search should be preferred by query planner and additional indexing is not required.
57 /// Note: 1 Kb = 1 vector of size 256
58 pub fn full_scan_threshold(self, value: u64) -> Self {
59 let mut new = self;
60 new.full_scan_threshold = Option::Some(Option::Some(value));
61 new
62 }
63 ///
64 /// Number of parallel threads used for background index building.
65 /// If 0 - automatically select from 8 to 16.
66 /// Best to keep between 8 and 16 to prevent likelihood of building broken/inefficient HNSW graphs.
67 /// On small CPUs, less threads are used.
68 pub fn max_indexing_threads(self, value: u64) -> Self {
69 let mut new = self;
70 new.max_indexing_threads = Option::Some(Option::Some(value));
71 new
72 }
73 ///
74 /// Store HNSW index on disk. If set to false, the index will be stored in RAM.
75 pub fn on_disk(self, value: bool) -> Self {
76 let mut new = self;
77 new.on_disk = Option::Some(Option::Some(value));
78 new
79 }
80 ///
81 /// Number of additional payload-aware links per node in the index graph. If not set - regular M parameter will be used.
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 /// Store copies of original and quantized vectors within the HNSW index file. Default: false.
89 /// Enabling this option will trade the search speed for disk usage by reducing amount of
90 /// random seeks during the search.
91 /// Requires quantized vectors to be enabled. Multi-vectors are not supported.
92 pub fn inline_storage(self, value: bool) -> Self {
93 let mut new = self;
94 new.inline_storage = Option::Some(Option::Some(value));
95 new
96 }
97
98 fn build_inner(self) -> Result<HnswConfigDiff, std::convert::Infallible> {
99 Ok(HnswConfigDiff {
100 m: match self.m {
101 Some(value) => value,
102 None => core::default::Default::default(),
103 },
104 ef_construct: match self.ef_construct {
105 Some(value) => value,
106 None => core::default::Default::default(),
107 },
108 full_scan_threshold: match self.full_scan_threshold {
109 Some(value) => value,
110 None => core::default::Default::default(),
111 },
112 max_indexing_threads: match self.max_indexing_threads {
113 Some(value) => value,
114 None => core::default::Default::default(),
115 },
116 on_disk: match self.on_disk {
117 Some(value) => value,
118 None => core::default::Default::default(),
119 },
120 payload_m: match self.payload_m {
121 Some(value) => value,
122 None => core::default::Default::default(),
123 },
124 inline_storage: match self.inline_storage {
125 Some(value) => value,
126 None => core::default::Default::default(),
127 },
128 })
129 }
130 /// Create an empty builder, with all fields set to `None` or `PhantomData`.
131 fn create_empty() -> Self {
132 Self {
133 m: core::default::Default::default(),
134 ef_construct: core::default::Default::default(),
135 full_scan_threshold: core::default::Default::default(),
136 max_indexing_threads: core::default::Default::default(),
137 on_disk: core::default::Default::default(),
138 payload_m: core::default::Default::default(),
139 inline_storage: core::default::Default::default(),
140 }
141 }
142}
143
144impl From<HnswConfigDiffBuilder> for HnswConfigDiff {
145 fn from(value: HnswConfigDiffBuilder) -> Self {
146 value.build_inner().unwrap_or_else(|_| {
147 panic!(
148 "Failed to convert {0} to {1}",
149 "HnswConfigDiffBuilder", "HnswConfigDiff"
150 )
151 })
152 }
153}
154
155impl HnswConfigDiffBuilder {
156 /// Builds the desired type. Can often be omitted.
157 pub fn build(self) -> HnswConfigDiff {
158 self.build_inner().unwrap_or_else(|_| {
159 panic!(
160 "Failed to build {0} into {1}",
161 "HnswConfigDiffBuilder", "HnswConfigDiff"
162 )
163 })
164 }
165}
166
167impl Default for HnswConfigDiffBuilder {
168 fn default() -> Self {
169 Self::create_empty()
170 }
171}