Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildInputMap ¶
func BuildInputMap(it *core.Item, rctx *core.RecommendContext) map[string]interface{}
BuildInputMap 构建 CEL 表达式的输入数据(item / label / rctx 三个顶层变量)。
func ConvertToCELSyntax ¶
提供辅助函数来转换旧语法到 CEL 语法 例如:label.recall_source contains "hot" -> label.recall_source.contains("hot")
Types ¶
type CompiledExpr ¶
type CompiledExpr struct {
// contains filtered or unexported fields
}
CompiledExpr 预编译的 CEL 表达式,可对不同 item/rctx 重复求值。 cel.Program 本身是线程安全的,CompiledExpr 也可并发调用 Eval。
func Compile ¶
func Compile(expr string) (*CompiledExpr, error)
Compile 预编译 CEL 表达式。表达式为空时返回 (nil, nil)。
func (*CompiledExpr) Eval ¶
func (c *CompiledExpr) Eval(item *core.Item, rctx *core.RecommendContext) (bool, error)
Eval 对预编译表达式求值,返回布尔结果。
type Eval ¶
type Eval struct {
// contains filtered or unexported fields
}
Eval 是 Label DSL 解释器,使用 CEL (Common Expression Language) 实现。 CEL 是 Google 开发的表达式语言,具有类型安全、高性能、线程安全等特性。
表达式语法(CEL 标准语法):
- 基础:label.recall_source == "hot" / label.rank_model != "lr"
- 数值:item.score > 0.7 / item.score >= 0.5
- 逻辑:label.category == "A" && item.score > 0.8
- 存在性:label.recall_source != null
- 包含:label.recall_source.contains("hot") 或 "hot" in label.recall_source
示例:
- `label.recall_source.contains("hot")` → 召回来源包含 "hot"
- `label.rank_model == "lr" && item.score > 0.7` → LR 模型且分数 > 0.7
- `label.category != null && label.category == "A"` → 存在 category 且为 "A"
func NewEval ¶
func NewEval(item *core.Item, rctx *core.RecommendContext) *Eval
NewEval 创建一个新的 DSL 解释器。 表达式会被编译并缓存,可以多次调用 Evaluate 方法。
func (*Eval) Evaluate ¶
Evaluate 解析并执行 DSL 表达式,返回布尔结果。 表达式使用 CEL (Common Expression Language) 语法。
支持的语法:
- label.recall_source == "hot"
- item.score > 0.7
- label.category == "A" && item.score > 0.8
- label.recall_source != null (检查是否存在)
- label.recall_source.contains("hot") 或 "hot" in label.recall_source
注意:has(label.key) 可以用 label.key != null 替代
Click to show internal directories.
Click to hide internal directories.