fex(kb):知识库数据清洗针对pdf含有大量图片ocr清洗超时问题优化;perf(chat):问答回复点击doc移动端无法预览问题优化

This commit is contained in:
runny committed 2026-06-08 13:47:46 +08:00
1 parent 0890c79070
commit 900a13722c
8 files changed
+170 -18

No files matched your search

+16 -1
View File
@@ -10,6 +10,21 @@ _RAPID_OCR_ENGINE = None
_PDF_PAGE_IMAGE_MAX_EDGE = 1800
def _is_meaningful_ocr_line(text: str) -> bool:
token = re.sub(r"\s+", "", text or "")
if not token or re.fullmatch(r"[\W_]+", token):
return False
cjk_count = len(re.findall(r"[\u4e00-\u9fff]", token))
alnum_count = len(re.findall(r"[A-Za-z0-9]", token))
if cjk_count >= 2:
return True
if cjk_count >= 1 and len(token) >= 2:
return True
if alnum_count >= 5:
return True
return len(token) >= 4
def _decode_data_uri_image(data_uri: str):
m = re.match(r"^data:image/[^;]+;base64,(.+)$", data_uri or "", re.DOTALL)
if not m:
@@ -120,7 +135,7 @@ def run(
continue
txt = str(it[1]).strip()
conf = float(it[2])
if txt and conf >= min_confidence:
if txt and conf >= min_confidence and _is_meaningful_ocr_line(txt):
lines.append(txt)
if lines:
text = "OCR_TEXT:\n" + "\n".join(f"- {x}" for x in lines)