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 mult_with<E: Into<Expression>, I: IntoIterator<Item = E>>(expressions: I) -> Self {
169 let exprs: Vec<Expression> = expressions.into_iter().map(|e| e.into()).collect();
170 Self::mult(MultExpression { mult: exprs })
171 }
172
173 pub fn sum_with<E: Into<Expression>, I: IntoIterator<Item = E>>(expressions: I) -> Self {
175 let exprs: Vec<Expression> = expressions.into_iter().map(|e| e.into()).collect();
176 Self::sum(SumExpression { sum: exprs })
177 }
178
179 pub fn div_with<L: Into<Expression>, R: Into<Expression>>(
181 left: L,
182 right: R,
183 by_zero_default: Option<f32>,
184 ) -> Self {
185 Self::div(DivExpression {
186 left: Some(Box::new(left.into())),
187 right: Some(Box::new(right.into())),
188 by_zero_default,
189 })
190 }
191
192 pub fn pow_with<B: Into<Expression>, E: Into<Expression>>(base: B, exponent: E) -> Self {
194 Self::pow(PowExpression {
195 base: Some(Box::new(base.into())),
196 exponent: Some(Box::new(exponent.into())),
197 })
198 }
199}
200
201impl From<String> for Expression {
202 fn from(value: String) -> Self {
203 Self::variable(value)
204 }
205}
206
207impl From<f32> for Expression {
208 fn from(value: f32) -> Self {
209 Self::constant(value)
210 }
211}