qdrant_client/
expressions.rs1use crate::qdrant::*;
7
8impl Expression {
9 pub fn constant(value: f32) -> Self {
11 Self {
12 variant: Some(expression::Variant::Constant(value)),
13 }
14 }
15
16 pub fn variable<S: Into<String>>(name: S) -> Self {
18 Self {
19 variant: Some(expression::Variant::Variable(name.into())),
20 }
21 }
22
23 pub fn score() -> Self {
25 Self {
26 variant: Some(expression::Variant::Variable("$score".to_string())),
27 }
28 }
29
30 pub fn score_idx(idx: usize) -> Self {
32 Self {
33 variant: Some(expression::Variant::Variable(format!("$score[{idx}]"))),
34 }
35 }
36
37 pub fn condition<C: Into<Condition>>(condition: C) -> Self {
39 Self {
40 variant: Some(expression::Variant::Condition(condition.into())),
41 }
42 }
43
44 pub fn geo_distance<G: Into<GeoDistance>>(geo_distance: G) -> Self {
46 Self {
47 variant: Some(expression::Variant::GeoDistance(geo_distance.into())),
48 }
49 }
50
51 pub fn datetime<S: Into<String>>(datetime: S) -> Self {
53 Self {
54 variant: Some(expression::Variant::Datetime(datetime.into())),
55 }
56 }
57
58 pub fn datetime_key<S: Into<String>>(key: S) -> Self {
60 Self {
61 variant: Some(expression::Variant::DatetimeKey(key.into())),
62 }
63 }
64
65 pub fn mult<M: Into<MultExpression>>(mult: M) -> Self {
67 Self {
68 variant: Some(expression::Variant::Mult(mult.into())),
69 }
70 }
71
72 pub fn sum<S: Into<SumExpression>>(sum: S) -> Self {
74 Self {
75 variant: Some(expression::Variant::Sum(sum.into())),
76 }
77 }
78
79 pub fn div<D: Into<DivExpression>>(div: D) -> Self {
81 Self {
82 variant: Some(expression::Variant::Div(Box::new(div.into()))),
83 }
84 }
85
86 pub fn neg<E: Into<Expression>>(expr: E) -> Self {
88 Self {
89 variant: Some(expression::Variant::Neg(Box::new(expr.into()))),
90 }
91 }
92
93 pub fn abs<E: Into<Expression>>(expr: E) -> Self {
95 Self {
96 variant: Some(expression::Variant::Abs(Box::new(expr.into()))),
97 }
98 }
99
100 pub fn sqrt<E: Into<Expression>>(expr: E) -> Self {
102 Self {
103 variant: Some(expression::Variant::Sqrt(Box::new(expr.into()))),
104 }
105 }
106
107 pub fn pow<P: Into<PowExpression>>(pow: P) -> Self {
109 Self {
110 variant: Some(expression::Variant::Pow(Box::new(pow.into()))),
111 }
112 }
113
114 pub fn exp<E: Into<Expression>>(expr: E) -> Self {
116 Self {
117 variant: Some(expression::Variant::Exp(Box::new(expr.into()))),
118 }
119 }
120
121 pub fn log10<E: Into<Expression>>(expr: E) -> Self {
123 Self {
124 variant: Some(expression::Variant::Log10(Box::new(expr.into()))),
125 }
126 }
127
128 pub fn ln<E: Into<Expression>>(expr: E) -> Self {
130 Self {
131 variant: Some(expression::Variant::Ln(Box::new(expr.into()))),
132 }
133 }
134
135 pub fn geo_distance_with<G: Into<GeoPoint>, S: Into<String>>(origin: G, to: S) -> Self {
137 let geo_distance = GeoDistance {
138 origin: Some(origin.into()),
139 to: to.into(),
140 };
141 Self {
142 variant: Some(expression::Variant::GeoDistance(geo_distance)),
143 }
144 }
145
146 pub fn exp_decay<D: Into<DecayParamsExpression>>(decay: D) -> Self {
148 Self {
149 variant: Some(expression::Variant::ExpDecay(Box::new(decay.into()))),
150 }
151 }
152
153 pub fn gauss_decay<D: Into<DecayParamsExpression>>(decay: D) -> Self {
155 Self {
156 variant: Some(expression::Variant::GaussDecay(Box::new(decay.into()))),
157 }
158 }
159
160 pub fn lin_decay<D: Into<DecayParamsExpression>>(decay: D) -> Self {
162 Self {
163 variant: Some(expression::Variant::LinDecay(Box::new(decay.into()))),
164 }
165 }
166
167 pub fn acosh<E: Into<Expression>>(expr: E) -> Self {
169 Self {
170 variant: Some(expression::Variant::Acosh(Box::new(expr.into()))),
171 }
172 }
173
174 pub fn max<M: Into<MaxExpression>>(max: M) -> Self {
176 Self {
177 variant: Some(expression::Variant::Max(max.into())),
178 }
179 }
180
181 pub fn min<M: Into<MinExpression>>(min: M) -> Self {
183 Self {
184 variant: Some(expression::Variant::Min(min.into())),
185 }
186 }
187
188 pub fn mult_with<E: Into<Expression>, I: IntoIterator<Item = E>>(expressions: I) -> Self {
190 let exprs: Vec<Expression> = expressions.into_iter().map(|e| e.into()).collect();
191 Self::mult(MultExpression { mult: exprs })
192 }
193
194 pub fn sum_with<E: Into<Expression>, I: IntoIterator<Item = E>>(expressions: I) -> Self {
196 let exprs: Vec<Expression> = expressions.into_iter().map(|e| e.into()).collect();
197 Self::sum(SumExpression { sum: exprs })
198 }
199
200 pub fn max_with<E: Into<Expression>, I: IntoIterator<Item = E>>(expressions: I) -> Self {
202 let exprs: Vec<Expression> = expressions.into_iter().map(|e| e.into()).collect();
203 Self::max(MaxExpression { max: exprs })
204 }
205
206 pub fn min_with<E: Into<Expression>, I: IntoIterator<Item = E>>(expressions: I) -> Self {
208 let exprs: Vec<Expression> = expressions.into_iter().map(|e| e.into()).collect();
209 Self::min(MinExpression { min: exprs })
210 }
211
212 pub fn div_with<L: Into<Expression>, R: Into<Expression>>(
214 left: L,
215 right: R,
216 by_zero_default: Option<f32>,
217 ) -> Self {
218 Self::div(DivExpression {
219 left: Some(Box::new(left.into())),
220 right: Some(Box::new(right.into())),
221 by_zero_default,
222 })
223 }
224
225 pub fn pow_with<B: Into<Expression>, E: Into<Expression>>(base: B, exponent: E) -> Self {
227 Self::pow(PowExpression {
228 base: Some(Box::new(base.into())),
229 exponent: Some(Box::new(exponent.into())),
230 })
231 }
232}
233
234impl From<String> for Expression {
235 fn from(value: String) -> Self {
236 Self::variable(value)
237 }
238}
239
240impl From<f32> for Expression {
241 fn from(value: f32) -> Self {
242 Self::constant(value)
243 }
244}