feat(memory): 长记忆 store(SQLite+persona 隔离)/工作记忆滑动窗口/检索注入/手工提取钩子

This commit is contained in:
Aska committed 2026-09-06 05:12:42 +08:00
1 parent 285e1e9911
commit aa697c385f
10 files changed
+1705

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
package memory
import (
"context"
"io"
"log/slog"
"testing"
"git.yeij.top/AskaEth/Cyrene_v2/internal/db"
)
// testLogger returns a logger that writes nowhere, keeping test output clean.
func testLogger() *slog.Logger {
return slog.New(slog.NewTextHandler(io.Discard, nil))
}
// newTestStore opens an isolated in-memory SQLite DB and builds a Store over it.
// Each call owns a private DB, so parallel tests are isolated by construction.
func newTestStore(t *testing.T) *Store {
t.Helper()
ctx := context.Background()
d, err := db.Open(ctx, ":memory:", testLogger())
if err != nil {
t.Fatalf("open in-memory db: %v", err)
}
t.Cleanup(func() { _ = d.Close() })
s, err := NewStore(ctx, d, testLogger())
if err != nil {
t.Fatalf("NewStore: %v", err)
}
return s
}
// baseItem is a minimal valid memory item for tests.
func baseItem() MemoryItem {
return MemoryItem{
PersonaID: "persona.a",
RoleID: "role.1",
Scope: ScopePersona,
Kind: KindRelationship,
Content: "她喜欢喝冰美式",
Tags: []string{"habit", "coffee"},
Confidence: 0.9,
}
}