图谱抽取:KB 级启用后,存量文档经「重建知识」仍不生效——batch reparse 沿用上传时的 process_overrides 快照
环境
- WeKnora v0.9.0(官方 tag),docker compose 单机部署,ParadeDB v0.25.11-pg17
- NEO4J_ENABLE=true,neo4j 2025.10.1,连接验证正常
复现步骤
- 向知识库上传一批文档(此时库尚未启用图谱抽取)
- KB 设置 → 知识图谱:启用实体关系抽取,完整填写 tags/nodes/relations/text,保存成功
- 文档列表全选 → 「重建知识」(批量重建)
- 结果:全部文档
completed,但图谱抽取任务零入队——neo4j 0 节点 0 关系,日志无queue=graph,asynq 无 graph 队列键
根因(代码定位)
- 文档上传时,
metadata.process_overrides冻结快照(此时graph_enabled=false) - 有效配置合并
internal/application/service/knowledge_process_config.go:
——文档级显式 false 覆盖 KB 级 trueif overrides.GraphEnabled != nil { eff.GraphEnabled = *overrides.GraphEnabled } POST /knowledge/batch-reparse请求体不含 overrides 时,reparseKnowledge语义为 "nil keeps whatever was stored at upload time" → 沿用旧快照- 扇出点
knowledge_post_process.go:eff.GraphEnabled=false→ 零图谱子任务
矛盾点
KB 编辑器在索引策略变更时会主动提示「是否对已有的 N 篇文档重新处理?」—— UI 承诺新配置可应用到存量文档,但 graph/extract 配置经重建并不生效, 与提示语义不符。
影响
库级启用图谱仅对之后新上传的文档生效;存量文档即使批量重建也不进图, 且无任何 UI 提示或操作路径可刷新。
建议修复方向(任一)
a. batch reparse 不带 overrides 时,按 KB 当前配置刷新文档快照 b. 重建确认框提供「应用库当前配置」选项 c. 至少在文档/提示中对齐行为,告知存量文档刷新方式
数据证据(生产实测时间线,已脱敏)
- T0 上传文档(快照冻结 graph=false)
- T1 KB 级启用图谱(
extract_config.enabled=true,updated_at 可证) - T2 批量重建(T1 之后 44 分钟),26/26 completed,图谱抽取 0 次
- 三重验证:asynq graph 队列键 0 / 日志
queue=graph0 条 / neo4j nodes=0
我在当前 main(cbdcebab)做了静态代码核对,报告的配置覆盖链可以确认;未做运行时复现:
- Web 上传弹窗会生成完整的
graph_enabled/extract_config(frontend/src/views/knowledge/components/UploadConfirmDialog.vue:1326-1384),非空配置随后写入metadata.process_overrides(internal/application/service/knowledge_create.go:199-204,internal/types/knowledge.go:493-546)。 - batch worker 将
payload.ProcessConfig原样传给ReparseKnowledge(internal/application/service/knowledge_process.go:4907-4936);其为nil时,reparseKnowledge保留并重新读取已存 overrides(同文件3000-3019)。 - 合并先取 KB 配置,再让非
nil的文档级GraphEnabled覆盖(internal/application/service/knowledge_process_config.go:39-58,98-100);旧extract_config.enabled=false也会覆盖 KB 值,并在最终&&中关闭图谱(同文件139-145,359-380)。因此只清graph_enabled不足以修复。 - post-process 重读同一 overrides,只有
eff.GraphEnabled为真才计算并入队 graph 子任务(internal/application/service/knowledge_post_process.go:170-171,251-254,420-435)。 - KB 级开关及保存路径存在(
frontend/src/views/knowledge/settings/GraphSettings.vue:40-53,internal/application/service/knowledgebase.go:657-677),所以问题确在新旧配置合并/重建语义,而不是缺少 KB 开关。
对三个方向的取舍:
- 方向 1(
nil时刷新快照)改动直接,但会改变已文档化的“未传则沿用上传配置”契约,可能覆盖文档级显式选择;还需考虑升级前已入队的nilpayload。 - 方向 2(确认框显式“应用库当前配置”)是我个人更推荐的方向:可复用现有
process_config,保留默认兼容行为,也无需数据迁移;但需明确提示会覆盖所选文档的 overrides,并同时覆盖列表批量重建和 KB 编辑器的rebuild-index(后者目前在internal/handler/knowledge.go:3513固定传nil)。 - 方向 3 风险最低,适合作为补充说明,但单独采用仍不能兑现“重新处理以应用新策略”的提示。
重叠风险:#4217 已修改同一快照/恢复 KB 设置路径,#2758 已做批量配置弹窗,#2763 也修改 knowledge_process.go,实施前需先协调。#5299、#5328、#5308 仅涉及下游 Neo4j 写入或抽取结果解析,无文件重叠。
我可以按方向 2 实现,或基于上述现有 PR 补齐图谱场景与回归测试;若维护者认可请告知,若已有安排请忽略。
Reproduced on a clean v0.9.0 Docker Compose deployment (Neo4j enabled) with the same shape as the report: batch rebuild with no process_config completes both documents while zero graph tasks are enqueued (no asynq:{graph} keys, no queue=graph log lines, Neo4j unchanged), yet the same request carrying "process_config": {} enqueues graph tasks immediately.
That nil and {} differ is the whole bug: an explicit empty object already replaces the stored snapshot so every field resolves from the KB's current config. The fix in #5591 unifies nil with that existing semantics (a single normalization inside ReparseKnowledge), so the document-list batch rebuild and the processing-timeline retry pick up strategy changes made after upload, while explicit overrides — including the single-document reparse dialog — keep winning. Stale snapshots self-heal on the next rebuild; no migration involved.
Verified end-to-end after the fix: an override-less batch or single-document rebuild flips a stale graph_enabled: false to a refreshed snapshot, enqueues graph tasks, and the extraction lands in Neo4j (+25 nodes for two rebuilt documents); an explicit graph_enabled: false still pins; new uploads are unchanged.