qdrant_client/builders/
discover_input_builder.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use crate::qdrant::*;

pub struct DiscoverInputBuilder {
    /// Use this as the primary search objective
    pub(crate) target: Option<Option<VectorInput>>,
    /// Search space will be constrained by these pairs of vectors
    pub(crate) context: Option<Option<ContextInput>>,
}

impl DiscoverInputBuilder {
    /// Use this as the primary search objective
    #[allow(unused_mut)]
    pub fn target<VALUE: core::convert::Into<VectorInput>>(self, value: VALUE) -> Self {
        let mut new = self;
        new.target = Option::Some(Option::Some(value.into()));
        new
    }
    /// Search space will be constrained by these pairs of vectors
    #[allow(unused_mut)]
    pub fn context<VALUE: core::convert::Into<ContextInput>>(self, value: VALUE) -> Self {
        let mut new = self;
        new.context = Option::Some(Option::Some(value.into()));
        new
    }

    fn build_inner(self) -> Result<DiscoverInput, DiscoverInputBuilderError> {
        Ok(DiscoverInput {
            target: self.target.unwrap_or_default(),
            context: self.context.unwrap_or_default(),
        })
    }
    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
    fn create_empty() -> Self {
        Self {
            target: core::default::Default::default(),
            context: core::default::Default::default(),
        }
    }
}

impl From<DiscoverInputBuilder> for DiscoverInput {
    fn from(value: DiscoverInputBuilder) -> Self {
        value.build_inner().unwrap_or_else(|_| {
            panic!(
                "Failed to convert {0} to {1}",
                "DiscoverInputBuilder", "DiscoverInput"
            )
        })
    }
}

impl DiscoverInputBuilder {
    /// Builds the desired type. Can often be omitted.
    pub fn build(self) -> DiscoverInput {
        self.build_inner().unwrap_or_else(|_| {
            panic!(
                "Failed to build {0} into {1}",
                "DiscoverInputBuilder", "DiscoverInput"
            )
        })
    }
}

impl DiscoverInputBuilder {
    pub(crate) fn empty() -> Self {
        Self::create_empty()
    }
}

/// Error type for DiscoverInputBuilder
#[non_exhaustive]
#[derive(Debug)]
pub enum DiscoverInputBuilderError {
    /// Uninitialized field
    UninitializedField(&'static str),
    /// Custom validation error
    ValidationError(String),
}

// Implementing the From trait for conversion from UninitializedFieldError
impl From<derive_builder::UninitializedFieldError> for DiscoverInputBuilderError {
    fn from(s: derive_builder::UninitializedFieldError) -> Self {
        Self::UninitializedField(s.field_name())
    }
}

// Implementing the From trait for conversion from String
impl From<String> for DiscoverInputBuilderError {
    fn from(s: String) -> Self {
        Self::ValidationError(s)
    }
}

// Implementing the Display trait for better error messages
impl std::fmt::Display for DiscoverInputBuilderError {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::UninitializedField(ref field) => {
                write!(f, "`{}` must be initialized", field)
            }
            Self::ValidationError(ref error) => write!(f, "{}", error),
        }
    }
}

// Implementing the Error trait
impl std::error::Error for DiscoverInputBuilderError {}