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
use crate::qdrant::*;
#[derive(Clone)]
pub struct QuantizationSearchParamsBuilder {
///
/// If set to true, search will ignore quantized vector data
pub(crate) ignore: Option<Option<bool>>,
///
/// If true, use original vectors to re-score top-k results. If ignored, qdrant decides automatically does rescore enabled or not.
pub(crate) rescore: Option<Option<bool>>,
///
/// Oversampling factor for quantization.
///
/// Defines how many extra vectors should be pre-selected using quantized index,
/// and then re-scored using original vectors.
///
/// For example, if `oversampling` is 2.4 and `limit` is 100, then 240 vectors will be pre-selected using quantized index,
/// and then top-100 will be returned after re-scoring.
pub(crate) oversampling: Option<Option<f64>>,
}
impl QuantizationSearchParamsBuilder {
///
/// If set to true, search will ignore quantized vector data
pub fn ignore(self, value: bool) -> Self {
let mut new = self;
new.ignore = Option::Some(Option::Some(value));
new
}
///
/// If true, use original vectors to re-score top-k results. If ignored, qdrant decides automatically does rescore enabled or not.
pub fn rescore(self, value: bool) -> Self {
let mut new = self;
new.rescore = Option::Some(Option::Some(value));
new
}
///
/// Oversampling factor for quantization.
///
/// Defines how many extra vectors should be pre-selected using quantized index,
/// and then re-scored using original vectors.
///
/// For example, if `oversampling` is 2.4 and `limit` is 100, then 240 vectors will be pre-selected using quantized index,
/// and then top-100 will be returned after re-scoring.
pub fn oversampling(self, value: f64) -> Self {
let mut new = self;
new.oversampling = Option::Some(Option::Some(value));
new
}
fn build_inner(self) -> Result<QuantizationSearchParams, std::convert::Infallible> {
Ok(QuantizationSearchParams {
ignore: self.ignore.unwrap_or_default(),
rescore: self.rescore.unwrap_or_default(),
oversampling: self.oversampling.unwrap_or_default(),
})
}
/// Create an empty builder, with all fields set to `None` or `PhantomData`.
fn create_empty() -> Self {
Self {
ignore: core::default::Default::default(),
rescore: core::default::Default::default(),
oversampling: core::default::Default::default(),
}
}
}
impl Default for QuantizationSearchParamsBuilder {
fn default() -> Self {
Self::create_empty()
}
}
impl From<QuantizationSearchParamsBuilder> for QuantizationSearchParams {
fn from(value: QuantizationSearchParamsBuilder) -> Self {
value.build_inner().unwrap_or_else(|_| {
panic!(
"Failed to convert {0} to {1}",
"QuantizationSearchParamsBuilder", "QuantizationSearchParams"
)
})
}
}
impl QuantizationSearchParamsBuilder {
/// Builds the desired type. Can often be omitted.
pub fn build(self) -> QuantizationSearchParams {
self.build_inner().unwrap_or_else(|_| {
panic!(
"Failed to build {0} into {1}",
"QuantizationSearchParamsBuilder", "QuantizationSearchParams"
)
})
}
}