qdrant_client/qdrant_client/builders/
query.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use crate::qdrant::{
    ContextInput, ContextInputBuilder, ContextInputPairBuilder, DiscoverInput,
    DiscoverInputBuilder, OrderBy, OrderByBuilder, PrefetchQuery, PrefetchQueryBuilder, Query,
    QueryPointGroupsBuilder, QueryPointsBuilder, RecommendInput, RecommendInputBuilder,
    VectorInput,
};

impl QueryPointsBuilder {
    pub fn add_prefetch(mut self, prefetch_query: impl Into<PrefetchQuery>) -> Self {
        self.prefetch
            .get_or_insert_with(Vec::new)
            .push(prefetch_query.into());
        self
    }
}

impl QueryPointGroupsBuilder {
    pub fn add_prefetch(mut self, prefetch_query: impl Into<PrefetchQuery>) -> Self {
        self.prefetch
            .get_or_insert_with(Vec::new)
            .push(prefetch_query.into());
        self
    }
}

impl PrefetchQueryBuilder {
    pub fn add_prefetch(mut self, prefetch_query: impl Into<PrefetchQuery>) -> Self {
        match self.prefetch {
            Some(ref mut prefetch) => prefetch.push(prefetch_query.into()),
            None => self.prefetch = Some(vec![prefetch_query.into()]),
        }
        self
    }
}

impl Query {
    pub fn new_nearest(value: impl Into<VectorInput>) -> Self {
        Self {
            variant: Some(crate::qdrant::query::Variant::Nearest(value.into())),
        }
    }

    pub fn new_recommend(value: impl Into<RecommendInput>) -> Self {
        Self {
            variant: Some(crate::qdrant::query::Variant::Recommend(value.into())),
        }
    }

    pub fn new_discover(value: impl Into<DiscoverInput>) -> Self {
        Self {
            variant: Some(crate::qdrant::query::Variant::Discover(value.into())),
        }
    }

    pub fn new_context(value: impl Into<crate::qdrant::ContextInput>) -> Self {
        Self {
            variant: Some(crate::qdrant::query::Variant::Context(value.into())),
        }
    }

    pub fn new_order_by(value: impl Into<OrderBy>) -> Self {
        Self {
            variant: Some(crate::qdrant::query::Variant::OrderBy(value.into())),
        }
    }

    pub fn new_fusion(value: crate::qdrant::Fusion) -> Self {
        Self {
            variant: Some(crate::qdrant::query::Variant::Fusion(value.into())),
        }
    }

    pub fn new_sample(value: crate::qdrant::Sample) -> Self {
        Self {
            variant: Some(crate::qdrant::query::Variant::Sample(value.into())),
        }
    }
}

impl RecommendInputBuilder {
    pub fn add_positive(mut self, value: impl Into<VectorInput>) -> Self {
        match self.positive {
            Some(ref mut positive) => positive.push(value.into()),
            None => self.positive = Some(vec![value.into()]),
        }
        self
    }

    pub fn add_negative(mut self, value: impl Into<VectorInput>) -> Self {
        match self.negative {
            Some(ref mut negative) => negative.push(value.into()),
            None => self.negative = Some(vec![value.into()]),
        }
        self
    }
}

impl DiscoverInputBuilder {
    pub fn new(target: impl Into<VectorInput>, context: impl Into<ContextInput>) -> Self {
        let builder = Self::empty();
        builder.target(target).context(context)
    }
}

impl ContextInputPairBuilder {
    pub fn new(positive: impl Into<VectorInput>, negative: impl Into<VectorInput>) -> Self {
        ContextInputPairBuilder::empty()
            .positive(positive)
            .negative(negative)
    }
}

impl ContextInputBuilder {
    pub fn add_pair(
        mut self,
        positive: impl Into<VectorInput>,
        negative: impl Into<VectorInput>,
    ) -> Self {
        match self.pairs {
            Some(ref mut pairs) => {
                pairs.push(ContextInputPairBuilder::new(positive, negative).build())
            }
            None => {
                self.pairs = Some(vec![
                    ContextInputPairBuilder::new(positive, negative).build()
                ])
            }
        }
        self
    }
}

impl OrderByBuilder {
    pub fn new(key: impl Into<String>) -> Self {
        let builder = Self::empty();
        builder.key(key.into())
    }
}