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