fix(外观专利): 覆盖率分母改为解析全行并启用阈值,修「904 行只检 1 行仍报成功」
三处叠加导致塌陷不可见: 1. validateCompleteLlmCoverage 收到的 receivedRows 已经按「拿到结果」过滤过分母, 覆盖率恒为 100%,整片结果丢失也测不出来;改为传解析出的全部行。 2. 判定被放在 filterReceivedParsedRows 之后,整个源文件结果全空时会先 continue 掉, 连判都不判;移到循环开头,zip 少一个文件不能还报成功。 3. 阈值本身写死在 `boolean enforceCompleteLlmCoverage = false` 上,是死代码。 改为配置 aiimage.appearance-patent.llm-coverage-min-ratio,默认 0.5 只拦塌陷级 (现网正常任务实测约 0.91)。 完整性判定另拆出 hasDeliverableLlmResult:现网正常返回里 patent 恒为空串, 拿它当必要条件会把每个任务都判成不完整。 isTechnicalLlmFailure 去掉按 "coze" 子串匹配——品牌名 "Cozee Bay" 会被判成调用失败、 真结论被清空;Coze 工作流特征串随直连改造一并移除。
This commit is contained in:
@@ -56,4 +56,13 @@ public class AppearancePatentProperties {
|
||||
|
||||
/** 单个外观专利源文件最多解析的有效数据行数,防止 POI 用户模型撑爆堆。 */
|
||||
private int maxParseRows = 50000;
|
||||
|
||||
/**
|
||||
* 组装结果文件时要求的 LLM 覆盖率下限(0~1,<=0 关闭)。
|
||||
* 低于该比例说明大批行根本没拿到结论(如 2026-09-20 任务 28805:904 行只检了 1 行却报成功),
|
||||
* 此时判任务失败并由失败通知告警,而不是交付一份看着完整、实际是复制结论的表。
|
||||
* 默认 0.5 只拦塌陷级异常;生产正常任务实测约 0.91(28798:723 行 658 行有结论),
|
||||
* 需要更严时调高,调到 1.0 即要求全行有结论。
|
||||
*/
|
||||
private double llmCoverageMinRatio = 0.5D;
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import com.nanri.aiimage.modules.task.model.entity.TaskFileJobEntity;
|
||||
|
||||
/**
|
||||
* APPEARANCE_PATENT 结果文件 Job Handler(04 注册表)。
|
||||
* process 返回 Service 的 boolean(false=等待 coze 异步结果,Worker 保持运行心跳);
|
||||
* process 返回 Service 的 boolean(false=等待 LLM 异步结果,Worker 保持运行心跳);
|
||||
* cleanup 委托 cleanupResultFileJob;支持异步 offload;owner scoped。
|
||||
*/
|
||||
public class AppearancePatentResultFileJobHandler implements ResultFileJobHandler {
|
||||
|
||||
+36
-10
@@ -2049,6 +2049,9 @@ public class AppearancePatentTaskService {
|
||||
for (SourceRows item : sourceRows) {
|
||||
Map<String, AppearancePatentResultRowDto> resultMap =
|
||||
loadPersistedResultRowsForRowsWithRetry(task.getId(), item.rows());
|
||||
// 覆盖率先于「本文件无结果就跳过」判定:整源文件的 LLM 结果全丢(分片被跳过、
|
||||
// 结果清空)时覆盖率是 0%,必须在这里判掉,不能让 zip 少一个文件还报任务成功。
|
||||
validateCompleteLlmCoverage(task.getId(), item.rows(), resultMap);
|
||||
List<AppearancePatentParsedRowVo> receivedRows = filterReceivedParsedRows(item.rows(), resultMap);
|
||||
if (receivedRows.isEmpty()) {
|
||||
resultMap.clear();
|
||||
@@ -2061,7 +2064,6 @@ public class AppearancePatentTaskService {
|
||||
reasonRows += resultMap.values().stream()
|
||||
.filter(this::hasReasonFields)
|
||||
.count();
|
||||
validateCompleteLlmCoverage(task.getId(), receivedRows, resultMap);
|
||||
conclusionPropagated += GroupResultPropagator.propagateByGroup(
|
||||
receivedRows,
|
||||
AppearancePatentParsedRowVo::getDisplayId,
|
||||
@@ -2242,10 +2244,15 @@ public class AppearancePatentTaskService {
|
||||
return receivedRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖率判定:分母必须是**解析出的全部行**(只滤掉不需要送检的行),不能是已经拿到结果的行。
|
||||
* 传已过滤的集合会让分母恒等于分子 —— 整片结果丢失(chunk payload 缺失被跳过、
|
||||
* 客户端漏回传)时覆盖率仍是 100%,阈值形同虚设。
|
||||
*/
|
||||
private void validateCompleteLlmCoverage(Long taskId,
|
||||
List<AppearancePatentParsedRowVo> receivedRows,
|
||||
List<AppearancePatentParsedRowVo> parsedRows,
|
||||
Map<String, AppearancePatentResultRowDto> resultMap) {
|
||||
if (receivedRows == null || receivedRows.isEmpty()) {
|
||||
if (parsedRows == null || parsedRows.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
@@ -2255,25 +2262,44 @@ public class AppearancePatentTaskService {
|
||||
int expectedRows = 0;
|
||||
int missingRows = 0;
|
||||
List<String> sampleAsins = new ArrayList<>();
|
||||
for (AppearancePatentParsedRowVo parsedRow : receivedRows) {
|
||||
for (AppearancePatentParsedRowVo parsedRow : parsedRows) {
|
||||
if (!hasPromptFields(parsedRow)) {
|
||||
continue;
|
||||
}
|
||||
expectedRows++;
|
||||
AppearancePatentResultRowDto resultRow = findResultRow(parsedRow, resultMap);
|
||||
if (resultRow == null || !hasCompleteLlmResult(resultRow)) {
|
||||
if (resultRow == null || !hasDeliverableLlmResult(resultRow)) {
|
||||
missingRows++;
|
||||
if (sampleAsins.size() < 5) {
|
||||
sampleAsins.add(firstNonBlank(parsedRow.getAsin(), firstNonBlank(parsedRow.getDisplayId(), "")));
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean enforceCompleteLlmCoverage = false;
|
||||
if (enforceCompleteLlmCoverage && expectedRows > 0 && missingRows > 0) {
|
||||
log.warn("[appearance-patent] incomplete llm coverage taskId={} expectedRows={} missingRows={} samples={}",
|
||||
taskId, expectedRows, missingRows, sampleAsins);
|
||||
throw new BusinessException("LLM 结果不完整:缺少 " + missingRows + "/" + expectedRows + " 条检测结果,请等待重试或重新运行任务");
|
||||
if (expectedRows <= 0) {
|
||||
return;
|
||||
}
|
||||
int resolvedRows = expectedRows - missingRows;
|
||||
double coverage = (double) resolvedRows / expectedRows;
|
||||
double minCoverage = properties.getLlmCoverageMinRatio();
|
||||
if (missingRows > 0) {
|
||||
log.warn("[appearance-patent] incomplete llm coverage taskId={} expectedRows={} missingRows={} coverage={} samples={}",
|
||||
taskId, expectedRows, missingRows, String.format("%.2f%%", coverage * 100), sampleAsins);
|
||||
}
|
||||
if (minCoverage > 0 && coverage + 1e-9 < minCoverage) {
|
||||
throw new BusinessException("LLM 结果不完整:仅 " + resolvedRows + "/" + expectedRows
|
||||
+ " 行拿到检测结论(低于 " + Math.round(minCoverage * 100) + "% 覆盖率下限),请重新运行任务");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 交付口径的完整性判定:结论依赖标题维度、外观维度和最终结论三列。
|
||||
* 与 {@link #hasCompleteLlmResult} 的区别是不看 patentRisk —— 现网正常返回里 patent
|
||||
* 恒为空串(见 AppearancePatentLlmClient 的 LlmResult 构造),拿它当必要条件会把每个任务都判成不完整。
|
||||
*/
|
||||
private boolean hasDeliverableLlmResult(AppearancePatentResultRowDto row) {
|
||||
return hasUsableLlmField(row.getTitleRisk())
|
||||
&& hasUsableLlmField(row.getAppearanceRisk())
|
||||
&& hasUsableLlmField(row.getConclusion());
|
||||
}
|
||||
|
||||
private boolean hasCompleteLlmResult(AppearancePatentResultRowDto row) {
|
||||
|
||||
+5
-2
@@ -256,11 +256,14 @@ public final class AppearancePatentSheetBuilder {
|
||||
return normalized.contains("侵权") ? "成功" : "失败";
|
||||
}
|
||||
|
||||
/**
|
||||
* 只按当前直连 LLM 客户端会写入的文案判定技术性失败。早期 Coze 工作流特征串已随直连改造移除:
|
||||
* 按 "coze" 子串匹配会把品牌词 "Cozee Bay" 误判成调用失败,真结论被清空。
|
||||
*/
|
||||
public static boolean isTechnicalLlmFailure(String value) {
|
||||
String normalized = normalize(value).toLowerCase(Locale.ROOT);
|
||||
return normalized.contains("coze") || normalized.contains("llm")
|
||||
return normalized.contains("llm")
|
||||
|| normalized.contains("结果不完整")
|
||||
|| normalized.contains("工作流节点执行超限")
|
||||
|| normalized.contains("调用超时")
|
||||
|| normalized.contains("timeout");
|
||||
}
|
||||
|
||||
+8
-4
@@ -356,13 +356,17 @@ class AppearancePatentTaskServiceDelegationTest {
|
||||
|
||||
@Test
|
||||
void test_llm_failure_semantics_kept_in_sheet_builder() {
|
||||
assertTrue(AppearancePatentSheetBuilder.isTechnicalLlmFailure("coze 工作流节点执行超限"));
|
||||
assertTrue(AppearancePatentSheetBuilder.isTechnicalLlmFailure("LLM http 403: insufficient_user_quota"));
|
||||
assertTrue(AppearancePatentSheetBuilder.isTechnicalLlmFailure("调用超时"));
|
||||
assertFalse(AppearancePatentSheetBuilder.isTechnicalLlmFailure("无风险"));
|
||||
// 品牌词不是失败特征:早先按 "coze" 子串匹配,把品牌 "Cozee Bay" 当成调用失败清掉了真结论
|
||||
assertFalse(AppearancePatentSheetBuilder.isTechnicalLlmFailure("Cozee Bay"));
|
||||
AppearancePatentResultRowDto row = new AppearancePatentResultRowDto();
|
||||
row.setError("coze 调用超时");
|
||||
row.setTitleRisk("coze 调用超时");
|
||||
row.setError("LLM http 503: This model is currently overloaded");
|
||||
row.setTitleRisk("LLM http 503: This model is currently overloaded");
|
||||
row.setConclusion("");
|
||||
assertEquals("coze 调用超时", AppearancePatentSheetBuilder.userFacingLlmCellValue(row, row.getTitleRisk()));
|
||||
assertEquals("LLM http 503: This model is currently overloaded",
|
||||
AppearancePatentSheetBuilder.userFacingLlmCellValue(row, row.getTitleRisk()));
|
||||
assertEquals("失败", AppearancePatentSheetBuilder.userFacingStatus(row),
|
||||
"LLM 技术失败没得出判定 → 状态失败(旧口径按结论非空误判为成功)");
|
||||
}
|
||||
|
||||
+4
-4
@@ -200,14 +200,14 @@ class AppearancePatentSheetBuilderTest {
|
||||
try (Workbook wb = new XSSFWorkbook()) {
|
||||
AppearancePatentParsedRowVo p = parsedRow("2_1", "B01A", "US", "t", "", "");
|
||||
AppearancePatentResultRowDto r = resultRow("2_1", "B01A", "US");
|
||||
r.setTitleRisk("coze 调用超时");
|
||||
r.setError("coze 工作流节点执行超限");
|
||||
r.setConclusion("coze 调用超时");
|
||||
r.setTitleRisk("调用超时");
|
||||
r.setError("LLM http 503: This model is currently overloaded");
|
||||
r.setConclusion("调用超时");
|
||||
AppearancePatentSheetBuilder.buildResultSheet(wb, List.of(p), Map.of(
|
||||
AppearancePatentSheetBuilder.rowKey(r), r));
|
||||
|
||||
Row data = wb.getSheet("外观专利检测结果").getRow(1);
|
||||
assertEquals("coze 工作流节点执行超限", data.getCell(9).getStringCellValue(),
|
||||
assertEquals("LLM http 503: This model is currently overloaded", data.getCell(9).getStringCellValue(),
|
||||
"LLM 技术失败展示错误信息");
|
||||
assertEquals("失败", data.getCell(12).getStringCellValue(),
|
||||
"LLM 技术失败没得出判定,状态判失败");
|
||||
|
||||
Reference in New Issue
Block a user