2021-09-27 19:12:02 +08:00
# Segcore Search Design
2021-10-26 14:22:40 +08:00
2021-09-16 23:37:49 +08:00
init: 7.23.2021, by [FluorineDog ](https://github.com/FluorineDog )
2022-02-11 09:31:47 +08:00
update: 2.10.2022, by [zhuwenxing ](https://github.com/zhuwenxing )
2021-09-16 23:37:49 +08:00
## Search
2021-10-26 14:22:40 +08:00
2021-12-21 11:11:02 +08:00
Search now supports two modes: json DSL mode and Boolean Expr mode. We will talk about the latter one in detail because the former has been deprecated and is only used in tests.
2021-09-16 23:37:49 +08:00
2021-09-27 19:12:02 +08:00
The execution mode of Boolean Expr works as follows:
2021-10-26 14:22:40 +08:00
2021-12-20 19:35:31 +08:00
1. client packs search expr, topk, and query vector into proto and sends to Proxy node.
2021-12-29 11:28:47 +08:00
2. Proxy Node unmarshals the proto, parses it to logical plan, makes a static check, and generates protobuf IR.
2021-12-15 09:27:10 +08:00
3. Query Node unmarshals the plan, generates an executable plan AST, and queries in the segcore.
2021-09-16 23:37:49 +08:00
2022-02-11 09:31:47 +08:00
See details of expression usage at [Boolean Expression Rules ](https://milvus.io/docs/v2.0.0/boolean.md )
2021-09-16 23:37:49 +08:00
2021-09-27 19:12:02 +08:00
## Segcore Search Process
2021-10-26 14:22:40 +08:00
2021-12-21 19:23:03 +08:00
After obtaining the AST, the execution engine uses the visitor mode to explain and executes the whole AST tree:
2021-09-16 23:37:49 +08:00
2021-12-15 09:27:10 +08:00
1. Each node includes two steps, a mandatory vector search and an optional predicate.
2021-10-26 14:22:40 +08:00
2021-12-10 09:57:25 +08:00
1. If Predicate exists, execute predicate expression stage to generate bitset as the vector search bitmask.
2022-01-10 09:47:36 +08:00
2. If Predicate does not exist, the vector search bitmask will be empty.
2021-10-26 14:22:40 +08:00
3. Bitmask will be used to mark filtered out / deleted entities in the vector execution engine.
2021-09-27 19:12:02 +08:00
2021-12-28 10:38:07 +08:00
2. Currently, Milvus supports the following node on the AST, visitor mode is used to interpret and execute from top to bottom and generate the final bitmask.
2021-10-26 14:22:40 +08:00
1. LogicalUnaryExpr: not expression
2. LogicalBinaryExpr: and or expression
3. TermExpr: in expression `A in [1, 2, 3]`
4. CompareExpr: compare expression `A > 1` `B <= 1`
2021-09-27 19:12:02 +08:00
2021-12-22 14:15:49 +08:00
3. TermExpr and CompareExpr are leaf nodes of execution.