qdrant_client/builders/
discover_input_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct DiscoverInputBuilder {
5    /// Use this as the primary search objective
6    pub(crate) target: Option<Option<VectorInput>>,
7    /// Search space will be constrained by these pairs of vectors
8    pub(crate) context: Option<Option<ContextInput>>,
9}
10
11impl DiscoverInputBuilder {
12    /// Use this as the primary search objective
13    pub fn target<VALUE: core::convert::Into<VectorInput>>(self, value: VALUE) -> Self {
14        let mut new = self;
15        new.target = Option::Some(Option::Some(value.into()));
16        new
17    }
18    /// Search space will be constrained by these pairs of vectors
19    pub fn context<VALUE: core::convert::Into<ContextInput>>(self, value: VALUE) -> Self {
20        let mut new = self;
21        new.context = Option::Some(Option::Some(value.into()));
22        new
23    }
24
25    fn build_inner(self) -> Result<DiscoverInput, DiscoverInputBuilderError> {
26        Ok(DiscoverInput {
27            target: self.target.unwrap_or_default(),
28            context: self.context.unwrap_or_default(),
29        })
30    }
31    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
32    fn create_empty() -> Self {
33        Self {
34            target: core::default::Default::default(),
35            context: core::default::Default::default(),
36        }
37    }
38}
39
40impl From<DiscoverInputBuilder> for DiscoverInput {
41    fn from(value: DiscoverInputBuilder) -> Self {
42        value.build_inner().unwrap_or_else(|_| {
43            panic!(
44                "Failed to convert {0} to {1}",
45                "DiscoverInputBuilder", "DiscoverInput"
46            )
47        })
48    }
49}
50
51impl DiscoverInputBuilder {
52    /// Builds the desired type. Can often be omitted.
53    pub fn build(self) -> DiscoverInput {
54        self.build_inner().unwrap_or_else(|_| {
55            panic!(
56                "Failed to build {0} into {1}",
57                "DiscoverInputBuilder", "DiscoverInput"
58            )
59        })
60    }
61}
62
63impl DiscoverInputBuilder {
64    pub(crate) fn empty() -> Self {
65        Self::create_empty()
66    }
67}
68
69/// Error type for DiscoverInputBuilder
70#[non_exhaustive]
71#[derive(Debug)]
72pub enum DiscoverInputBuilderError {
73    /// Uninitialized field
74    UninitializedField(&'static str),
75    /// Custom validation error
76    ValidationError(String),
77}
78
79// Implementing the From trait for conversion from UninitializedFieldError
80impl From<derive_builder::UninitializedFieldError> for DiscoverInputBuilderError {
81    fn from(s: derive_builder::UninitializedFieldError) -> Self {
82        Self::UninitializedField(s.field_name())
83    }
84}
85
86// Implementing the From trait for conversion from String
87impl From<String> for DiscoverInputBuilderError {
88    fn from(s: String) -> Self {
89        Self::ValidationError(s)
90    }
91}
92
93// Implementing the Display trait for better error messages
94impl std::fmt::Display for DiscoverInputBuilderError {
95    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
96        match self {
97            Self::UninitializedField(ref field) => {
98                write!(f, "`{field}` must be initialized")
99            }
100            Self::ValidationError(ref error) => write!(f, "{error}"),
101        }
102    }
103}
104
105// Implementing the Error trait
106impl std::error::Error for DiscoverInputBuilderError {}