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
use crate::qdrant::AcornSearchParams;
#[derive(Clone)]
pub struct AcornSearchParamsBuilder {
/// If true, then ACORN may be used for the HNSW search based on filters selectivity.
///
/// Improves search recall for searches with multiple low-selectivity
/// payload filters, at cost of performance.
pub(crate) enable: bool,
/// Maximum selectivity of filters to enable ACORN.
///
/// If estimated filters selectivity is higher than this value,
/// ACORN will not be used. Selectivity is estimated as:
/// `estimated number of points satisfying the filters / total number of points`.
///
/// 0.0 for never, 1.0 for always. Default is 0.4.
pub(crate) max_selectivity: Option<Option<f64>>,
}
impl AcornSearchParamsBuilder {
/// Create a new AcornSearchParamsBuilder with required enable parameter.
///
/// # Arguments
///
/// * `enable` - If true, ACORN may be used for HNSW search based on filter selectivity
///
/// # Examples
///
/// ```
/// use qdrant_client::qdrant::AcornSearchParamsBuilder;
///
/// let acorn = AcornSearchParamsBuilder::new(true).build();
/// let acorn_with_selectivity = AcornSearchParamsBuilder::new(true)
/// .max_selectivity(0.5)
/// .build();
/// ```
pub fn new(enable: bool) -> Self {
Self {
enable,
max_selectivity: None,
}
}
/// Set maximum selectivity threshold for enabling ACORN.
///
/// If estimated filter selectivity is higher than this value, ACORN will not be used.
/// Selectivity is estimated as: `estimated number of points satisfying the filters / total number of points`
///
/// Value between 0.0 (never) and 1.0 (always). Default is 0.4.
pub fn max_selectivity(self, value: f64) -> Self {
let mut new = self;
new.max_selectivity = Option::Some(Option::Some(value));
new
}
pub fn build(self) -> AcornSearchParams {
AcornSearchParams {
enable: Some(self.enable),
max_selectivity: self.max_selectivity.unwrap_or_default(),
}
}
}
impl From<AcornSearchParamsBuilder> for AcornSearchParams {
fn from(value: AcornSearchParamsBuilder) -> Self {
value.build()
}
}