Skip to main content

qdrant_client/builders/
acorn_search_params_builder.rs

1use crate::qdrant::AcornSearchParams;
2
3#[derive(Clone)]
4pub struct AcornSearchParamsBuilder {
5    /// If true, then ACORN may be used for the HNSW search based on filters selectivity.
6    ///
7    /// Improves search recall for searches with multiple low-selectivity
8    /// payload filters, at cost of performance.
9    pub(crate) enable: bool,
10    /// Maximum selectivity of filters to enable ACORN.
11    ///
12    /// If estimated filters selectivity is higher than this value,
13    /// ACORN will not be used. Selectivity is estimated as:
14    /// `estimated number of points satisfying the filters / total number of points`.
15    ///
16    /// 0.0 for never, 1.0 for always. Default is 0.4.
17    pub(crate) max_selectivity: Option<Option<f64>>,
18}
19
20impl AcornSearchParamsBuilder {
21    /// Create a new AcornSearchParamsBuilder with required enable parameter.
22    ///
23    /// # Arguments
24    ///
25    /// * `enable` - If true, ACORN may be used for HNSW search based on filter selectivity
26    ///
27    /// # Examples
28    ///
29    /// ```
30    /// use qdrant_client::qdrant::AcornSearchParamsBuilder;
31    ///
32    /// let acorn = AcornSearchParamsBuilder::new(true).build();
33    /// let acorn_with_selectivity = AcornSearchParamsBuilder::new(true)
34    ///     .max_selectivity(0.5)
35    ///     .build();
36    /// ```
37    pub fn new(enable: bool) -> Self {
38        Self {
39            enable,
40            max_selectivity: None,
41        }
42    }
43
44    /// Set maximum selectivity threshold for enabling ACORN.
45    ///
46    /// If estimated filter selectivity is higher than this value, ACORN will not be used.
47    /// Selectivity is estimated as: `estimated number of points satisfying the filters / total number of points`
48    ///
49    /// Value between 0.0 (never) and 1.0 (always). Default is 0.4.
50    pub fn max_selectivity(self, value: f64) -> Self {
51        let mut new = self;
52        new.max_selectivity = Option::Some(Option::Some(value));
53        new
54    }
55
56    pub fn build(self) -> AcornSearchParams {
57        AcornSearchParams {
58            enable: Some(self.enable),
59            max_selectivity: self.max_selectivity.unwrap_or_default(),
60        }
61    }
62}
63
64impl From<AcornSearchParamsBuilder> for AcornSearchParams {
65    fn from(value: AcornSearchParamsBuilder) -> Self {
66        value.build()
67    }
68}