Skip to main content

qdrant_edge/edge/builders/
search_matrix_request.rs

1//! Fluent builder for [`SearchMatrixRequest`].
2//!
3//! Builder fields mirror [`SearchMatrixRequest`] explicitly so adding a field
4//! to the target struct forces a compile error here.
5
6use crate::segment::types::{Filter, VectorNameBuf};
7
8use crate::edge::requests::matrix::SearchMatrixRequest;
9
10/// Fluent builder for [`SearchMatrixRequest`].
11///
12/// `sample_size`, `limit_per_sample` and `using` are required and passed through
13/// [`Self::new`]; every other field is optional and falls back to the
14/// [`SearchMatrixRequest::new`] defaults.
15#[derive(Clone, Debug)]
16pub struct SearchMatrixRequestBuilder {
17    sample_size: usize,
18    limit_per_sample: usize,
19    filter: Option<Filter>,
20    using: VectorNameBuf,
21}
22
23impl SearchMatrixRequestBuilder {
24    pub fn new(sample_size: usize, limit_per_sample: usize, using: VectorNameBuf) -> Self {
25        let SearchMatrixRequest {
26            sample_size,
27            limit_per_sample,
28            filter,
29            using,
30        } = SearchMatrixRequest::new(sample_size, limit_per_sample, using);
31        Self {
32            sample_size,
33            limit_per_sample,
34            filter,
35            using,
36        }
37    }
38
39    pub fn filter(mut self, filter: Filter) -> Self {
40        self.filter = Some(filter);
41        self
42    }
43
44    pub fn build(self) -> SearchMatrixRequest {
45        // Exhaustively destructure Self and construct SearchMatrixRequest:
46        // adding a field to either type forces a compile error here.
47        let Self {
48            sample_size,
49            limit_per_sample,
50            filter,
51            using,
52        } = self;
53        SearchMatrixRequest {
54            sample_size,
55            limit_per_sample,
56            filter,
57            using,
58        }
59    }
60}