mirror of
https://gitcode.com/JianFeeeee/HomeAgent.git
synced 2026-10-03 15:53:56 +00:00
fix(memory): 修图记忆召回的两处能力缺失(关系重复 + 原句不回显)
针对 memory_recall / 自动注入这条图记忆召回链路的实测复核: - Recall(depth>1) 跨层不去重:每层都用已累积的 entityIDs 查邻接, 上一层刚产出的关系会在下一层被反复查回并再次 append。实测 小明→小红 在 depth=2 出现两次,memory_recall 的 10 条关系预算被 同一句话刷屏、真正的新关系(小红→小刚)被截断。改为按 relation ID 跨层去重(实体本就已去重)。 - memory_recall 从不回显 sentence_text:工具 schema 明写「填了才能日后 从图谱回到原文」、Recall 也已 JOIN 出句子,但输出只给实体名与关系类型, 该字段形同虚设。抽出 formatRecallRelations,对非空原句截断 60 字附在 关系行后;超过 10 条仍截断并提示。 测试:TestRecallWithDepth 增补去重与精确条数断言; 新增 TestFormatRecallRelations_SurfacesSentence / _Truncates。 go build/vet 干净,go test -race ./internal/memory/ ./internal/agent/core/... 全绿。
This commit is contained in:
@ -260,6 +260,22 @@ func TestRecallWithDepth(t *testing.T) {
|
||||
if len(result.Relations) == 0 {
|
||||
t.Error("expected relations with depth search")
|
||||
}
|
||||
|
||||
// 逐层查邻接会把已访问实体之间的关系反复查回。不跨层去重时,
|
||||
// 小明→小红 会在 depth=2 出现两次,memory_recall 的 10 条关系预算
|
||||
// 被同一句话刷屏、真正的新关系(小红→小刚)被截断。
|
||||
seen := map[int64]int{}
|
||||
for _, r := range result.Relations {
|
||||
seen[r.ID]++
|
||||
}
|
||||
for id, n := range seen {
|
||||
if n > 1 {
|
||||
t.Errorf("关系 id=%d 在深度遍历中重复 %d 次", id, n)
|
||||
}
|
||||
}
|
||||
if len(result.Relations) != 2 {
|
||||
t.Errorf("depth=2 应得 2 条关系(小明→小红、小红→小刚),实际 %d", len(result.Relations))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPurgeHard(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user