Skip to content

增加人物画像证据纠错功能,并提高检索表现#1747

Merged
A-Dawn merged 5 commits into
Mai-with-u:devfrom
A-Dawn:dev
May 26, 2026
Merged

增加人物画像证据纠错功能,并提高检索表现#1747
A-Dawn merged 5 commits into
Mai-with-u:devfrom
A-Dawn:dev

Conversation

@A-Dawn
Copy link
Copy Markdown
Collaborator

@A-Dawn A-Dawn commented May 26, 2026

  • ✅ 接受:与main直接相关的Bug修复:提交到dev分支
  • 新增功能类pr需要经过issue提前讨论,否则不会被合并
  • 🌐 i18n 提醒:除 bootstrap 或紧急修复外,请不要把非 zh-CN 目标翻译作为常规 GitHub 编辑面;常规翻译以 Crowdin -> l10n_* PR 回流为准,详见 docs/i18n.md

请填写以下内容

(删除掉中括号内的空格,并替换为小写的x

    • main 分支 禁止修改,请确认本次提交的分支 不是 main 分支
    • 我确认我阅读了贡献指南
    • 本次更新类型为:BUG修复
    • 本次更新类型为:功能新增
    • 本次更新是否经过测试
    • 如果本次修改涉及 src/A_memorix,我确认已阅读 src/A_memorix/MODIFICATION_POLICY.md,不涉及则无需勾选
  1. 请填写破坏性更新的具体内容(如有):
  2. 请简要说明本次更新的内容和目的:增加人物画像证据纠错功能,并提高检索表现

其他信息

  • 关联 Issue:Close #
  • 截图/GIF
  • 附加信息:

Summary by CodeRabbit

  • New Features

    • 在画像详情中新增证据列表、证据表格与“刷新证据”按钮,支持查看来源与序列化展示
    • 新增“纠错并刷新”操作,允许提交证据纠错并在成功后刷新画像与证据显示
    • 画像覆写区文案与按钮标签调整,保存/删除后自动刷新相关视图
  • Tests

    • 新增覆盖证据查询与纠错路由的端到端测试
  • Chores

    • 升级数据库模式并创建性能索引以改善证据查询效率

Review Change Stack

A-Dawn added 4 commits May 26, 2026 13:19
- 为 memory_profile_admin 增加画像证据查询与纠错动作

- 暴露 WebUI 画像证据接口并接入人物画像页

- 将用户可见 override 文案统一为画像覆写
Copilot AI review requested due to automatic review settings May 26, 2026 06:14
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dc372dc8-fa40-4aac-a868-5be002c81fc6

📥 Commits

Reviewing files that changed from the base of the PR and between c0993a8 and d66bc6c.

📒 Files selected for processing (3)
  • dashboard/src/components/memory/MemoryProfileManager.tsx
  • src/A_memorix/core/runtime/sdk_memory_kernel.py
  • src/A_memorix/core/storage/metadata_store.py

工作流总览

该PR在仪表盘中实现了内存画像证据的完整查询与纠错功能。前端通过新增API调用后端,后端在核心逻辑中聚合各来源的证据(关系、段落等),通过WebUI路由暴露给前端,前端展示证据表格并支持纠错操作,纠错时可选择刷新证据或重新加载完整画像数据;同时数据库层新增性能索引以优化热点查询。

变更说明

内存画像证据功能

层 / 文件(s) 概述
前端API类型与函数定义
dashboard/src/lib/memory-api.ts
新增 MemoryProfileEvidenceItemPayloadMemoryProfileEvidencePayloadMemoryProfileEvidenceCorrectPayload 等类型,以及 getMemoryProfileEvidencecorrectMemoryProfileEvidence 两个导出函数,用于前端调用证据接口。
后端证据构建与纠错业务逻辑
src/A_memorix/core/runtime/sdk_memory_kernel.py
实现证据类型推导、关系和段落证据条目构建、证据列表聚合和去重、证据查询(支持强制刷新)以及证据纠错流程(包括删除校验、可选刷新和结果返回)等内部方法;在 memory_profile_admin 中添加 evidencecorrect_evidence 两个动作分支。
WebUI路由与请求处理
src/webui/routers/memory.py
新增 ProfileEvidenceCorrectRequest 请求模型,添加 GET /profiles/{person_id}/evidencePOST /profiles/{person_id}/evidence/correct 两个路由端点,实现参数透传到后端业务逻辑。
后端路由集成测试
pytests/webui/test_memory_routes.py
添加两个测试用例验证证据查询和纠错路由,包括参数映射和响应结构的断言。
前端组件状态管理与证据加载
dashboard/src/components/memory/MemoryProfileManager.tsx
补充API导入,新增证据类型格式化辅助函数,扩展组件状态用于存储 profileEvidence 和加载/纠错状态;实现 loadProfileEvidence 函数在查询和选择画像时自动拉取证据。
前端组件UI展示与证据纠错操作
dashboard/src/components/memory/MemoryProfileManager.tsx
在详情区新增证据表格展示,支持刷新证据按钮;为每条证据提供"纠错并刷新"操作(当 deletable 时),纠错成功后根据返回结果更新证据或强制重新加载;更新保存/删除覆写时的证据刷新逻辑;调整"画像覆写"相关文案。
数据库索引性能优化
src/A_memorix/core/storage/metadata_store.py
将schema版本从12升至13,新增 _create_performance_indexes() 方法创建段落关系、实体关联和队列表的联合索引,在初始化和迁移流程中调用该方法。
前端测试mock更新
dashboard/src/routes/resource/__tests__/knowledge-base.test.tsx
在memory-api mock中补充 getMemoryProfileEvidencecorrectMemoryProfileEvidence 函数定义。

相关PR

  • Mai-with-u/MaiBot#1657:修改关系/向量证据的构建与过滤逻辑,确保证据正确绑定至目标person_id,影响本PR中证据内容的返回和编辑。

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR 标题准确反映了主要变更内容:增加人物画像证据纠错功能和性能提升,与文件改动完全相关。
Description check ✅ Passed PR 描述虽然保留了模板框架且关联 Issue 部分未填写具体编号,但已勾选必要的检查项、明确标注为功能新增、声明已测试并确认阅读了修改政策。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Comment on lines +99 to +105
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)}`
Comment on lines +1117 to +1121
export async function correctMemoryProfileEvidence(payload: {
person_id: string
evidence_type: string
hash: string
requested_by?: string
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8280c7c and c0993a8.

📒 Files selected for processing (7)
  • dashboard/src/components/memory/MemoryProfileManager.tsx
  • dashboard/src/lib/memory-api.ts
  • dashboard/src/routes/resource/__tests__/knowledge-base.test.tsx
  • pytests/webui/test_memory_routes.py
  • src/A_memorix/core/runtime/sdk_memory_kernel.py
  • src/A_memorix/core/storage/metadata_store.py
  • src/webui/routers/memory.py

Comment thread dashboard/src/components/memory/MemoryProfileManager.tsx Outdated
Comment thread dashboard/src/components/memory/MemoryProfileManager.tsx Outdated
Comment thread src/A_memorix/core/runtime/sdk_memory_kernel.py
Comment thread src/A_memorix/core/storage/metadata_store.py Outdated
@A-Dawn A-Dawn merged commit afc2481 into Mai-with-u:dev May 26, 2026
3 of 4 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request May 27, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants