Skip to main content

qdrant_client/builders/
float_index_params_builder.rs

1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct FloatIndexParamsBuilder {
6    /// If true - store index on disk.
7    pub(crate) on_disk: Option<Option<bool>>,
8    /// If true - use this key to organize storage of the collection data. This option assumes that this key will be used in majority of filtered requests.
9    pub(crate) is_principal: Option<Option<bool>>,
10    /// If true - enable HNSW index for this field.
11    pub(crate) enable_hnsw: Option<Option<bool>>,
12    /// Memory placement of the index.
13    pub(crate) memory: Option<Option<i32>>,
14}
15
16impl Default for FloatIndexParamsBuilder {
17    fn default() -> Self {
18        Self::new()
19    }
20}
21
22impl FloatIndexParamsBuilder {
23    pub fn new() -> Self {
24        Self::create_empty()
25    }
26
27    /// If true - store index on disk.
28    ///
29    /// Deprecated since 1.19.0, use [`memory`](Self::memory) instead.
30    pub fn on_disk(self, value: bool) -> Self {
31        let mut new = self;
32        new.on_disk = Option::Some(Option::Some(value));
33        new
34    }
35    /// If true - use this key to organize storage of the collection data. This option assumes that this key will be used in majority of filtered requests.
36    pub fn is_principal(self, value: bool) -> Self {
37        let mut new = self;
38        new.is_principal = Option::Some(Option::Some(value));
39        new
40    }
41    /// If true - enable HNSW index for this field.
42    pub fn enable_hnsw(self, value: bool) -> Self {
43        let mut new = self;
44        new.enable_hnsw = Option::Some(Option::Some(value));
45        new
46    }
47    /// Memory placement of the index.
48    /// Overrides the deprecated `on_disk` flag if both are set.
49    pub fn memory<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
50        let mut new = self;
51        new.memory = Option::Some(Option::Some(value.into()));
52        new
53    }
54
55    #[allow(deprecated)]
56    fn build_inner(self) -> Result<FloatIndexParams, std::convert::Infallible> {
57        Ok(FloatIndexParams {
58            on_disk: self.on_disk.unwrap_or_default(),
59            is_principal: self.is_principal.unwrap_or_default(),
60            enable_hnsw: self.enable_hnsw.unwrap_or_default(),
61            memory: self.memory.unwrap_or_default(),
62        })
63    }
64    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
65    fn create_empty() -> Self {
66        Self {
67            on_disk: core::default::Default::default(),
68            is_principal: core::default::Default::default(),
69            enable_hnsw: core::default::Default::default(),
70            memory: core::default::Default::default(),
71        }
72    }
73}
74
75impl From<FloatIndexParamsBuilder> for FloatIndexParams {
76    fn from(value: FloatIndexParamsBuilder) -> Self {
77        value.build_inner().unwrap_or_else(|_| {
78            panic!(
79                "Failed to convert {0} to {1}",
80                "FloatIndexParamsBuilder", "FloatIndexParams"
81            )
82        })
83    }
84}
85
86impl FloatIndexParamsBuilder {
87    /// Builds the desired type. Can often be omitted.
88    pub fn build(self) -> FloatIndexParams {
89        self.build_inner().unwrap_or_else(|_| {
90            panic!(
91                "Failed to build {0} into {1}",
92                "FloatIndexParamsBuilder", "FloatIndexParams"
93            )
94        })
95    }
96}