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