Skip to main content

qdrant_client/builders/
search_params_builder.rs

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