Skip to main content

qdrant_client/builders/
prefetch_query_builder.rs

1use crate::qdrant::*;
2
3#[must_use]
4#[derive(Clone)]
5pub struct PrefetchQueryBuilder {
6    /// Sub-requests to perform first. If present, the query will be performed on the results of the prefetches.
7    pub(crate) prefetch: Option<Vec<PrefetchQuery>>,
8    /// Query to perform. If missing, returns points ordered by their IDs.
9    pub(crate) query: Option<Option<Query>>,
10    /// Define which vector to use for querying. If missing, the default vector is is used.
11    pub(crate) using: Option<Option<String>>,
12    /// Filter conditions - return only those points that satisfy the specified conditions.
13    pub(crate) filter: Option<Option<Filter>>,
14    /// Search params for when there is no prefetch.
15    pub(crate) params: Option<Option<SearchParams>>,
16    /// Return points with scores better than this threshold.
17    pub(crate) score_threshold: Option<Option<f32>>,
18    /// Max number of points. Default is 10
19    pub(crate) limit: Option<Option<u64>>,
20    /// The location to use for IDs lookup, if not specified - use the current collection and the 'using' vector
21    pub(crate) lookup_from: Option<Option<LookupLocation>>,
22}
23
24impl PrefetchQueryBuilder {
25    /// Sub-requests to perform first. If present, the query will be performed on the results of the prefetches.
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    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    /// Define which vector to use for querying. If missing, the default vector is is used.
38    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    /// Filter conditions - return only those points that satisfy the specified conditions.
44    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    /// Search params for when there is no prefetch.
50    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    /// Return points with scores better than this threshold.
56    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    /// Max number of points. Default is 10
62    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    /// The location to use for IDs lookup, if not specified - use the current collection and the 'using' vector
68    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    /// Create an empty builder, with all fields set to `None` or `PhantomData`.
87    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    /// Builds the desired type. Can often be omitted.
114    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}