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}
25
26impl SearchParamsBuilder {
27 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 pub fn exact(self, value: bool) -> Self {
38 let mut new = self;
39 new.exact = Option::Some(Option::Some(value));
40 new
41 }
42 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 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 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 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 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}