后端: 1. Memory 管理面 API 落地(“我的记忆”增删改查 + 恢复) - 补齐 List/Get/Create/Update/Delete/Restore 的 handler、请求模型与返回视图 - 注册 `/api/v1/memory/items*` 路由并接入 MemoryHandler - 新增 memory item not found / invalid memory type / invalid memory content 三类管理面错误码 2. Memory Module / Service / Repo 扩展为“可管理 + 可治理”门面 - 新增 NewModuleWithObserve / ObserveDeps,导出 GetItem / CreateItem / UpdateItem / DeleteItem / RestoreItem / RunDedupCleanup / MemoryObserver / MemoryMetrics - 新增手动新增、修改、恢复能力;删除链路切到 SoftDeleteByID;所有管理动作统一事务内写 audit,并桥接向量同步与管理面观测 - 补齐 CreateItemFields / UpdateItemFields、单条 Create、管理侧字段更新、软删/恢复,以及 dedup 扫描/归档所需 repo 能力 - 审计操作补齐 archive / restore 3. Memory 读侧与注入侧观测补齐 - HybridRetrieve 返回 telemetry,统一记录 pinned hit / semantic hit / dedup drop / degraded / RAG fallback,并上报读取命中、去重丢弃、RAG 降级指标 - AgentService 持有 memory observer / metrics;injectMemoryContext 对读取失败、空注入、成功注入补齐结构化日志与注入计数 4. Worker / 决策 / 向量同步链路治理增强 - 召回结果显式携带 fallbackMode;hash 精确命中、rag→mysql 降级、最终动作统一写入决策观测 - 接入 vectorSyncer / observer / metrics;为 job 重试、任务成功/失败、决策分布与 fallback 补齐打点;向量 upsert/delete 统一改走公共 Syncer,并收敛 parseMemoryID 解析逻辑 5. 启动层接入 Memory 观测依赖 - 启动时创建 LoggerObserver + MetricsRegistry,并通过 NewModuleWithObserve 注入 memory 模块 前端:无 仓库:无
106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// ItemDTO 是记忆条目对外读写 DTO。
|
|
//
|
|
// 职责边界:
|
|
// 1. 面向 memory 模块内部服务层使用;
|
|
// 2. 不直接绑定 GORM 标签,避免传输结构与存储结构强耦合。
|
|
type ItemDTO struct {
|
|
ID int64
|
|
UserID int
|
|
ConversationID string
|
|
AssistantID string
|
|
RunID string
|
|
MemoryType string
|
|
Title string
|
|
Content string
|
|
ContentHash string
|
|
Confidence float64
|
|
Importance float64
|
|
SensitivityLevel int
|
|
IsExplicit bool
|
|
Status string
|
|
TTLAt *time.Time
|
|
CreatedAt *time.Time
|
|
UpdatedAt *time.Time
|
|
}
|
|
|
|
// ItemQuery 描述 memory_items 的通用查询条件。
|
|
//
|
|
// 职责边界:
|
|
// 1. 只表达 memory 仓储层需要的过滤条件;
|
|
// 2. 不直接承载注入策略、重排策略等上层业务语义;
|
|
// 3. IncludeGlobal 用于“会话级 + 全局级”混合读取场景。
|
|
type ItemQuery struct {
|
|
UserID int
|
|
ConversationID string
|
|
AssistantID string
|
|
RunID string
|
|
Statuses []string
|
|
MemoryTypes []string
|
|
IncludeGlobal bool
|
|
OnlyUnexpired bool
|
|
Limit int
|
|
Now time.Time
|
|
}
|
|
|
|
// RetrieveRequest 描述“供提示词注入前读取”所需的最小参数。
|
|
type RetrieveRequest struct {
|
|
Query string
|
|
UserID int
|
|
ConversationID string
|
|
AssistantID string
|
|
RunID string
|
|
MemoryTypes []string
|
|
Limit int
|
|
Now time.Time
|
|
}
|
|
|
|
// ListItemsRequest 描述记忆管理页列表查询参数。
|
|
type ListItemsRequest struct {
|
|
UserID int
|
|
ConversationID string
|
|
Statuses []string
|
|
MemoryTypes []string
|
|
Limit int
|
|
}
|
|
|
|
// CreateItemFields 是 repo 层落库时真正需要的字段集合。
|
|
type CreateItemFields struct {
|
|
UserID int
|
|
ConversationID string
|
|
AssistantID string
|
|
RunID string
|
|
MemoryType string
|
|
Title string
|
|
Content string
|
|
NormalizedContent string
|
|
ContentHash string
|
|
Confidence float64
|
|
Importance float64
|
|
SensitivityLevel int
|
|
IsExplicit bool
|
|
Status string
|
|
TTLAt *time.Time
|
|
VectorStatus string
|
|
SourceMessageID *int64
|
|
SourceEventID *string
|
|
LastAccessAt *time.Time
|
|
}
|
|
|
|
// UpdateItemFields 是“用户管理侧修改记忆”时 repo 层允许更新的字段集合。
|
|
type UpdateItemFields struct {
|
|
MemoryType string
|
|
Title string
|
|
Content string
|
|
NormalizedContent string
|
|
ContentHash string
|
|
Confidence float64
|
|
Importance float64
|
|
SensitivityLevel int
|
|
IsExplicit bool
|
|
TTLAt *time.Time
|
|
}
|