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