use crate::qdrant::*;
impl Expression {
pub fn constant(value: f32) -> Self {
Self {
variant: Some(expression::Variant::Constant(value)),
}
}
pub fn variable<S: Into<String>>(name: S) -> Self {
Self {
variant: Some(expression::Variant::Variable(name.into())),
}
}
pub fn score() -> Self {
Self {
variant: Some(expression::Variant::Variable("$score".to_string())),
}
}
pub fn score_idx(idx: usize) -> Self {
Self {
variant: Some(expression::Variant::Variable(format!("$score[{idx}]"))),
}
}
pub fn condition<C: Into<Condition>>(condition: C) -> Self {
Self {
variant: Some(expression::Variant::Condition(condition.into())),
}
}
pub fn geo_distance<G: Into<GeoDistance>>(geo_distance: G) -> Self {
Self {
variant: Some(expression::Variant::GeoDistance(geo_distance.into())),
}
}
pub fn datetime<S: Into<String>>(datetime: S) -> Self {
Self {
variant: Some(expression::Variant::Datetime(datetime.into())),
}
}
pub fn datetime_key<S: Into<String>>(key: S) -> Self {
Self {
variant: Some(expression::Variant::DatetimeKey(key.into())),
}
}
pub fn mult<M: Into<MultExpression>>(mult: M) -> Self {
Self {
variant: Some(expression::Variant::Mult(mult.into())),
}
}
pub fn sum<S: Into<SumExpression>>(sum: S) -> Self {
Self {
variant: Some(expression::Variant::Sum(sum.into())),
}
}
pub fn div<D: Into<DivExpression>>(div: D) -> Self {
Self {
variant: Some(expression::Variant::Div(Box::new(div.into()))),
}
}
pub fn neg<E: Into<Expression>>(expr: E) -> Self {
Self {
variant: Some(expression::Variant::Neg(Box::new(expr.into()))),
}
}
pub fn abs<E: Into<Expression>>(expr: E) -> Self {
Self {
variant: Some(expression::Variant::Abs(Box::new(expr.into()))),
}
}
pub fn sqrt<E: Into<Expression>>(expr: E) -> Self {
Self {
variant: Some(expression::Variant::Sqrt(Box::new(expr.into()))),
}
}
pub fn pow<P: Into<PowExpression>>(pow: P) -> Self {
Self {
variant: Some(expression::Variant::Pow(Box::new(pow.into()))),
}
}
pub fn exp<E: Into<Expression>>(expr: E) -> Self {
Self {
variant: Some(expression::Variant::Exp(Box::new(expr.into()))),
}
}
pub fn log10<E: Into<Expression>>(expr: E) -> Self {
Self {
variant: Some(expression::Variant::Log10(Box::new(expr.into()))),
}
}
pub fn ln<E: Into<Expression>>(expr: E) -> Self {
Self {
variant: Some(expression::Variant::Ln(Box::new(expr.into()))),
}
}
pub fn geo_distance_with<G: Into<GeoPoint>, S: Into<String>>(origin: G, to: S) -> Self {
let geo_distance = GeoDistance {
origin: Some(origin.into()),
to: to.into(),
};
Self {
variant: Some(expression::Variant::GeoDistance(geo_distance)),
}
}
pub fn exp_decay<D: Into<DecayParamsExpression>>(decay: D) -> Self {
Self {
variant: Some(expression::Variant::ExpDecay(Box::new(decay.into()))),
}
}
pub fn gauss_decay<D: Into<DecayParamsExpression>>(decay: D) -> Self {
Self {
variant: Some(expression::Variant::GaussDecay(Box::new(decay.into()))),
}
}
pub fn lin_decay<D: Into<DecayParamsExpression>>(decay: D) -> Self {
Self {
variant: Some(expression::Variant::LinDecay(Box::new(decay.into()))),
}
}
pub fn mult_with<E: Into<Expression>, I: IntoIterator<Item = E>>(expressions: I) -> Self {
let exprs: Vec<Expression> = expressions.into_iter().map(|e| e.into()).collect();
Self::mult(MultExpression { mult: exprs })
}
pub fn sum_with<E: Into<Expression>, I: IntoIterator<Item = E>>(expressions: I) -> Self {
let exprs: Vec<Expression> = expressions.into_iter().map(|e| e.into()).collect();
Self::sum(SumExpression { sum: exprs })
}
pub fn div_with<L: Into<Expression>, R: Into<Expression>>(
left: L,
right: R,
by_zero_default: Option<f32>,
) -> Self {
Self::div(DivExpression {
left: Some(Box::new(left.into())),
right: Some(Box::new(right.into())),
by_zero_default,
})
}
pub fn pow_with<B: Into<Expression>, E: Into<Expression>>(base: B, exponent: E) -> Self {
Self::pow(PowExpression {
base: Some(Box::new(base.into())),
exponent: Some(Box::new(exponent.into())),
})
}
}
impl From<String> for Expression {
fn from(value: String) -> Self {
Self::variable(value)
}
}
impl From<f32> for Expression {
fn from(value: f32) -> Self {
Self::constant(value)
}
}