后端: 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
4.0 KiB
Go
106 lines
4.0 KiB
Go
package model
|
||
|
||
import "time"
|
||
|
||
// MemoryGetItemRequest 描述“查看我的某条记忆”所需的最小参数。
|
||
type MemoryGetItemRequest struct {
|
||
UserID int
|
||
MemoryID int64
|
||
}
|
||
|
||
// MemoryCreateItemRequest 描述“手动新增一条记忆”的输入。
|
||
type MemoryCreateItemRequest struct {
|
||
UserID int `json:"-"`
|
||
ConversationID string `json:"conversation_id,omitempty"`
|
||
AssistantID string `json:"assistant_id,omitempty"`
|
||
RunID string `json:"run_id,omitempty"`
|
||
MemoryType string `json:"memory_type"`
|
||
Title string `json:"title"`
|
||
Content string `json:"content"`
|
||
Confidence *float64 `json:"confidence,omitempty"`
|
||
Importance *float64 `json:"importance,omitempty"`
|
||
SensitivityLevel *int `json:"sensitivity_level,omitempty"`
|
||
IsExplicit *bool `json:"is_explicit,omitempty"`
|
||
TTLAt *time.Time `json:"ttl_at,omitempty"`
|
||
Reason string `json:"reason,omitempty"`
|
||
OperatorType string `json:"-"`
|
||
}
|
||
|
||
// MemoryUpdateItemRequest 描述“手动修改一条记忆”的 Patch 输入。
|
||
//
|
||
// 说明:
|
||
// 1. 使用指针区分“未传字段”和“显式传零值”;
|
||
// 2. ClearTTL 用于表达“显式清空 ttl_at”;
|
||
// 3. 当前仍只允许修改内容侧字段,不开放跨用户、跨归属字段改写。
|
||
type MemoryUpdateItemRequest struct {
|
||
UserID int `json:"-"`
|
||
MemoryID int64 `json:"-"`
|
||
MemoryType *string `json:"memory_type,omitempty"`
|
||
Title *string `json:"title,omitempty"`
|
||
Content *string `json:"content,omitempty"`
|
||
Confidence *float64 `json:"confidence,omitempty"`
|
||
Importance *float64 `json:"importance,omitempty"`
|
||
SensitivityLevel *int `json:"sensitivity_level,omitempty"`
|
||
IsExplicit *bool `json:"is_explicit,omitempty"`
|
||
TTLAt *time.Time `json:"ttl_at,omitempty"`
|
||
ClearTTL bool `json:"clear_ttl,omitempty"`
|
||
Reason string `json:"reason,omitempty"`
|
||
OperatorType string `json:"-"`
|
||
}
|
||
|
||
// MemoryDeleteItemRequest 描述“删除我的一条记忆”的输入。
|
||
type MemoryDeleteItemRequest struct {
|
||
UserID int
|
||
MemoryID int64
|
||
Reason string
|
||
OperatorType string
|
||
}
|
||
|
||
// MemoryRestoreItemRequest 描述“恢复我的一条记忆”的输入。
|
||
type MemoryRestoreItemRequest struct {
|
||
UserID int
|
||
MemoryID int64
|
||
Reason string
|
||
OperatorType string
|
||
}
|
||
|
||
// MemoryDedupCleanupRequest 描述离线去重治理任务的执行参数。
|
||
type MemoryDedupCleanupRequest struct {
|
||
UserID int
|
||
Limit int
|
||
DryRun bool
|
||
Reason string
|
||
OperatorType string
|
||
}
|
||
|
||
// MemoryDedupCleanupResult 描述一次离线去重治理的汇总结果。
|
||
type MemoryDedupCleanupResult struct {
|
||
ScannedGroupCount int `json:"scanned_group_count"`
|
||
DedupedGroupCount int `json:"deduped_group_count"`
|
||
KeptCount int `json:"kept_count"`
|
||
ArchivedCount int `json:"archived_count"`
|
||
ArchivedIDs []int64 `json:"archived_ids,omitempty"`
|
||
DryRun bool `json:"dry_run"`
|
||
}
|
||
|
||
// MemoryItemView 是前端可见的记忆条目视图。
|
||
type MemoryItemView struct {
|
||
ID int64 `json:"id"`
|
||
UserID int `json:"user_id"`
|
||
ConversationID string `json:"conversation_id,omitempty"`
|
||
AssistantID string `json:"assistant_id,omitempty"`
|
||
RunID string `json:"run_id,omitempty"`
|
||
MemoryType string `json:"memory_type"`
|
||
Title string `json:"title"`
|
||
Content string `json:"content"`
|
||
ContentHash string `json:"content_hash,omitempty"`
|
||
Confidence float64 `json:"confidence"`
|
||
Importance float64 `json:"importance"`
|
||
SensitivityLevel int `json:"sensitivity_level"`
|
||
IsExplicit bool `json:"is_explicit"`
|
||
Status string `json:"status"`
|
||
TTLAt *time.Time `json:"ttl_at,omitempty"`
|
||
CreatedAt *time.Time `json:"created_at,omitempty"`
|
||
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
||
}
|