qdrant_client/builders/
search_params_builder.rs1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct SearchParamsBuilder {
5 pub(crate) hnsw_ef: Option<Option<u64>>,
9 pub(crate) exact: Option<Option<bool>>,
12 pub(crate) quantization: Option<Option<QuantizationSearchParams>>,
15 pub(crate) indexed_only: Option<Option<bool>>,
20}
21
22impl SearchParamsBuilder {
23 #[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 #[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 #[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 #[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 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 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}