增加人物画像证据纠错功能,并提高检索表现#1747
Conversation
- 为 memory_profile_admin 增加画像证据查询与纠错动作 - 暴露 WebUI 画像证据接口并接入人物画像页 - 将用户可见 override 文案统一为画像覆写
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
工作流总览该PR在仪表盘中实现了内存画像证据的完整查询与纠错功能。前端通过新增API调用后端,后端在核心逻辑中聚合各来源的证据(关系、段落等),通过WebUI路由暴露给前端,前端展示证据表格并支持纠错操作,纠错时可选择刷新证据或重新加载完整画像数据;同时数据库层新增性能索引以优化热点查询。 变更说明内存画像证据功能
相关PR
🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
该 PR 为 WebUI 增加“人物画像支撑证据查看/纠错”能力,并通过在 MetadataStore 中补充热点查询索引来提升检索/查询性能。
Changes:
- 新增人物画像证据查询接口与证据纠错(删除/停用证据并可触发刷新)接口,并在 Dashboard 增加对应 UI 操作入口
- 在 Memory Kernel 增加 profile_admin 的
evidence/correct_evidence动作与证据聚合响应结构 - MetadataStore schema 升级并新增多组性能索引
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/webui/routers/memory.py | 增加人物画像证据查询与纠错路由,并转发到 profile_admin 动作 |
| src/A_memorix/core/storage/metadata_store.py | schema 版本升级并新增热点索引创建逻辑,用于提升查询性能 |
| src/A_memorix/core/runtime/sdk_memory_kernel.py | 实现 evidence/纠错证据的管理动作与响应聚合逻辑 |
| pytests/webui/test_memory_routes.py | 增加 WebUI 路由层的 evidence / correct_evidence 测试 |
| dashboard/src/routes/resource/tests/knowledge-base.test.tsx | 更新 memory-api mock,补齐新增导出 |
| dashboard/src/lib/memory-api.ts | 增加前端调用 evidence / correct_evidence 的 API 封装与类型 |
| dashboard/src/components/memory/MemoryProfileManager.tsx | 增加证据列表展示、刷新与“纠错并刷新”交互入口 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # 时序索引(仅在列存在时创建,兼容旧库迁移) | ||
| self._create_temporal_indexes_if_ready() | ||
| self._create_performance_indexes() |
| const confidence = Number(item.confidence) | ||
| if (Number.isFinite(confidence)) { | ||
| return `置信度 ${confidence.toFixed(2)}` | ||
| } | ||
| const score = Number(item.score) | ||
| if (Number.isFinite(score)) { | ||
| return `分数 ${score.toFixed(2)}` |
| export async function correctMemoryProfileEvidence(payload: { | ||
| person_id: string | ||
| evidence_type: string | ||
| hash: string | ||
| requested_by?: string |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
dashboard/src/routes/resource/__tests__/knowledge-base.test.tsx (1)
91-92: 🏗️ Heavy lift补一条画像证据主路径的回归测试。
这里只补了 mock,还没有覆盖“选中画像后拉取证据 / 纠错后直接使用
refreshed_evidence/ 兜底重新拉取”这几条新增状态流转。当前 PR 的核心价值基本都在这里,建议至少补一条集成用例把这条链路钉住。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dashboard/src/routes/resource/__tests__/knowledge-base.test.tsx` around lines 91 - 92, 补一条覆盖画像证据主路径的集成测试:在 knowledge-base.test.tsx 中新增用例,模拟 getMemoryProfileEvidence 和 correctMemoryProfileEvidence(用 diff 中的标识符)分别返回初始 evidence / 包含 refreshed_evidence 的响应,并通过用户交互(选中画像、触发纠错)断言先调用 getMemoryProfileEvidence、纠错调用 correctMemoryProfileEvidence 并且组件用返回的 refreshed_evidence 更新显示;另外再加一个分支 mock correctMemoryProfileEvidence 返回不含 refreshed_evidence 的情况,断言组件会兜底再次调用 getMemoryProfileEvidence 并更新显示。确保用 vi.fn() 控制返回值并匹配组件交互(选择画像、点击纠错)和最终断言。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dashboard/src/components/memory/MemoryProfileManager.tsx`:
- Around line 208-213: 将证据加载与当前 selectedPersonId 绑定,避免 A 的证据出现在 B 的详情或重复请求:在
effect 中不要只检查 profileEvidence 的存在,而要比对 profileEvidence.personId 与
selectedPersonId,且在调用 loadProfileEvidence 时明确传入 selectedPersonId;改写判断为当
selectedPersonId 存在且 (profileEvidence 为空 或 profileEvidence.personId !==
selectedPersonId) 且 queryResult 不阻塞时才调用
loadProfileEvidence(selectedPersonId)。同样修复其他相同逻辑处(涉及 loadProfileEvidence /
getMemoryProfileEvidence 的分支 231-245 和 294-300),确保所有触发点都以 personId
为键去重/判断,避免重复请求。
- Around line 139-141: 当前逻辑使用 `profileEvidence?.profile_text || profileText`
会把空字符串视为“无值”并回退,导致用户显式留空无法展示;请将这一处改为显式判空(例如使用 nullish 合并或检查 `=== undefined`/`===
null`)以允许空字符串被接受:更新 `displayedProfileText` 的第二分支,使其用
`profileEvidence?.profile_text ?? profileText` 或等价的显式非 null/undefined 判断来决定是否使用
`profileEvidence.profile_text`(保留原先对 `showAutoProfile` 和
`profileEvidence?.auto_profile_text` 的判断不变)。
In `@src/A_memorix/core/runtime/sdk_memory_kernel.py`:
- Around line 5942-5948: _profile_relation_content currently concatenates
subject, predicate, object without separators, producing unreadable
"subjectpredicateobject"; change it to produce a human-friendly, consistent
relation string by inserting separators (e.g., " - " or " | ") between non-empty
parts or, better, call the project’s central relation formatter instead of
manual concat. Locate _profile_relation_content, use the relation keys
("subject", "predicate", "object"), and either (a) return f"{subject} -
{predicate} - {obj}" when all parts exist or (b) invoke the existing relation
formatting utility (e.g., format_relation_text / format_relation) to produce the
standardized text and return that result.
In `@src/A_memorix/core/storage/metadata_store.py`:
- Around line 1063-1064: The call to _create_performance_indexes() runs before
schema migration and immediately creates indexes that reference new columns
(e.g., paragraphs.is_deleted and relations.is_inactive), causing "no such
column" errors on older DBs; fix by moving the _create_performance_indexes()
invocation to after _migrate_schema() completes (or alternatively add the same
PRAGMA table_info guard used in _create_temporal_indexes_if_ready() to check for
the presence of those columns before creating indexes) so indexes are only
created when the required columns exist.
---
Nitpick comments:
In `@dashboard/src/routes/resource/__tests__/knowledge-base.test.tsx`:
- Around line 91-92: 补一条覆盖画像证据主路径的集成测试:在 knowledge-base.test.tsx 中新增用例,模拟
getMemoryProfileEvidence 和 correctMemoryProfileEvidence(用 diff 中的标识符)分别返回初始
evidence / 包含 refreshed_evidence 的响应,并通过用户交互(选中画像、触发纠错)断言先调用
getMemoryProfileEvidence、纠错调用 correctMemoryProfileEvidence 并且组件用返回的
refreshed_evidence 更新显示;另外再加一个分支 mock correctMemoryProfileEvidence 返回不含
refreshed_evidence 的情况,断言组件会兜底再次调用 getMemoryProfileEvidence 并更新显示。确保用 vi.fn()
控制返回值并匹配组件交互(选择画像、点击纠错)和最终断言。
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0ce5e1a4-cd1b-46f3-b2b4-4efd57828045
📒 Files selected for processing (7)
dashboard/src/components/memory/MemoryProfileManager.tsxdashboard/src/lib/memory-api.tsdashboard/src/routes/resource/__tests__/knowledge-base.test.tsxpytests/webui/test_memory_routes.pysrc/A_memorix/core/runtime/sdk_memory_kernel.pysrc/A_memorix/core/storage/metadata_store.pysrc/webui/routers/memory.py
zh-CN目标翻译作为常规 GitHub 编辑面;常规翻译以 Crowdin ->l10n_*PR 回流为准,详见docs/i18n.md请填写以下内容
(删除掉中括号内的空格,并替换为小写的x)
main分支 禁止修改,请确认本次提交的分支 不是main分支src/A_memorix,我确认已阅读src/A_memorix/MODIFICATION_POLICY.md,不涉及则无需勾选其他信息
Summary by CodeRabbit
New Features
Tests
Chores