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