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