Expression

@Serializable(with = ExpressionSerializer::class)
sealed interface Expression

An arithmetic expression over a point's score and payload, evaluated by Qdrant to rerank the candidates a Prefetch produced.

This is the "boost by business rules" layer: multiply the vector score by a popularity field, add a bonus for points matching a condition, decay by recency or by distance. It runs on the server, over candidates that have already been narrowed, which is what makes it cheap enough to be worth doing.

// relevance, boosted for in-stock items and decayed by how far away the seller is
qdrant.search("products") {
prefetch { query(queryVector); limit = 100 }
formula(
Expression.sum(
Expression.score,
Expression.mult(Expression.of(0.5), Expression.condition(filter { must { "in_stock" eq true } })),
Expression.expDecay(Expression.geoDistance(origin = here, to = "seller_location"), scale = 5_000.0),
),
)
limit = 10
}

Request-only: Qdrant never returns an expression, so this serializes but does not deserialize.

Inheritors

Types

Link copied to clipboard
data class Abs(val operand: Expression) : Expression

Absolute value.

Link copied to clipboard
object Companion
Link copied to clipboard
data class Condition(val condition: Condition) : Expression

A filter condition as a number: 1.0 when the point matches, 0.0 when it does not.

Link copied to clipboard
data class Datetime(val value: String) : Expression

An RFC 3339 datetime as a Unix timestamp.

Link copied to clipboard
data class DatetimeKey(val key: String) : Expression

A payload key holding a datetime, as a Unix timestamp.

Link copied to clipboard
data class Div(val left: Expression, val right: Expression, val byZeroDefault: Double? = null) : Expression

left divided by right. byZeroDefault is what the division evaluates to when right is zero; without it Qdrant fails the query rather than inventing a number.

Link copied to clipboard
data class Exp(val operand: Expression) : Expression

Natural exponential.

Link copied to clipboard
data class ExpDecay(val params: DecayParams) : Expression

Exponential decay of params.

Link copied to clipboard
data class GaussDecay(val params: DecayParams) : Expression

Gaussian decay of params.

Link copied to clipboard
data class GeoDistance(val origin: GeoPoint, val to: String) : Expression

Distance in metres from origin to the geo point in the payload field to.

Link copied to clipboard
data class LinDecay(val params: DecayParams) : Expression

Linear decay of params.

Link copied to clipboard
data class Ln(val operand: Expression) : Expression

Natural logarithm.

Link copied to clipboard
data class Log10(val operand: Expression) : Expression

Base-10 logarithm.

Link copied to clipboard
data class Mult(val operands: List<Expression>) : Expression

The product of every operand.

Link copied to clipboard
data class Neg(val operand: Expression) : Expression

Arithmetic negation.

Link copied to clipboard
data class Pow(val base: Expression, val exponent: Expression) : Expression

base raised to exponent.

Link copied to clipboard
data class Sqrt(val operand: Expression) : Expression

Square root.

Link copied to clipboard
data class Sum(val operands: List<Expression>) : Expression

The sum of every operand.

Link copied to clipboard
data class Value(val value: Double) : Expression

A constant.

Link copied to clipboard
data class Variable(val name: String) : Expression

A payload key, or one of Qdrant's variables. $score is the vector score of the candidate; a plain key reads that payload field, and a missing field evaluates to the formula's default for that key (see defaults) or fails the query.