后端: 1. 记忆系统移除 todo_hint 类型——随口记已由 Task 系统承接,todo_hint 语义重叠且无完成追踪 - 全链路清理:常量、校验、默认重要度、30 天 TTL、读取预算、LLM 抽取提示词枚举 - 总预算从四类收缩为三类(preference / constraint / fact) 2. 记忆抽取触发点从 chat-persist 移至 graph-completion——避免随口记消息被误提取为 constraint/preference - chat-persist consumer 不再自动入队 memory.extract.requested,仅负责聊天历史落库 - graph 完成后新增条件发布:检测 UsedQuickNote 标记,调用过 quick_note_create 则跳过记忆抽取 - ResetForNextRun 重置 UsedQuickNote,防止跨轮残留导致后续正常消息记忆抽取被误跳过 3. 任务类查询接口返回 items 补充数据库主键 ID(前端拖拽编排依赖此字段) 前端: 4. 排程视图新增手动编排模式——侧边栏任务块拖拽入周课表 + 悬浮删除热区 + 建议块虚线标识 - TaskClassSidebar 拖拽发起 + 预览态嵌入时间格式化(含周次/星期) - WeekPlanningBoard 外部拖入 / 内部移动 / 悬浮删除区交互 - ScheduleView 手动编排状态机(进入/退出/取消/覆盖确认)+ apply 时同步处理新增与删除
77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package service
|
|
|
|
import (
|
|
"sort"
|
|
"time"
|
|
|
|
memorymodel "github.com/LoveLosita/smartflow/backend/memory/model"
|
|
)
|
|
|
|
// RankItems 对读取结果做统一重排。
|
|
//
|
|
// 步骤化说明:
|
|
// 1. 先基于 importance / confidence / recency 构造基础分,保持和旧链路相近的排序直觉;
|
|
// 2. 再叠加“显式记忆 / 类型优先级”奖励,让 constraint 与 preference 更稳定地排在前面;
|
|
// 3. 同分按 ID 降序,保证排序在日志与测试里具备稳定性。
|
|
func RankItems(items []memorymodel.ItemDTO, now time.Time) []memorymodel.ItemDTO {
|
|
if len(items) == 0 {
|
|
return nil
|
|
}
|
|
|
|
ranked := make([]memorymodel.ItemDTO, len(items))
|
|
copy(ranked, items)
|
|
sort.SliceStable(ranked, func(i, j int) bool {
|
|
left := scoreRankedItem(ranked[i], now)
|
|
right := scoreRankedItem(ranked[j], now)
|
|
if left == right {
|
|
return ranked[i].ID > ranked[j].ID
|
|
}
|
|
return left > right
|
|
})
|
|
return ranked
|
|
}
|
|
|
|
// scoreRankedItem 计算 hybrid 读链路的统一重排分数。
|
|
//
|
|
// 说明:
|
|
// 1. 这里仍然只依赖条目自身属性,不引入 conversation_id 加分;
|
|
// 2. 原因是同对话内容本就已经存在于上下文窗口,记忆读侧应专注跨对话补充;
|
|
// 3. 类型加权仍然保留,用于确保 constraint / preference 的业务优先级稳定生效。
|
|
func scoreRankedItem(item memorymodel.ItemDTO, now time.Time) float64 {
|
|
score := 0.35*clamp01(item.Importance) + 0.3*clamp01(item.Confidence) + 0.2*recencyScoreDTO(item, now)
|
|
if item.IsExplicit {
|
|
score += 0.1
|
|
}
|
|
switch memorymodel.NormalizeMemoryType(item.MemoryType) {
|
|
case memorymodel.MemoryTypeConstraint:
|
|
score += 0.15
|
|
case memorymodel.MemoryTypePreference:
|
|
score += 0.10
|
|
}
|
|
return score
|
|
}
|
|
|
|
func recencyScoreDTO(item memorymodel.ItemDTO, now time.Time) float64 {
|
|
base := item.UpdatedAt
|
|
if base == nil {
|
|
base = item.CreatedAt
|
|
}
|
|
if base == nil || now.Before(*base) {
|
|
return 0.5
|
|
}
|
|
|
|
age := now.Sub(*base)
|
|
switch {
|
|
case age <= 24*time.Hour:
|
|
return 1
|
|
case age <= 7*24*time.Hour:
|
|
return 0.85
|
|
case age <= 30*24*time.Hour:
|
|
return 0.65
|
|
case age <= 90*24*time.Hour:
|
|
return 0.45
|
|
default:
|
|
return 0.25
|
|
}
|
|
}
|