fix: 蒸馏产物不回写记忆库,OnDistillComplete缺InsertMemory
蒸馏引擎跑完后结果只进了图谱(SQLite)没有写回LanceDB记忆库。 OnDistillComplete回调中有graphUpdater.UpdateFromDistill() 和冲突检测,但没有将extracted facts作为distilled类别记忆 写入memories表。 修复:在server.go的OnDistillComplete回调中添加 ldb.InsertMemory循环,将result.Facts逐条写入LanceDB。 同时添加models import。 验证: - force distill -> 5条distilled记忆写入,评分0.828-0.987 - 时间戳正确,category=distilled - recall可通过category过滤获取蒸馏产物
This commit is contained in:
parent
ff935587bd
commit
36af93055f
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/xiaoxue/memoryweave/internal/distill"
|
||||
"github.com/xiaoxue/memoryweave/internal/governance"
|
||||
"github.com/xiaoxue/memoryweave/internal/metrics"
|
||||
"github.com/xiaoxue/memoryweave/internal/models"
|
||||
"github.com/xiaoxue/memoryweave/internal/selfoptimize"
|
||||
"github.com/xiaoxue/memoryweave/internal/storage"
|
||||
)
|
||||
|
|
@ -128,7 +129,7 @@ func NewServer() http.Handler {
|
|||
if llmAPIKey == "" { llmAPIKey = os.Getenv("API_KEY") }
|
||||
distillEngine := distill.NewEngine(llmEndpoint, llmModel, llmAPIKey)
|
||||
routes.DistillEngineRef = distillEngine
|
||||
// 蒸馏完成 → 自动图谱更新 + 冲突检测 + 被动验证
|
||||
// 蒸馏完成 → 自动图谱更新 + 冲突检测 + 被动验证 + 回写内存
|
||||
distill.OnDistillComplete = func(input distill.DistillInput, result distill.DistillResult) {
|
||||
entityNames := make([]string, len(result.Entities))
|
||||
for i, e := range result.Entities { entityNames[i] = e.Name }
|
||||
|
|
@ -137,6 +138,26 @@ func NewServer() http.Handler {
|
|||
Entities: entityNames, Namespace: input.Namespace,
|
||||
EpisodeID: input.EpisodeID,
|
||||
})
|
||||
|
||||
// 回写蒸馏产物到记忆库(LanceDB)
|
||||
for _, fact := range result.Facts {
|
||||
mem := models.MemoryRecord{
|
||||
ID: fmt.Sprintf("mem_%d", time.Now().UnixNano()),
|
||||
AgentID: input.AgentID,
|
||||
Namespace: input.Namespace,
|
||||
Content: fact,
|
||||
Category: "distilled",
|
||||
Tier: "normal",
|
||||
QualityScore: result.Overall,
|
||||
Version: 1,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
DerivedFrom: input.EpisodeID,
|
||||
}
|
||||
if err := ldb.InsertMemory(mem); err != nil {
|
||||
log.Printf("[distill] commit fact failed: %v", err)
|
||||
}
|
||||
}
|
||||
// 冲突检测:加载同 namespace 已有记忆进行比较
|
||||
zeroVec := make([]float32, 1024)
|
||||
existingMems, _ := ldb.Search("memories", zeroVec, 100, input.Namespace)
|
||||
|
|
|
|||
Loading…
Reference in New Issue