Files
smartmate/backend/memory/service/config_loader.go
Losita 634a9fb926 Version: 0.9.21.dev.260416
后端:
1. Memory 写入链路新增"召回→比对→汇总"去重决策层
- 新增决策流程:Runner 根据decision.enabled 配置走决策路径(语义召回候选 → Hash 精确命中 → LLM 逐对比对 → 汇总决策 → 执行 ADD/UPDATE/DELETE/NONE),默认关闭,旧路径完全保留
- 新增 LLMDecisionOrchestrator:单对关系判断编排器,输出 duplicate/update/conflict/unrelated 四种关系
- 新增 decision_flow / apply_actions:决策流程主循环与动作落地(新增、更新内容、软删除、跳过)
- 新增 aggregate_decision / decision_validate:汇总规则(按优先级判定动作)与 LLM 输出校验
- 新增 decision model:CandidateSnapshot / ComparisonResult / FinalDecision 等决策层核心类型
- ItemRepo 新增 FindActiveByHash / UpdateContentByID / SoftDeleteByID 三个决策层专用方法
- RAG Runtime / Pipeline / Service 新增 DeleteMemory 向量删除能力,MilvusStore 补充 duplicate collection 错误识别
- Runner 新增 syncVectorDeletes 处理决策层 DELETE 动作的向量清理
- config 新增 decision(enabled/candidateTopK/candidateMinScore/fallbackMode)和 write.mode 配置项,config_loader 增加默认值兜底
- 删除 HANDOFF-RAG复用后续实施计划.md 和旧 log.txt,新增 Log.txt 记录决策流程调试日志
- normalize_facts 导出 HashContent 供决策层复用,audit 新增 update 操作常量

前端:无 仓库:无
2026-04-16 12:11:58 +08:00

77 lines
2.6 KiB
Go

package service
import (
"time"
memorymodel "github.com/LoveLosita/smartflow/backend/memory/model"
"github.com/spf13/viper"
)
// LoadConfigFromViper 读取记忆模块配置并做默认值兜底。
//
// 默认策略:
// 1. temperature/top_p 使用低随机参数,提升可复现性;
// 2. Day1 先提供参数位,不强制所有参数立即生效;
// 3. 轮询与重试参数给出保守默认值,避免对主链路造成压力。
func LoadConfigFromViper() memorymodel.Config {
cfg := memorymodel.Config{
Enabled: viper.GetBool("memory.enabled"),
RAGEnabled: viper.GetBool("memory.rag.enabled"),
ExtractPrompt: viper.GetString("memory.prompt.extract"),
DecisionPrompt: viper.GetString("memory.prompt.decision"),
Threshold: viper.GetFloat64("memory.threshold"),
EnableReranker: viper.GetBool("memory.enableReranker"),
LLMTemperature: viper.GetFloat64("memory.llm.temperature"),
LLMTopP: viper.GetFloat64("memory.llm.topP"),
JobMaxRetry: viper.GetInt("memory.job.maxRetry"),
WorkerPollEvery: viper.GetDuration("memory.worker.pollEvery"),
WorkerClaimBatch: viper.GetInt("memory.worker.claimBatch"),
// 决策层配置:默认关闭,灰度开启后才会生效。
DecisionEnabled: viper.GetBool("memory.decision.enabled"),
DecisionCandidateTopK: viper.GetInt("memory.decision.candidateTopK"),
DecisionCandidateMinScore: viper.GetFloat64("memory.decision.candidateMinScore"),
DecisionFallbackMode: viper.GetString("memory.decision.fallbackMode"),
WriteMode: viper.GetString("memory.write.mode"),
}
if cfg.Threshold <= 0 {
cfg.Threshold = 0.55
}
if cfg.LLMTemperature <= 0 {
cfg.LLMTemperature = 0.1
}
if cfg.LLMTopP <= 0 {
cfg.LLMTopP = 0.2
}
if cfg.JobMaxRetry <= 0 {
cfg.JobMaxRetry = 6
}
if cfg.WorkerPollEvery <= 0 {
cfg.WorkerPollEvery = 2 * time.Second
}
if cfg.WorkerClaimBatch <= 0 {
cfg.WorkerClaimBatch = 1
}
// 决策层配置默认值兜底。
// 说明:
// 1. TopK 和 MinScore 是 Milvus 召回参数,需要保守默认值避免召回过多噪声候选;
// 2. FallbackMode 默认退回旧路径新增,保证决策流程异常时不丢数据;
// 3. WriteMode 由 DecisionEnabled 隐式决定,这里不做强制联动。
if cfg.DecisionCandidateTopK <= 0 {
cfg.DecisionCandidateTopK = 5
}
if cfg.DecisionCandidateMinScore <= 0 {
cfg.DecisionCandidateMinScore = 0.6
}
if cfg.DecisionFallbackMode == "" {
cfg.DecisionFallbackMode = "legacy_add"
}
if cfg.WriteMode == "" {
cfg.WriteMode = "legacy"
}
return cfg
}