fix distill quality gate short-fact rejection + register conflicts into active
This commit is contained in:
@@ -23,6 +23,28 @@ import (
|
||||
"github.com/xiaoxue/memoryweave/internal/redact"
|
||||
)
|
||||
|
||||
// isSoulfulShortFact 判断是否为<20 字的人侧结构化短事实(放行,非碎片)
|
||||
//
|
||||
// 画像/心迹/牵挂/偏好/习惯/目标类由 daemon 侧固化前缀写入(如"画像规则:"、"牵挂:"、
|
||||
// "偏好:"、"习惯:"、"目标:"、"行为规则:"),天然短但 100% 是用户事实。
|
||||
// 仅放行前缀已知且内容非纯噪声的短事实;否则仍按碎片拒绝。
|
||||
func isSoulfulShortFact(s string) bool {
|
||||
shortFactPrefixes := []string{
|
||||
"画像规则", "画像:", "心迹:", "牵挂:", "偏好:", "习惯:", "目标:",
|
||||
"行为规则", "沟通风格", "当前目标", "待处理", "待拍板",
|
||||
}
|
||||
for _, p := range shortFactPrefixes {
|
||||
if strings.HasPrefix(s, p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// 带"牧尘/用户/小唯"主语的短陈述也是真实用户事实
|
||||
if hasStatementSubject(s) && !isStatusReportLike(s) && !isPureQuestion(s) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsQualityFact 判断蒸馏事实是否有入库价值(严格质量门槛)
|
||||
//
|
||||
// 2026-09-10 P0 追加:先做密钥脱敏再判定。含凭证的事实不再把原文带进图谱
|
||||
@@ -41,8 +63,13 @@ func IsQualityFact(fact string) bool {
|
||||
return false
|
||||
}
|
||||
runeLen := utf8.RuneCountInString(s)
|
||||
// <20字 → 拒绝(碎片)
|
||||
// 人侧结构化短事实:画像/心迹/牵挂/偏好/习惯/目标<20 字也放行(这类
|
||||
// 天然短、但 100% 是真实用户事实;"画像规则:" 前缀是 daemon 侧固化的
|
||||
// 结构化标签,不是碎片噪声)
|
||||
if runeLen < 20 {
|
||||
if isSoulfulShortFact(s) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
// 20-50字 → 需含实体或动词短语
|
||||
|
||||
@@ -3,6 +3,7 @@ package governance
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -53,6 +54,7 @@ func (cd *ConflictDetector) Scan(newContent string, newEntities []string, existi
|
||||
// 检测事实冲突:内容语义矛盾
|
||||
if IsContradiction(newContent, existingContent) {
|
||||
conflicts = append(conflicts, &Conflict{
|
||||
ID: "cft_" + strconv.FormatInt(time.Now().UnixNano(), 10) + "_" + strconv.Itoa(len(conflicts)),
|
||||
Type: ConflictFact,
|
||||
Entity: e1,
|
||||
Description: "事实冲突:新内容与已有记录矛盾",
|
||||
@@ -66,6 +68,14 @@ func (cd *ConflictDetector) Scan(newContent string, newEntities []string, existi
|
||||
}
|
||||
}
|
||||
|
||||
if len(conflicts) > 0 {
|
||||
cd.mu.Lock()
|
||||
for _, c := range conflicts {
|
||||
cd.active[c.ID] = c
|
||||
}
|
||||
cd.mu.Unlock()
|
||||
}
|
||||
|
||||
return conflicts
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user