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    /// Index every object of this array as a separate entry.
15    pub(crate) nested: Option<Option<String>>,
16}
17
18impl Default for FloatIndexParamsBuilder {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl FloatIndexParamsBuilder {
25    pub fn new() -> Self {
26        Self::create_empty()
27    }
28
29    /// If true - store index on disk.
30    ///
31    /// Deprecated since 1.19.0, use [`memory`](Self::memory) instead.
32    pub fn on_disk(self, value: bool) -> Self {
33        let mut new = self;
34        new.on_disk = Option::Some(Option::Some(value));
35        new
36    }
37    /// 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.
38    pub fn is_principal(self, value: bool) -> Self {
39        let mut new = self;
40        new.is_principal = Option::Some(Option::Some(value));
41        new
42    }
43    /// If true - enable HNSW index for this field.
44    pub fn enable_hnsw(self, value: bool) -> Self {
45        let mut new = self;
46        new.enable_hnsw = Option::Some(Option::Some(value));
47        new
48    }
49    /// Memory placement of the index.
50    /// Overrides the deprecated `on_disk` flag if both are set.
51    pub fn memory<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
52        let mut new = self;
53        new.memory = Option::Some(Option::Some(value.into()));
54        new
55    }
56    /// Index every object of this array as a separate entry, e.g. `offers` for the field `offers[].price`.
57    /// The field must be inside the array's elements.
58    pub fn nested(self, value: impl Into<String>) -> Self {
59        let mut new = self;
60        new.nested = Option::Some(Option::Some(value.into()));
61        new
62    }
63
64    #[allow(deprecated)]
65    fn build_inner(self) -> Result<FloatIndexParams, std::convert::Infallible> {
66        Ok(FloatIndexParams {
67            on_disk: self.on_disk.unwrap_or_default(),
68            is_principal: self.is_principal.unwrap_or_default(),
69            enable_hnsw: self.enable_hnsw.unwrap_or_default(),
70            memory: self.memory.unwrap_or_default(),
71            nested: self.nested.unwrap_or_default(),
72        })
73    }
74    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
75    fn create_empty() -> Self {
76        Self {
77            on_disk: core::default::Default::default(),
78            is_principal: core::default::Default::default(),
79            enable_hnsw: core::default::Default::default(),
80            memory: core::default::Default::default(),
81            nested: core::default::Default::default(),
82        }
83    }
84}
85
86impl From<FloatIndexParamsBuilder> for FloatIndexParams {
87    fn from(value: FloatIndexParamsBuilder) -> Self {
88        value.build_inner().unwrap_or_else(|_| {
89            panic!(
90                "Failed to convert {0} to {1}",
91                "FloatIndexParamsBuilder", "FloatIndexParams"
92            )
93        })
94    }
95}
96
97impl FloatIndexParamsBuilder {
98    /// Builds the desired type. Can often be omitted.
99    pub fn build(self) -> FloatIndexParams {
100        self.build_inner().unwrap_or_else(|_| {
101            panic!(
102                "Failed to build {0} into {1}",
103                "FloatIndexParamsBuilder", "FloatIndexParams"
104            )
105        })
106    }
107}