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