qdrant_client/builders/
recommend_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
use crate::qdrant::*;

pub struct RecommendInputBuilder {
    /// Look for vectors closest to the vectors from these points
    pub(crate) positive: Option<Vec<VectorInput>>,
    /// Try to avoid vectors like the vector from these points
    pub(crate) negative: Option<Vec<VectorInput>>,
    /// How to use the provided vectors to find the results
    pub(crate) strategy: Option<Option<i32>>,
}

impl RecommendInputBuilder {
    /// Look for vectors closest to the vectors from these points
    #[allow(unused_mut)]
    pub fn positive<VALUE: core::convert::Into<Vec<VectorInput>>>(self, value: VALUE) -> Self {
        let mut new = self;
        new.positive = Option::Some(value.into());
        new
    }
    /// Try to avoid vectors like the vector from these points
    #[allow(unused_mut)]
    pub fn negative<VALUE: core::convert::Into<Vec<VectorInput>>>(self, value: VALUE) -> Self {
        let mut new = self;
        new.negative = Option::Some(value.into());
        new
    }
    /// How to use the provided vectors to find the results
    #[allow(unused_mut)]
    pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
        let mut new = self;
        new.strategy = Option::Some(Option::Some(value.into()));
        new
    }

    fn build_inner(self) -> Result<RecommendInput, std::convert::Infallible> {
        Ok(RecommendInput {
            positive: self.positive.unwrap_or_default(),
            negative: self.negative.unwrap_or_default(),
            strategy: self.strategy.unwrap_or_default(),
        })
    }
    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
    fn create_empty() -> Self {
        Self {
            positive: core::default::Default::default(),
            negative: core::default::Default::default(),
            strategy: core::default::Default::default(),
        }
    }
}

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

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

impl Default for RecommendInputBuilder {
    fn default() -> Self {
        Self::create_empty()
    }
}