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 pub(crate) acorn: Option<Option<AcornSearchParams>>,
23}
24
25impl SearchParamsBuilder {
26 pub fn hnsw_ef(self, value: u64) -> Self {
30 let mut new = self;
31 new.hnsw_ef = Option::Some(Option::Some(value));
32 new
33 }
34 pub fn exact(self, value: bool) -> Self {
37 let mut new = self;
38 new.exact = Option::Some(Option::Some(value));
39 new
40 }
41 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 pub fn indexed_only(self, value: bool) -> Self {
56 let mut new = self;
57 new.indexed_only = Option::Some(Option::Some(value));
58 new
59 }
60 pub fn acorn<VALUE: core::convert::Into<AcornSearchParams>>(self, value: VALUE) -> Self {
63 let mut new = self;
64 new.acorn = Option::Some(Option::Some(value.into()));
65 new
66 }
67
68 fn build_inner(self) -> Result<SearchParams, std::convert::Infallible> {
69 Ok(SearchParams {
70 hnsw_ef: self.hnsw_ef.unwrap_or_default(),
71 exact: self.exact.unwrap_or_default(),
72 quantization: self.quantization.unwrap_or_default(),
73 indexed_only: self.indexed_only.unwrap_or_default(),
74 acorn: self.acorn.unwrap_or_default(),
75 })
76 }
77 fn create_empty() -> Self {
79 Self {
80 hnsw_ef: core::default::Default::default(),
81 exact: core::default::Default::default(),
82 quantization: core::default::Default::default(),
83 indexed_only: core::default::Default::default(),
84 acorn: core::default::Default::default(),
85 }
86 }
87}
88
89impl From<SearchParamsBuilder> for SearchParams {
90 fn from(value: SearchParamsBuilder) -> Self {
91 value.build_inner().unwrap_or_else(|_| {
92 panic!(
93 "Failed to convert {0} to {1}",
94 "SearchParamsBuilder", "SearchParams"
95 )
96 })
97 }
98}
99
100impl SearchParamsBuilder {
101 pub fn build(self) -> SearchParams {
103 self.build_inner().unwrap_or_else(|_| {
104 panic!(
105 "Failed to build {0} into {1}",
106 "SearchParamsBuilder", "SearchParams"
107 )
108 })
109 }
110}
111
112impl Default for SearchParamsBuilder {
113 fn default() -> Self {
114 Self::create_empty()
115 }
116}