Skip to main content

qdrant_client/builders/
keyword_index_params_builder.rs

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