qdrant_client/builders/
search_params_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct SearchParamsBuilder {
5    ///
6    /// Params relevant to HNSW index. Size of the beam in a beam-search.
7    /// Larger the value - more accurate the result, more time required for search.
8    pub(crate) hnsw_ef: Option<Option<u64>>,
9    ///
10    /// Search without approximation. If set to true, search may run long but with exact results.
11    pub(crate) exact: Option<Option<bool>>,
12    ///
13    /// If set to true, search will ignore quantized vector data
14    pub(crate) quantization: Option<Option<QuantizationSearchParams>>,
15    ///
16    /// If enabled, the engine will only perform search among indexed or small segments.
17    /// Using this option prevents slow searches in case of delayed index, but does not
18    /// guarantee that all uploaded vectors will be included in search results
19    pub(crate) indexed_only: Option<Option<bool>>,
20    ///
21    /// Params relevant to ACORN index
22    pub(crate) acorn: Option<Option<AcornSearchParams>>,
23}
24
25impl SearchParamsBuilder {
26    ///
27    /// Params relevant to HNSW index. Size of the beam in a beam-search.
28    /// Larger the value - more accurate the result, more time required for search.
29    pub fn hnsw_ef(self, value: u64) -> Self {
30        let mut new = self;
31        new.hnsw_ef = Option::Some(Option::Some(value));
32        new
33    }
34    ///
35    /// Search without approximation. If set to true, search may run long but with exact results.
36    pub fn exact(self, value: bool) -> Self {
37        let mut new = self;
38        new.exact = Option::Some(Option::Some(value));
39        new
40    }
41    ///
42    /// If set to true, search will ignore quantized vector data
43    pub fn quantization<VALUE: core::convert::Into<QuantizationSearchParams>>(
44        self,
45        value: VALUE,
46    ) -> Self {
47        let mut new = self;
48        new.quantization = Option::Some(Option::Some(value.into()));
49        new
50    }
51    ///
52    /// If enabled, the engine will only perform search among indexed or small segments.
53    /// Using this option prevents slow searches in case of delayed index, but does not
54    /// guarantee that all uploaded vectors will be included in search results
55    pub fn indexed_only(self, value: bool) -> Self {
56        let mut new = self;
57        new.indexed_only = Option::Some(Option::Some(value));
58        new
59    }
60    ///
61    /// Params relevant to ACORN index
62    pub fn acorn<VALUE: core::convert::Into<AcornSearchParams>>(self, value: VALUE) -> Self {
63        let mut new = self;
64        new.acorn = Option::Some(Option::Some(value.into()));
65        new
66    }
67
68    fn build_inner(self) -> Result<SearchParams, std::convert::Infallible> {
69        Ok(SearchParams {
70            hnsw_ef: self.hnsw_ef.unwrap_or_default(),
71            exact: self.exact.unwrap_or_default(),
72            quantization: self.quantization.unwrap_or_default(),
73            indexed_only: self.indexed_only.unwrap_or_default(),
74            acorn: self.acorn.unwrap_or_default(),
75        })
76    }
77    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
78    fn create_empty() -> Self {
79        Self {
80            hnsw_ef: core::default::Default::default(),
81            exact: core::default::Default::default(),
82            quantization: core::default::Default::default(),
83            indexed_only: core::default::Default::default(),
84            acorn: core::default::Default::default(),
85        }
86    }
87}
88
89impl From<SearchParamsBuilder> for SearchParams {
90    fn from(value: SearchParamsBuilder) -> Self {
91        value.build_inner().unwrap_or_else(|_| {
92            panic!(
93                "Failed to convert {0} to {1}",
94                "SearchParamsBuilder", "SearchParams"
95            )
96        })
97    }
98}
99
100impl SearchParamsBuilder {
101    /// Builds the desired type. Can often be omitted.
102    pub fn build(self) -> SearchParams {
103        self.build_inner().unwrap_or_else(|_| {
104            panic!(
105                "Failed to build {0} into {1}",
106                "SearchParamsBuilder", "SearchParams"
107            )
108        })
109    }
110}
111
112impl Default for SearchParamsBuilder {
113    fn default() -> Self {
114        Self::create_empty()
115    }
116}