Skip to main content

qdrant_client/builders/
recommend_input_builder.rs

1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct RecommendInputBuilder {
6    /// Look for vectors closest to the vectors from these points
7    pub(crate) positive: Option<Vec<VectorInput>>,
8    /// Try to avoid vectors like the vector from these points
9    pub(crate) negative: Option<Vec<VectorInput>>,
10    /// How to use the provided vectors to find the results
11    pub(crate) strategy: Option<Option<i32>>,
12}
13
14impl RecommendInputBuilder {
15    /// Look for vectors closest to the vectors from these points
16    pub fn positive<VALUE: core::convert::Into<Vec<VectorInput>>>(self, value: VALUE) -> Self {
17        let mut new = self;
18        new.positive = Option::Some(value.into());
19        new
20    }
21    /// Try to avoid vectors like the vector from these points
22    pub fn negative<VALUE: core::convert::Into<Vec<VectorInput>>>(self, value: VALUE) -> Self {
23        let mut new = self;
24        new.negative = Option::Some(value.into());
25        new
26    }
27    /// How to use the provided vectors to find the results
28    pub fn strategy<VALUE: core::convert::Into<i32>>(self, value: VALUE) -> Self {
29        let mut new = self;
30        new.strategy = Option::Some(Option::Some(value.into()));
31        new
32    }
33
34    fn build_inner(self) -> Result<RecommendInput, std::convert::Infallible> {
35        Ok(RecommendInput {
36            positive: self.positive.unwrap_or_default(),
37            negative: self.negative.unwrap_or_default(),
38            strategy: self.strategy.unwrap_or_default(),
39        })
40    }
41    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
42    fn create_empty() -> Self {
43        Self {
44            positive: core::default::Default::default(),
45            negative: core::default::Default::default(),
46            strategy: core::default::Default::default(),
47        }
48    }
49}
50
51impl From<RecommendInputBuilder> for RecommendInput {
52    fn from(value: RecommendInputBuilder) -> Self {
53        value.build_inner().unwrap_or_else(|_| {
54            panic!(
55                "Failed to convert {0} to {1}",
56                "RecommendInputBuilder", "RecommendInput"
57            )
58        })
59    }
60}
61
62impl RecommendInputBuilder {
63    /// Builds the desired type. Can often be omitted.
64    pub fn build(self) -> RecommendInput {
65        self.build_inner().unwrap_or_else(|_| {
66            panic!(
67                "Failed to build {0} into {1}",
68                "RecommendInputBuilder", "RecommendInput"
69            )
70        })
71    }
72}
73
74impl Default for RecommendInputBuilder {
75    fn default() -> Self {
76        Self::create_empty()
77    }
78}