qdrant_client/builders/
context_input_pair_builder.rs1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct ContextInputPairBuilder {
5 pub(crate) positive: Option<Option<VectorInput>>,
7 pub(crate) negative: Option<Option<VectorInput>>,
9}
10
11impl ContextInputPairBuilder {
12 pub fn positive<VALUE: core::convert::Into<VectorInput>>(self, value: VALUE) -> Self {
14 let mut new = self;
15 new.positive = Option::Some(Option::Some(value.into()));
16 new
17 }
18 pub fn negative<VALUE: core::convert::Into<VectorInput>>(self, value: VALUE) -> Self {
20 let mut new = self;
21 new.negative = Option::Some(Option::Some(value.into()));
22 new
23 }
24
25 fn build_inner(self) -> Result<ContextInputPair, ContextInputPairBuilderError> {
26 Ok(ContextInputPair {
27 positive: self.positive.unwrap_or_default(),
28 negative: self.negative.unwrap_or_default(),
29 })
30 }
31 fn create_empty() -> Self {
33 Self {
34 positive: core::default::Default::default(),
35 negative: core::default::Default::default(),
36 }
37 }
38}
39
40impl From<ContextInputPairBuilder> for ContextInputPair {
41 fn from(value: ContextInputPairBuilder) -> Self {
42 value.build_inner().unwrap_or_else(|_| {
43 panic!(
44 "Failed to convert {0} to {1}",
45 "ContextInputPairBuilder", "ContextInputPair"
46 )
47 })
48 }
49}
50
51impl ContextInputPairBuilder {
52 pub fn build(self) -> ContextInputPair {
54 self.build_inner().unwrap_or_else(|_| {
55 panic!(
56 "Failed to build {0} into {1}",
57 "ContextInputPairBuilder", "ContextInputPair"
58 )
59 })
60 }
61}
62
63impl ContextInputPairBuilder {
64 pub(crate) fn empty() -> Self {
65 Self::create_empty()
66 }
67}
68
69#[non_exhaustive]
71#[derive(Debug)]
72pub enum ContextInputPairBuilderError {
73 UninitializedField(&'static str),
75 ValidationError(String),
77}
78
79impl std::fmt::Display for ContextInputPairBuilderError {
81 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
82 match self {
83 Self::UninitializedField(field) => {
84 write!(f, "`{field}` must be initialized")
85 }
86 Self::ValidationError(error) => write!(f, "{error}"),
87 }
88 }
89}
90
91impl std::error::Error for ContextInputPairBuilderError {}
93
94impl From<derive_builder::UninitializedFieldError> for ContextInputPairBuilderError {
96 fn from(error: derive_builder::UninitializedFieldError) -> Self {
97 Self::UninitializedField(error.field_name())
98 }
99}
100
101impl From<String> for ContextInputPairBuilderError {
103 fn from(error: String) -> Self {
104 Self::ValidationError(error)
105 }
106}