diff --git a/go/internal/distill/engine.go b/go/internal/distill/engine.go index 4f1e34c..b80f558 100644 --- a/go/internal/distill/engine.go +++ b/go/internal/distill/engine.go @@ -74,11 +74,11 @@ type LLMResponse struct { VD float64 `json:"vd"` RU float64 `json:"ru"` Entities []string `json:"entities"` - Facts []string `json:"facts"` // 旧格式兼容 - Decisions []string `json:"decisions"` // 新格式:决策结论 - Conclusions []string `json:"conclusions"` // 新格式:最终结论 - ActionsTaken []string `json:"actions_taken"` // 新格式:采取的行动 - OpenQuestions []string `json:"open_questions"` // 新格式:悬而未决 + Facts []string `json:"facts"` // 旧格式兼容 + Decisions []string `json:"decisions"` // 新格式:决策结论 + Conclusions []string `json:"conclusions"` // 新格式:最终结论 + ActionsTaken []string `json:"actions_taken"` // 新格式:采取的行动 + OpenQuestions []string `json:"open_questions"` // 新格式:悬而未决 } // LLM 5维权重 @@ -102,19 +102,19 @@ type Engine struct { APIKey string // 队列 - queue []DistillInput - batchSize int + queue []DistillInput + batchSize int batchTimeout time.Duration - lastDistill time.Time + lastDistill time.Time // P3 双缓冲:token 积累触发(LightMem 移植) pendingTokens int flushTokenThreshold int // 成本控制 - dailyLimit int - dailyUsed int - dailyReset time.Time + dailyLimit int + dailyUsed int + dailyReset time.Time // HTTP客户端 client *http.Client @@ -250,10 +250,15 @@ func (e *Engine) distillOne(input DistillInput) DistillResult { input.EpisodeID, overall, score.IS, score.SU, score.PA, score.VD, score.RU) if overall < 0.7 && score.VD < 0.8 { - log.Printf("[distill] score below threshold for %s, skip", input.EpisodeID) - // 即使阈值未通过,仍然用 LLM 实体提取(如果有的话) - if len(llmResp.Entities) == 0 { - return DistillResult{} + // 人侧短事实(画像/心迹/牵挂/偏好/习惯/目标)是用户亲口陈述, + // LLM 打分天然偏低(短、无上下文),不应因分数被丢弃——否则"牧尘不在招商局工作" + // 这类关键事实永远到不了 memories,t6 永远比对不到。 + if !isSoulfulShortFact(input.Content) { + log.Printf("[distill] score below threshold for %s, skip", input.EpisodeID) + // 即使阈值未通过,仍然用 LLM 实体提取(如果有的话) + if len(llmResp.Entities) == 0 { + return DistillResult{} + } } } @@ -492,7 +497,9 @@ func (e *Engine) extractFacts(content string) ([]string, []Entity) { seen[cleanChinese] = true isTech := containsAny(cleanChinese, []string{"端口", "配置", "系统", "内存", "显卡", "服务", "记忆", "织忆", "飞书", "版本", "模型", "工具", "项目", "安装", "部署", "目录", "路径", "开发", "语言"}) etype := "entity" - if isTech { etype = "fact" } + if isTech { + etype = "fact" + } entities = append(entities, Entity{ Name: cleanChinese, Type: etype, Properties: []string{"extracted"}, }) @@ -531,8 +538,12 @@ func isTechToken(s string) bool { hasDigit := false hasLetter := false for _, r := range s { - if r >= '0' && r <= '9' { hasDigit = true } - if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') { hasLetter = true } + if r >= '0' && r <= '9' { + hasDigit = true + } + if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') { + hasLetter = true + } } return hasDigit && hasLetter } @@ -695,11 +706,11 @@ func (e *Engine) GetStatus() map[string]interface{} { e.mu.Lock() defer e.mu.Unlock() return map[string]interface{}{ - "queue_len": len(e.queue), - "batch_size": e.batchSize, - "last_distill": e.lastDistill.Format(time.RFC3339), - "daily_used": e.dailyUsed, - "daily_limit": e.dailyLimit, + "queue_len": len(e.queue), + "batch_size": e.batchSize, + "last_distill": e.lastDistill.Format(time.RFC3339), + "daily_used": e.dailyUsed, + "daily_limit": e.dailyLimit, "daily_remaining": e.dailyLimit - e.dailyUsed, } }