Skip to main content

qdrant_edge/edge/builders/
edge_sparse_vector_params.rs

1//! Fluent builder for [`EdgeSparseVectorParams`].
2//!
3//! Builder fields mirror [`EdgeSparseVectorParams`] explicitly so adding a
4//! field to the target struct forces a compile error here.
5
6use crate::segment::data_types::modifier::Modifier;
7use crate::segment::types::VectorStorageDatatype;
8
9use crate::edge::config::vectors::EdgeSparseVectorParams;
10
11/// Fluent builder for [`EdgeSparseVectorParams`].
12///
13/// All fields are optional; calling [`Self::build`] without setters yields
14/// an [`EdgeSparseVectorParams`] with every field `None`.
15#[derive(Debug, Clone, Default)]
16pub struct EdgeSparseVectorParamsBuilder {
17    full_scan_threshold: Option<usize>,
18    on_disk: Option<bool>,
19    modifier: Option<Modifier>,
20    datatype: Option<VectorStorageDatatype>,
21}
22
23impl EdgeSparseVectorParamsBuilder {
24    pub fn new() -> Self {
25        Self::default()
26    }
27
28    pub fn full_scan_threshold(mut self, full_scan_threshold: usize) -> Self {
29        self.full_scan_threshold = Some(full_scan_threshold);
30        self
31    }
32
33    /// If `true`, sparse index is on disk (mmap); otherwise in RAM.
34    pub fn on_disk(mut self, on_disk: bool) -> Self {
35        self.on_disk = Some(on_disk);
36        self
37    }
38
39    pub fn modifier(mut self, modifier: Modifier) -> Self {
40        self.modifier = Some(modifier);
41        self
42    }
43
44    pub fn datatype(mut self, datatype: VectorStorageDatatype) -> Self {
45        self.datatype = Some(datatype);
46        self
47    }
48
49    pub fn build(self) -> EdgeSparseVectorParams {
50        // Exhaustively destructure Self and construct EdgeSparseVectorParams:
51        // adding a field to either type forces a compile error here.
52        let Self {
53            full_scan_threshold,
54            on_disk,
55            modifier,
56            datatype,
57        } = self;
58        EdgeSparseVectorParams {
59            full_scan_threshold,
60            on_disk,
61            modifier,
62            datatype,
63        }
64    }
65}