qdrant_client/builders/
max_optimization_threads_builder.rs

1use crate::qdrant::*;
2
3/// Max number of threads (jobs) for running optimizations per shard.
4/// Each optimization job will also use `max_indexing_threads` threads by itself for index building.
5///
6/// - If `auto` - have no limit and choose dynamically to saturate CPU.
7/// - If `disabled` or `0` - no optimization threads, optimizations will be disabled.
8#[derive(Clone)]
9pub struct MaxOptimizationThreadsBuilder {
10    pub(crate) inner: MaxOptimizationThreads,
11}
12
13impl MaxOptimizationThreadsBuilder {
14    /// Use specific number of optimization threads.
15    ///
16    /// - If `0` - no optimization threads, optimizations will be disabled.
17    #[allow(unused_mut)]
18    #[inline]
19    pub fn threads(threads: u64) -> Self {
20        Self {
21            inner: MaxOptimizationThreads::from(threads),
22        }
23    }
24
25    /// No optimization threads, optimizations will be disabled.
26    #[allow(unused_mut)]
27    #[inline]
28    pub fn disabled() -> Self {
29        Self::threads(0)
30    }
31
32    /// Have no limit and choose dynamically to saturate CPU.
33    #[allow(unused_mut)]
34    #[inline]
35    pub fn auto() -> Self {
36        Self {
37            inner: MaxOptimizationThreads::from(max_optimization_threads::Variant::Setting(
38                max_optimization_threads::Setting::Auto as i32,
39            )),
40        }
41    }
42}
43
44impl From<MaxOptimizationThreadsBuilder> for MaxOptimizationThreads {
45    fn from(value: MaxOptimizationThreadsBuilder) -> Self {
46        value.build()
47    }
48}
49
50impl MaxOptimizationThreadsBuilder {
51    pub fn build(self) -> MaxOptimizationThreads {
52        self.inner
53    }
54}
55
56impl Default for MaxOptimizationThreadsBuilder {
57    fn default() -> Self {
58        Self::auto()
59    }
60}
61
62impl From<u64> for MaxOptimizationThreads {
63    fn from(threads: u64) -> Self {
64        MaxOptimizationThreads {
65            variant: Some(max_optimization_threads::Variant::from(threads)),
66        }
67    }
68}
69
70impl From<max_optimization_threads::Variant> for MaxOptimizationThreads {
71    fn from(setting: max_optimization_threads::Variant) -> Self {
72        MaxOptimizationThreads {
73            variant: Some(setting),
74        }
75    }
76}
77
78impl From<u64> for max_optimization_threads::Variant {
79    fn from(threads: u64) -> Self {
80        Self::Value(threads)
81    }
82}
83
84impl From<max_optimization_threads::Setting> for max_optimization_threads::Variant {
85    fn from(setting: max_optimization_threads::Setting) -> Self {
86        Self::Setting(setting as i32)
87    }
88}