Why: I2 layering - between rules and the L2 classifier there is now a deterministic host-scored semantic layer (rules then semantic then model), and fallback can be rescued by a validated command generator instead of going straight to the default channel. Evidence: go vet clean; full suite ok, including ten new tests (rerank resolve/below-threshold/tie/error-then-L2, generator valid/invalid/error, catalog top-k). Impact: IntentSpec gains Examples; Options gains Semantic (with threshold), Generator; ambiguous candidates rerank through host scores before L2; fallback validates generated commands (action/slots/kind fail-closed) and synthesizes Top with slots; generated commands are no longer overwritten by deriveCommands; CatalogTopK by priority. Refs: Documents proposal 2026-10-07-agent-stack-n1q1i1-plans.md I2
14 lines
648 B
Go
14 lines
648 B
Go
package intent
|
|
|
|
import "context"
|
|
|
|
// SemanticScorer 语义相似度端口(I2 分层与评测):宿主注入向量模型,
|
|
// 核心不做 I/O——打分由宿主计算,库只消费分数。
|
|
// 只在规则裁决为 Ambiguous 时被调用(规则→语义→模型分层的中位);
|
|
// 实现应幂等且无副作用(同一输入与示例集应得到同一分数)。
|
|
type SemanticScorer interface {
|
|
// Score 返回 input 与 examples 的最高相似度,取值 [0,1]。
|
|
// 实现返回错误时识别保持 Ambiguous,不会使 Recognize 失败。
|
|
Score(ctx context.Context, input string, examples []string) (float64, error)
|
|
}
|