1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use crate::qdrant::*;
#[must_use]
#[derive(Clone)]
pub struct SearchParamsBuilder {
///
/// Params relevant to HNSW index. Size of the beam in a beam-search.
/// Larger the value - more accurate the result, more time required for search.
pub(crate) hnsw_ef: Option<Option<u64>>,
///
/// Search without approximation. If set to true, search may run long but with exact results.
pub(crate) exact: Option<Option<bool>>,
///
/// If set to true, search will ignore quantized vector data
pub(crate) quantization: Option<Option<QuantizationSearchParams>>,
///
/// If enabled, the engine will only perform search among indexed or small segments.
/// Using this option prevents slow searches in case of delayed index, but does not
/// guarantee that all uploaded vectors will be included in search results
pub(crate) indexed_only: Option<Option<bool>>,
///
/// Params relevant to ACORN index
pub(crate) acorn: Option<Option<AcornSearchParams>>,
///
/// Which population sparse vector IDF statistics are computed over
pub(crate) idf: Option<Option<IdfParams>>,
}
impl SearchParamsBuilder {
///
/// Params relevant to HNSW index. Size of the beam in a beam-search.
/// Larger the value - more accurate the result, more time required for search.
pub fn hnsw_ef(self, value: u64) -> Self {
let mut new = self;
new.hnsw_ef = Option::Some(Option::Some(value));
new
}
///
/// Search without approximation. If set to true, search may run long but with exact results.
pub fn exact(self, value: bool) -> Self {
let mut new = self;
new.exact = Option::Some(Option::Some(value));
new
}
///
/// If set to true, search will ignore quantized vector data
pub fn quantization<VALUE: core::convert::Into<QuantizationSearchParams>>(
self,
value: VALUE,
) -> Self {
let mut new = self;
new.quantization = Option::Some(Option::Some(value.into()));
new
}
///
/// If enabled, the engine will only perform search among indexed or small segments.
/// Using this option prevents slow searches in case of delayed index, but does not
/// guarantee that all uploaded vectors will be included in search results
pub fn indexed_only(self, value: bool) -> Self {
let mut new = self;
new.indexed_only = Option::Some(Option::Some(value));
new
}
///
/// Params relevant to ACORN index
pub fn acorn<VALUE: core::convert::Into<AcornSearchParams>>(self, value: VALUE) -> Self {
let mut new = self;
new.acorn = Option::Some(Option::Some(value.into()));
new
}
///
/// Which population sparse vector IDF statistics are computed over.
/// If unset, statistics are collection-wide (global).
pub fn idf<VALUE: core::convert::Into<IdfParams>>(self, value: VALUE) -> Self {
let mut new = self;
new.idf = Option::Some(Option::Some(value.into()));
new
}
fn build_inner(self) -> Result<SearchParams, std::convert::Infallible> {
Ok(SearchParams {
hnsw_ef: self.hnsw_ef.unwrap_or_default(),
exact: self.exact.unwrap_or_default(),
quantization: self.quantization.unwrap_or_default(),
indexed_only: self.indexed_only.unwrap_or_default(),
acorn: self.acorn.unwrap_or_default(),
idf: self.idf.unwrap_or_default(),
})
}
/// Create an empty builder, with all fields set to `None` or `PhantomData`.
fn create_empty() -> Self {
Self {
hnsw_ef: core::default::Default::default(),
exact: core::default::Default::default(),
quantization: core::default::Default::default(),
indexed_only: core::default::Default::default(),
acorn: core::default::Default::default(),
idf: core::default::Default::default(),
}
}
}
impl From<SearchParamsBuilder> for SearchParams {
fn from(value: SearchParamsBuilder) -> Self {
value.build_inner().unwrap_or_else(|_| {
panic!(
"Failed to convert {0} to {1}",
"SearchParamsBuilder", "SearchParams"
)
})
}
}
impl SearchParamsBuilder {
/// Builds the desired type. Can often be omitted.
pub fn build(self) -> SearchParams {
self.build_inner().unwrap_or_else(|_| {
panic!(
"Failed to build {0} into {1}",
"SearchParamsBuilder", "SearchParams"
)
})
}
}
impl Default for SearchParamsBuilder {
fn default() -> Self {
Self::create_empty()
}
}