qdrant_client/builders/
prefetch_query_builder.rs1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct PrefetchQueryBuilder {
6 pub(crate) prefetch: Option<Vec<PrefetchQuery>>,
8 pub(crate) query: Option<Option<Query>>,
10 pub(crate) using: Option<Option<String>>,
12 pub(crate) filter: Option<Option<Filter>>,
14 pub(crate) params: Option<Option<SearchParams>>,
16 pub(crate) score_threshold: Option<Option<f32>>,
18 pub(crate) limit: Option<Option<u64>>,
20 pub(crate) lookup_from: Option<Option<LookupLocation>>,
22}
23
24impl PrefetchQueryBuilder {
25 pub fn prefetch<VALUE: core::convert::Into<Vec<PrefetchQuery>>>(self, value: VALUE) -> Self {
27 let mut new = self;
28 new.prefetch = Option::Some(value.into());
29 new
30 }
31 pub fn query<VALUE: core::convert::Into<Query>>(self, value: VALUE) -> Self {
33 let mut new = self;
34 new.query = Option::Some(Option::Some(value.into()));
35 new
36 }
37 pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
39 let mut new = self;
40 new.using = Option::Some(Option::Some(value.into()));
41 new
42 }
43 pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
45 let mut new = self;
46 new.filter = Option::Some(Option::Some(value.into()));
47 new
48 }
49 pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
51 let mut new = self;
52 new.params = Option::Some(Option::Some(value.into()));
53 new
54 }
55 pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
57 let mut new = self;
58 new.score_threshold = Option::Some(Option::Some(value.into()));
59 new
60 }
61 pub fn limit<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
63 let mut new = self;
64 new.limit = Option::Some(Option::Some(value.into()));
65 new
66 }
67 pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
69 let mut new = self;
70 new.lookup_from = Option::Some(Option::Some(value.into()));
71 new
72 }
73
74 fn build_inner(self) -> Result<PrefetchQuery, std::convert::Infallible> {
75 Ok(PrefetchQuery {
76 prefetch: self.prefetch.unwrap_or_default(),
77 query: self.query.unwrap_or_default(),
78 using: self.using.unwrap_or_default(),
79 filter: self.filter.unwrap_or_default(),
80 params: self.params.unwrap_or_default(),
81 score_threshold: self.score_threshold.unwrap_or_default(),
82 limit: self.limit.unwrap_or_default(),
83 lookup_from: self.lookup_from.unwrap_or_default(),
84 })
85 }
86 fn create_empty() -> Self {
88 Self {
89 prefetch: core::default::Default::default(),
90 query: core::default::Default::default(),
91 using: core::default::Default::default(),
92 filter: core::default::Default::default(),
93 params: core::default::Default::default(),
94 score_threshold: core::default::Default::default(),
95 limit: core::default::Default::default(),
96 lookup_from: core::default::Default::default(),
97 }
98 }
99}
100
101impl From<PrefetchQueryBuilder> for PrefetchQuery {
102 fn from(value: PrefetchQueryBuilder) -> Self {
103 value.build_inner().unwrap_or_else(|_| {
104 panic!(
105 "Failed to convert {0} to {1}",
106 "PrefetchQueryBuilder", "PrefetchQuery"
107 )
108 })
109 }
110}
111
112impl PrefetchQueryBuilder {
113 pub fn build(self) -> PrefetchQuery {
115 self.build_inner().unwrap_or_else(|_| {
116 panic!(
117 "Failed to build {0} into {1}",
118 "PrefetchQueryBuilder", "PrefetchQuery"
119 )
120 })
121 }
122}
123
124impl Default for PrefetchQueryBuilder {
125 fn default() -> Self {
126 Self::create_empty()
127 }
128}