Version: 0.9.13.dev.260410
后端: 1. Memory Day1 链路打通(chat_history -> outbox -> memory_jobs) - 更新 service/events/chat_history_persist.go:聊天消息落库同事务追加 memory.extract.requested 事件(仅 user 消息,失败回滚后由 outbox 重试) - 新建 service/events/memory_extract_requested.go:消费 memory.extract.requested 并幂等入队 memory_jobs,补齐 payload 校验、文本截断与 idempotency key - 更新 cmd/start.go:注册 RegisterMemoryExtractRequestedHandler 2. Memory 模块骨架落地(先跑通状态机,再接入真实抽取) - 新建 memory/model、repo、service、orchestrator、worker、utils 目录与 Day1 mock 抽取执行链 - 新建 model/memory.go:补齐 memory_items / memory_jobs / memory_audit_logs / memory_user_settings 与事件 payload 模型 - 更新 inits/mysql.go:接入 4 张 memory 相关表 AutoMigrate 3. RAG 复用基础设施预埋(依赖可替换) - 新建 infra/rag:core pipeline + chunk/embed/retrieve/rerank/store/corpus/config 分层实现 - 默认接入 MockEmbedder + InMemoryStore,预留 Milvus / Eino 适配实现 - 新增 infra/rag/RAG复用接口实施计划.md 4. 本地依赖与交接文档同步 - 更新 docker-compose.yml:新增 etcd / minio / milvus / attu 服务与数据卷 - 删除 newAgent/HANDOFF_工具研究与运行态重置.md、newAgent/阶段3_上下文瘦身设计.md - 新增 newAgent/HANDOFF_WebSearch两阶段实施计划.md、memory/HANDOFF-RAG复用后续实施计划.md、memory/README.md 前端:无 仓库:无
This commit is contained in:
49
backend/memory/service/config_loader.go
Normal file
49
backend/memory/service/config_loader.go
Normal file
@@ -0,0 +1,49 @@
|
||||
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"),
|
||||
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"),
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
33
backend/memory/service/enqueue_service.go
Normal file
33
backend/memory/service/enqueue_service.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
memorymodel "github.com/LoveLosita/smartflow/backend/memory/model"
|
||||
memoryrepo "github.com/LoveLosita/smartflow/backend/memory/repo"
|
||||
)
|
||||
|
||||
// EnqueueService 是 Day1 的“任务入队门面”。
|
||||
//
|
||||
// 职责边界:
|
||||
// 1. 只负责把抽取请求入 memory_jobs;
|
||||
// 2. 不负责执行抽取、不负责写 memory_items。
|
||||
type EnqueueService struct {
|
||||
jobRepo *memoryrepo.JobRepo
|
||||
}
|
||||
|
||||
func NewEnqueueService(jobRepo *memoryrepo.JobRepo) *EnqueueService {
|
||||
return &EnqueueService{jobRepo: jobRepo}
|
||||
}
|
||||
|
||||
func (s *EnqueueService) EnqueueExtractJob(
|
||||
ctx context.Context,
|
||||
payload memorymodel.ExtractJobPayload,
|
||||
sourceEventID string,
|
||||
) error {
|
||||
if s == nil || s.jobRepo == nil {
|
||||
return errors.New("memory enqueue service is nil")
|
||||
}
|
||||
return s.jobRepo.CreatePendingExtractJob(ctx, payload, sourceEventID)
|
||||
}
|
||||
Reference in New Issue
Block a user