Predicate Expressions

A predicate is an expression outputs a boolean value. Milvus conducts scalar filtering by searching with predicates. A predicate expression, when evaluated, returns either TRUE or FALSE. View Python SDK API Reference for instruction on using predicate expressions.

Predicate Syntax

An expression can be either NONE or a logical expression.

Expr := LogicalExpr | NIL

Types of predicate operators

Operator Description Examples
Relational operators Relational operators use symbols to check for equality, inequality, or relative order between two expressions. Relational operators include >, >=, <, <=, ==, and !=.
  • A > 1
  • B >= 2
  • C < 3
  • D <= 4
  • E == 5
  • F != 6
Logical operators Logical operators perform a comparison between two expressions. The supported logical operators are: AND, && OR, , and NOT.
IN operator The IN condition is satisfied when the expression to the left of the keyword IN is included in the list of items.
  • FloatCol in [1.0, 2, 3.0]
  • Int64Col in [1, 2, 3]

Relational Operators

Relational operators are symbols that compare one expression with another expression. Data types between left and right side of the operator must match. The supported operators are:

  • equals(==)
  • not equals(!=)
  • is greater than (>)
  • is greater than or equal to (>=)
  • is less than (<)
  • is less than or equal to (<=)

Logical Operators

There are two types of logical operators, unary and binray. UnaryLogicalOp acts on only one logical expression, while BinaryLogicalOp compares one logic expression with another logic expression. The supported operators are:

  • NOT !
  • AND &&
  • OR ||


LogicalExpr := LogicalExpr BinaryLogicalOp LogicalExpr
  | UnaryLogicalOp LogicalExpr
  | "(" LogicalExpr ")"
  | RelationalExpr
  | InExpr

IN Operator

The IN operator matches values in a field to any of the items in the constant array, which must be a comma-separated list of items. Data types between left and right side of the operator must match.


InExpr := IDENTIFIER "in" ConstantArray
ConstantArray := "[" Constant+, "]"

Order of Evaluation

The order in which the Milvus evaluates predicate expressions follows the table below:

  1. Expressions inside parentheses
  2. Not operators
  3. Or operators
  4. And Operators

Learn more about Boolean Expression Rules.

Is this page helpful?
Scored Successfully!