Files
weichenandCursor fac5704303 feat(workflowscope): score document hits by workflow relation weight
Keep WORKFLOW_SCOPE_MODE=strict as the default so cross-workflow mentions stay blocked until weighted mode is turned on.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-21 09:07:50 +00:00

56 lines
1.5 KiB
Go

package workflowscope
import "chat-agent-system/internal/workflowdef"
const (
// WeightSame 当前激活工作流。
WeightSame = 1.0
// WeightUnknown 文档没有工作流归属(存量行)。
WeightUnknown = 0.80
// WeightAdjacent 同产品域且目录序相邻(|Δorder| == 10)。
WeightAdjacent = 0.60
// WeightSameDomain 同产品域但目录序更远。
WeightSameDomain = 0.50
// WeightCrossDomain 医疗四与软件两之间。
WeightCrossDomain = 0.35
)
// RelationWeight 按「当前激活工作流 ↔ 文档所属工作流」给出关系权重。
// active 为空时不惩罚(调用方应不过滤)。owner 为空视为归属未知。
func RelationWeight(active, owner string) float64 {
if active == "" {
return WeightSame
}
if owner == "" {
return WeightUnknown
}
if active == owner {
return WeightSame
}
if !sameProductDomain(active, owner) {
return WeightCrossDomain
}
activeOrder := workflowdef.OfficialCatalogOrder(active)
ownerOrder := workflowdef.OfficialCatalogOrder(owner)
if activeOrder != 9999 && ownerOrder != 9999 && absInt(activeOrder-ownerOrder) == 10 {
return WeightAdjacent
}
return WeightSameDomain
}
func sameProductDomain(a, b string) bool {
aMed := workflowdef.IsMedicalWorkflowKey(a)
bMed := workflowdef.IsMedicalWorkflowKey(b)
if aMed || bMed {
return aMed && bMed
}
return workflowdef.IsSoftwareWorkflowKey(a) && workflowdef.IsSoftwareWorkflowKey(b)
}
func absInt(v int) int {
if v < 0 {
return -v
}
return v
}