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
22impl SearchParamsBuilder {
23    ///
24    /// Params relevant to HNSW index. Size of the beam in a beam-search.
25    /// Larger the value - more accurate the result, more time required for search.
26    #[allow(unused_mut)]
27    pub fn hnsw_ef(self, value: u64) -> Self {
28        let mut new = self;
29        new.hnsw_ef = Option::Some(Option::Some(value));
30        new
31    }
32    ///
33    /// Search without approximation. If set to true, search may run long but with exact results.
34    #[allow(unused_mut)]
35    pub fn exact(self, value: bool) -> Self {
36        let mut new = self;
37        new.exact = Option::Some(Option::Some(value));
38        new
39    }
40    ///
41    /// If set to true, search will ignore quantized vector data
42    #[allow(unused_mut)]
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    #[allow(unused_mut)]
56    pub fn indexed_only(self, value: bool) -> Self {
57        let mut new = self;
58        new.indexed_only = Option::Some(Option::Some(value));
59        new
60    }
61
62    fn build_inner(self) -> Result<SearchParams, std::convert::Infallible> {
63        Ok(SearchParams {
64            hnsw_ef: self.hnsw_ef.unwrap_or_default(),
65            exact: self.exact.unwrap_or_default(),
66            quantization: self.quantization.unwrap_or_default(),
67            indexed_only: self.indexed_only.unwrap_or_default(),
68        })
69    }
70    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
71    fn create_empty() -> Self {
72        Self {
73            hnsw_ef: core::default::Default::default(),
74            exact: core::default::Default::default(),
75            quantization: core::default::Default::default(),
76            indexed_only: core::default::Default::default(),
77        }
78    }
79}
80
81impl From<SearchParamsBuilder> for SearchParams {
82    fn from(value: SearchParamsBuilder) -> Self {
83        value.build_inner().unwrap_or_else(|_| {
84            panic!(
85                "Failed to convert {0} to {1}",
86                "SearchParamsBuilder", "SearchParams"
87            )
88        })
89    }
90}
91
92impl SearchParamsBuilder {
93    /// Builds the desired type. Can often be omitted.
94    pub fn build(self) -> SearchParams {
95        self.build_inner().unwrap_or_else(|_| {
96            panic!(
97                "Failed to build {0} into {1}",
98                "SearchParamsBuilder", "SearchParams"
99            )
100        })
101    }
102}
103
104impl Default for SearchParamsBuilder {
105    fn default() -> Self {
106        Self::create_empty()
107    }
108}