WeKnora icon indicating copy to clipboard operation
WeKnora copied to clipboard

[Bug]: Graph extraction discards valid entries when the model returns a mixed JSON array

Open lynnlase opened this issue 3 weeks ago • 0 comments

Affected Component

Backend Service & API

Bug Description

知识图谱抽取模型可能返回合法的 JSON 数组,但数组里混有 null 或字符串等非对象项。当前 Formater.parseOutput 在第一个非对象项处直接返回错误,整个切片中原本符合 WeKnora 结构的节点和关系也一并丢失。普通正文和向量可用,这个问题只影响该切片的图谱增强。

这一签名在日常入库的脱敏追踪中出现过。复现数据如下,全部为虚构内容。

Steps to Reproduce

  1. 创建启用图谱抽取的知识库。给图谱模型使用一个可控的 OpenAI-compatible stub,正文和 Embedding 正常运行。
  2. 上传一份包含“测试控制器控制测试驱动器”的小文档。让 stub 以 finish_reason=stop 返回以下正文。
[
  {"entity":"Synthetic Controller"},
  null,
  {"entity":"Synthetic Drive"},
  {"entity1":"Synthetic Controller","entity2":"Synthetic Drive","relation":"controls"}
]
  1. 检查图谱切片的处理轨迹和写入结果。可增加一个对照响应,仅移除 null。

以上是根据已核对的源码整理的复验步骤,未在纯上游完整环境执行。错误分支也可通过将这段响应直接传给 NewFormater().ParseGraph 验证。

Actual Behavior

json.Unmarshal 成功。遍历数组时,非对象项触发 each item in the sequence must be a mapping.。ParseGraph 整体返回错误,ProcessChunkExtract 将此切片记录为 GRAPH_EXTRACT_FAILED。同一数组里的合法节点和关系不会写入。

Expected Behavior

可以考虑先在模型端使用受支持的结构化输出或更明确的 schema,再对返回结果逐项校验。如果数组中有可独立验证的规范节点和关系,保留这些条目,并记录丢弃项数量及部分增强结果。纯无效数组和无效 JSON 保持可诊断的失败语义,避免把模型输出异常统一标成成功。合法空数组仍代表无关系可抽取。

WeKnora Version

v0.9.0 / f17ee8a8,并核对官方 main@77ac9d7b5b57936e28695b23d7a37c9609c57fe3 的同一分支。

Deployment Method

Docker Compose

Operating System

Linux

Relevant Logs

Synthetic signature: GRAPH_EXTRACT_FAILED / each item in the sequence must be a mapping.

Related Issues

#1113 处理围栏和 JSON 提取,#3600 处理无可抽取内容时的散文输出,#2256 处理对象字段别名,#5302 处理上传者可见的状态。此问题发生在合法 JSON 数组中,规范对象与非对象混在一起的场景。

Confirmation

  • [x] I have searched existing issues and confirmed this is a new one

lynnlase avatar Nov 09 '26 05:11 lynnlase