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 操作常量 前端:无 仓库:无
This commit is contained in:
@@ -210,6 +210,78 @@ func (r *ItemRepo) UpdateVectorStateByID(
|
||||
}).Error
|
||||
}
|
||||
|
||||
// FindActiveByHash 按用户和内容哈希精确查找活跃记忆。
|
||||
//
|
||||
// 用途:
|
||||
// 1. 决策层 Step 1 的 Hash 精确命中检查;
|
||||
// 2. 利用 idx_memory_items_user_type_hash 联合索引,避免全表扫描;
|
||||
// 3. 只返回 status=active 的记录,软删除记录不参与去重。
|
||||
func (r *ItemRepo) FindActiveByHash(ctx context.Context, userID int, contentHash string) ([]model.MemoryItem, error) {
|
||||
if r == nil || r.db == nil {
|
||||
return nil, errors.New("memory item repo is nil")
|
||||
}
|
||||
if userID <= 0 || strings.TrimSpace(contentHash) == "" {
|
||||
return nil, errors.New("memory item find by hash params is invalid")
|
||||
}
|
||||
|
||||
var items []model.MemoryItem
|
||||
err := r.db.WithContext(ctx).
|
||||
Where("user_id = ? AND content_hash = ? AND status = ?", userID, contentHash, model.MemoryItemStatusActive).
|
||||
Find(&items).Error
|
||||
return items, err
|
||||
}
|
||||
|
||||
// UpdateContentByID 更新指定记忆的内容相关字段。
|
||||
//
|
||||
// 步骤化说明:
|
||||
// 1. 只改 title/content/normalized_content/content_hash/confidence/importance 六个字段;
|
||||
// 2. 不改 status/user_id/memory_type 等身份字段,保证更新操作不改变记忆归属;
|
||||
// 3. updated_at 由 GORM AutoUpdateTime 自动维护。
|
||||
func (r *ItemRepo) UpdateContentByID(ctx context.Context, memoryID int64, fields memorymodel.UpdateContentFields) error {
|
||||
if r == nil || r.db == nil {
|
||||
return errors.New("memory item repo is nil")
|
||||
}
|
||||
if memoryID <= 0 {
|
||||
return errors.New("memory item update content id is invalid")
|
||||
}
|
||||
|
||||
return r.db.WithContext(ctx).
|
||||
Model(&model.MemoryItem{}).
|
||||
Where("id = ?", memoryID).
|
||||
Updates(map[string]any{
|
||||
"title": fields.Title,
|
||||
"content": fields.Content,
|
||||
"normalized_content": fields.NormalizedContent,
|
||||
"content_hash": fields.ContentHash,
|
||||
"confidence": fields.Confidence,
|
||||
"importance": fields.Importance,
|
||||
}).Error
|
||||
}
|
||||
|
||||
// SoftDeleteByID 软删除指定用户的某条记忆。
|
||||
//
|
||||
// 说明:
|
||||
// 1. 复用 UpdateStatusByIDAt 的逻辑模式,把 status 改为 deleted;
|
||||
// 2. 同时把 vector_status 重置为 pending,确保向量侧也能感知删除;
|
||||
// 3. 必须带 user_id 条件,避免跨用户误删。
|
||||
func (r *ItemRepo) SoftDeleteByID(ctx context.Context, userID int, memoryID int64) error {
|
||||
if r == nil || r.db == nil {
|
||||
return errors.New("memory item repo is nil")
|
||||
}
|
||||
if userID <= 0 || memoryID <= 0 {
|
||||
return errors.New("memory item soft delete params is invalid")
|
||||
}
|
||||
|
||||
return r.db.WithContext(ctx).
|
||||
Model(&model.MemoryItem{}).
|
||||
Where("id = ? AND user_id = ?", memoryID, userID).
|
||||
Updates(map[string]any{
|
||||
"status": model.MemoryItemStatusDeleted,
|
||||
"vector_status": "pending",
|
||||
"updated_at": time.Now(),
|
||||
}).Error
|
||||
}
|
||||
|
||||
func applyScopedEquality(db *gorm.DB, column, value string, includeGlobal bool) *gorm.DB {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
|
||||
Reference in New Issue
Block a user