qdrant_client/builders/
prefetch_query_builder.rs

1use crate::qdrant::*;
2
3#[derive(Clone)]
4pub struct PrefetchQueryBuilder {
5    /// Sub-requests to perform first. If present, the query will be performed on the results of the prefetches.
6    pub(crate) prefetch: Option<Vec<PrefetchQuery>>,
7    /// Query to perform. If missing, returns points ordered by their IDs.
8    pub(crate) query: Option<Option<Query>>,
9    /// Define which vector to use for querying. If missing, the default vector is is used.
10    pub(crate) using: Option<Option<String>>,
11    /// Filter conditions - return only those points that satisfy the specified conditions.
12    pub(crate) filter: Option<Option<Filter>>,
13    /// Search params for when there is no prefetch.
14    pub(crate) params: Option<Option<SearchParams>>,
15    /// Return points with scores better than this threshold.
16    pub(crate) score_threshold: Option<Option<f32>>,
17    /// Max number of points. Default is 10
18    pub(crate) limit: Option<Option<u64>>,
19    /// The location to use for IDs lookup, if not specified - use the current collection and the 'using' vector
20    pub(crate) lookup_from: Option<Option<LookupLocation>>,
21}
22
23impl PrefetchQueryBuilder {
24    /// Sub-requests to perform first. If present, the query will be performed on the results of the prefetches.
25    #[allow(unused_mut)]
26    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    /// Query to perform. If missing, returns points ordered by their IDs.
32    #[allow(unused_mut)]
33    pub fn query<VALUE: core::convert::Into<Query>>(self, value: VALUE) -> Self {
34        let mut new = self;
35        new.query = Option::Some(Option::Some(value.into()));
36        new
37    }
38    /// Define which vector to use for querying. If missing, the default vector is is used.
39    #[allow(unused_mut)]
40    pub fn using<VALUE: core::convert::Into<String>>(self, value: VALUE) -> Self {
41        let mut new = self;
42        new.using = Option::Some(Option::Some(value.into()));
43        new
44    }
45    /// Filter conditions - return only those points that satisfy the specified conditions.
46    #[allow(unused_mut)]
47    pub fn filter<VALUE: core::convert::Into<Filter>>(self, value: VALUE) -> Self {
48        let mut new = self;
49        new.filter = Option::Some(Option::Some(value.into()));
50        new
51    }
52    /// Search params for when there is no prefetch.
53    #[allow(unused_mut)]
54    pub fn params<VALUE: core::convert::Into<SearchParams>>(self, value: VALUE) -> Self {
55        let mut new = self;
56        new.params = Option::Some(Option::Some(value.into()));
57        new
58    }
59    /// Return points with scores better than this threshold.
60    #[allow(unused_mut)]
61    pub fn score_threshold<VALUE: core::convert::Into<f32>>(self, value: VALUE) -> Self {
62        let mut new = self;
63        new.score_threshold = Option::Some(Option::Some(value.into()));
64        new
65    }
66    /// Max number of points. Default is 10
67    #[allow(unused_mut)]
68    pub fn limit<VALUE: core::convert::Into<u64>>(self, value: VALUE) -> Self {
69        let mut new = self;
70        new.limit = Option::Some(Option::Some(value.into()));
71        new
72    }
73    /// The location to use for IDs lookup, if not specified - use the current collection and the 'using' vector
74    #[allow(unused_mut)]
75    pub fn lookup_from<VALUE: core::convert::Into<LookupLocation>>(self, value: VALUE) -> Self {
76        let mut new = self;
77        new.lookup_from = Option::Some(Option::Some(value.into()));
78        new
79    }
80
81    fn build_inner(self) -> Result<PrefetchQuery, std::convert::Infallible> {
82        Ok(PrefetchQuery {
83            prefetch: self.prefetch.unwrap_or_default(),
84            query: self.query.unwrap_or_default(),
85            using: self.using.unwrap_or_default(),
86            filter: self.filter.unwrap_or_default(),
87            params: self.params.unwrap_or_default(),
88            score_threshold: self.score_threshold.unwrap_or_default(),
89            limit: self.limit.unwrap_or_default(),
90            lookup_from: self.lookup_from.unwrap_or_default(),
91        })
92    }
93    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
94    fn create_empty() -> Self {
95        Self {
96            prefetch: core::default::Default::default(),
97            query: core::default::Default::default(),
98            using: core::default::Default::default(),
99            filter: core::default::Default::default(),
100            params: core::default::Default::default(),
101            score_threshold: core::default::Default::default(),
102            limit: core::default::Default::default(),
103            lookup_from: core::default::Default::default(),
104        }
105    }
106}
107
108impl From<PrefetchQueryBuilder> for PrefetchQuery {
109    fn from(value: PrefetchQueryBuilder) -> Self {
110        value.build_inner().unwrap_or_else(|_| {
111            panic!(
112                "Failed to convert {0} to {1}",
113                "PrefetchQueryBuilder", "PrefetchQuery"
114            )
115        })
116    }
117}
118
119impl PrefetchQueryBuilder {
120    /// Builds the desired type. Can often be omitted.
121    pub fn build(self) -> PrefetchQuery {
122        self.build_inner().unwrap_or_else(|_| {
123            panic!(
124                "Failed to build {0} into {1}",
125                "PrefetchQueryBuilder", "PrefetchQuery"
126            )
127        })
128    }
129}
130
131impl Default for PrefetchQueryBuilder {
132    fn default() -> Self {
133        Self::create_empty()
134    }
135}