qdrant_client/builders/
search_params_builder.rs1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct SearchParamsBuilder {
6 pub(crate) hnsw_ef: Option<Option<u64>>,
10 pub(crate) exact: Option<Option<bool>>,
13 pub(crate) quantization: Option<Option<QuantizationSearchParams>>,
16 pub(crate) indexed_only: Option<Option<bool>>,
21 pub(crate) acorn: Option<Option<AcornSearchParams>>,
24 pub(crate) idf: Option<Option<IdfParams>>,
27}
28
29impl SearchParamsBuilder {
30 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 pub fn exact(self, value: bool) -> Self {
41 let mut new = self;
42 new.exact = Option::Some(Option::Some(value));
43 new
44 }
45 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 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 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 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 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 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}