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