Skip to main content

qdrant_client/builders/
float_index_params_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct FloatIndexParamsBuilder {
5    /// If true - store index on disk.
6    pub(crate) on_disk: Option<Option<bool>>,
7    /// 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.
8    pub(crate) is_principal: Option<Option<bool>>,
9    /// If true - enable HNSW index for this field.
10    pub(crate) enable_hnsw: Option<Option<bool>>,
11}
12
13impl Default for FloatIndexParamsBuilder {
14    fn default() -> Self {
15        Self::new()
16    }
17}
18
19impl FloatIndexParamsBuilder {
20    pub fn new() -> Self {
21        Self::create_empty()
22    }
23
24    /// If true - store index on disk.
25    pub fn on_disk(self, value: bool) -> Self {
26        let mut new = self;
27        new.on_disk = Option::Some(Option::Some(value));
28        new
29    }
30    /// 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.
31    pub fn is_principal(self, value: bool) -> Self {
32        let mut new = self;
33        new.is_principal = Option::Some(Option::Some(value));
34        new
35    }
36    /// If true - enable HNSW index for this field.
37    pub fn enable_hnsw(self, value: bool) -> Self {
38        let mut new = self;
39        new.enable_hnsw = Option::Some(Option::Some(value));
40        new
41    }
42
43    fn build_inner(self) -> Result<FloatIndexParams, std::convert::Infallible> {
44        Ok(FloatIndexParams {
45            on_disk: self.on_disk.unwrap_or_default(),
46            is_principal: self.is_principal.unwrap_or_default(),
47            enable_hnsw: self.enable_hnsw.unwrap_or_default(),
48        })
49    }
50    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
51    fn create_empty() -> Self {
52        Self {
53            on_disk: core::default::Default::default(),
54            is_principal: core::default::Default::default(),
55            enable_hnsw: core::default::Default::default(),
56        }
57    }
58}
59
60impl From<FloatIndexParamsBuilder> for FloatIndexParams {
61    fn from(value: FloatIndexParamsBuilder) -> Self {
62        value.build_inner().unwrap_or_else(|_| {
63            panic!(
64                "Failed to convert {0} to {1}",
65                "FloatIndexParamsBuilder", "FloatIndexParams"
66            )
67        })
68    }
69}
70
71impl FloatIndexParamsBuilder {
72    /// Builds the desired type. Can often be omitted.
73    pub fn build(self) -> FloatIndexParams {
74        self.build_inner().unwrap_or_else(|_| {
75            panic!(
76                "Failed to build {0} into {1}",
77                "FloatIndexParamsBuilder", "FloatIndexParams"
78            )
79        })
80    }
81}