Skip to main content

qdrant_edge/edge/builders/
retrieve_request.rs

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