Skip to main content

qdrant_edge/edge/builders/
edge_vector_params.rs

1//! Fluent builder for [`EdgeVectorParams`].
2//!
3//! Builder fields mirror [`EdgeVectorParams`] explicitly so adding a field
4//! to the target struct forces a compile error here.
5
6use crate::segment::types::{
7    Distance, HnswConfig, MultiVectorConfig, QuantizationConfig, VectorStorageDatatype,
8};
9
10use crate::edge::config::vectors::EdgeVectorParams;
11
12/// Fluent builder for [`EdgeVectorParams`].
13///
14/// `size` and `distance` are required and passed through [`Self::new`]; every
15/// other field is optional and falls back to `None`.
16#[derive(Debug, Clone)]
17pub struct EdgeVectorParamsBuilder {
18    size: usize,
19    distance: Distance,
20    on_disk: Option<bool>,
21    multivector_config: Option<MultiVectorConfig>,
22    datatype: Option<VectorStorageDatatype>,
23    quantization_config: Option<QuantizationConfig>,
24    hnsw_config: Option<HnswConfig>,
25}
26
27impl EdgeVectorParamsBuilder {
28    pub fn new(size: usize, distance: Distance) -> Self {
29        Self {
30            size,
31            distance,
32            on_disk: None,
33            multivector_config: None,
34            datatype: None,
35            quantization_config: None,
36            hnsw_config: None,
37        }
38    }
39
40    /// If `true`, vector storage is on disk (mmap); otherwise in RAM.
41    pub fn on_disk(mut self, on_disk: bool) -> Self {
42        self.on_disk = Some(on_disk);
43        self
44    }
45
46    pub fn multivector_config(mut self, multivector_config: MultiVectorConfig) -> Self {
47        self.multivector_config = Some(multivector_config);
48        self
49    }
50
51    pub fn datatype(mut self, datatype: VectorStorageDatatype) -> Self {
52        self.datatype = Some(datatype);
53        self
54    }
55
56    /// Per-vector quantization. Overrides the global
57    /// [`EdgeConfig::quantization_config`](crate::EdgeConfig::quantization_config)
58    /// when set.
59    pub fn quantization_config(mut self, quantization_config: QuantizationConfig) -> Self {
60        self.quantization_config = Some(quantization_config);
61        self
62    }
63
64    /// Per-vector HNSW config. Overrides the global
65    /// [`EdgeConfig::hnsw_config`](crate::EdgeConfig::hnsw_config) when set.
66    pub fn hnsw_config(mut self, hnsw_config: HnswConfig) -> Self {
67        self.hnsw_config = Some(hnsw_config);
68        self
69    }
70
71    pub fn build(self) -> EdgeVectorParams {
72        // Exhaustively destructure Self and construct EdgeVectorParams:
73        // adding a field to either type forces a compile error here.
74        let Self {
75            size,
76            distance,
77            on_disk,
78            multivector_config,
79            datatype,
80            quantization_config,
81            hnsw_config,
82        } = self;
83        EdgeVectorParams {
84            size,
85            distance,
86            on_disk,
87            multivector_config,
88            datatype,
89            quantization_config,
90            hnsw_config,
91        }
92    }
93}