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
use std::sync::OnceLock;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// Global feature flags, normally initialized when starting Qdrant.
static FEATURE_FLAGS: OnceLock<FeatureFlags> = OnceLock::new();
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Eq, PartialEq, JsonSchema)]
#[serde(default)]
pub struct FeatureFlags {
/// Magic feature flag that enables all features.
///
/// Note that this will only be applied to all flags when passed into [`init_feature_flags`].
all: bool,
/// Use incremental HNSW building.
///
/// Enabled by default in Qdrant 1.14.1.
pub incremental_hnsw_building: bool,
/// Use appendable quantization in appendable plain segments.
///
/// Enabled by default in Qdrant 1.16.0.
pub appendable_quantization: bool,
/// Use single-file mmap in-ram vector storage (InRamMmap)
///
/// Enabled by default in Qdrant 1.17.1+
pub single_file_mmap_vector_storage: bool,
}
impl Default for FeatureFlags {
fn default() -> FeatureFlags {
FeatureFlags {
all: false,
incremental_hnsw_building: true,
appendable_quantization: true,
single_file_mmap_vector_storage: false,
}
}
}
impl FeatureFlags {
/// Check if the feature flags are set to default values.
pub fn is_default(self) -> bool {
self == FeatureFlags::default()
}
}
/// Initializes the global feature flags with `flags`. Must only be called once at
/// startup or otherwise throws a warning and discards the values.
pub fn init_feature_flags(mut flags: FeatureFlags) {
let FeatureFlags {
all,
incremental_hnsw_building,
appendable_quantization,
single_file_mmap_vector_storage,
} = &mut flags;
// If all is set, explicitly set all feature flags
if *all {
*incremental_hnsw_building = true;
*appendable_quantization = true;
*single_file_mmap_vector_storage = true;
}
let res = FEATURE_FLAGS.set(flags);
if res.is_err() {
log::warn!("Feature flags already initialized!");
}
}
/// Returns the configured global feature flags.
pub fn feature_flags() -> FeatureFlags {
if let Some(flags) = FEATURE_FLAGS.get() {
return *flags;
}
// They should always be initialized.
log::warn!("Feature flags not initialized!");
FeatureFlags::default()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_defaults() {
// Ensure we properly deserialize and don't crash on empty state
let empty: FeatureFlags = serde_json::from_str("{}").unwrap();
assert!(empty.is_default());
assert!(feature_flags().is_default());
assert!(FeatureFlags::default().is_default());
}
}