From 8b6dd6a5c2b3380f8713776f0a5230952abd7e0b Mon Sep 17 00:00:00 2001 From: shawnxiao105-afk Date: Wed, 13 May 2026 11:47:50 +0800 Subject: [PATCH] fix: guard whitespace-only chunks before embedding (#13938) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem When parsing DOCX files with many tables, DeepDOC generates chunks containing only empty HTML table tags, such as: ```html
``` After the regex cleanup at `task_executor.py:584`, this becomes `" "` (whitespace only). The guard at line 585 (`if not c`) only catches empty strings `""`, but whitespace strings are truthy in Python and pass through. When sent to Zhipu `embedding-3` API, it rejects them with error 1213: `未正常接收到prompt参数`. ## Root Cause ```python c = re.sub(r"]{0,12})?>", " ", c) if not c: # ← only catches "", not " " / "\n" / "\t" c = "None" ``` Verified with Zhipu `embedding-3`: | Input | Result | |---|---| | `""` | error 1213 | | `" "` | error 1213 | | `"\n"` | error 1213 | | `"None"` | OK | ## Fix ```diff - if not c: + if not c.strip(): c = "None" ``` ## Testing Reproduced with a 678KB DOCX file (166 tables, 270 chunks). Chunk #89 is the empty table above. After fix, `"None"` is sent instead and embedding succeeds. --------- Co-authored-by: Kevin Hu --- rag/svr/task_executor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rag/svr/task_executor.py b/rag/svr/task_executor.py index b31057bc08..548d88ab1b 100644 --- a/rag/svr/task_executor.py +++ b/rag/svr/task_executor.py @@ -640,7 +640,8 @@ async def embedding(docs, mdl, parser_config=None, callback=None): if not c: c = d["content_with_weight"] c = re.sub(r"]{0,12})?>", " ", c) - if not c: + if not c.strip(): + logging.debug("embedding(): normalized whitespace-only chunk to placeholder 'None' (len=%d)", len(c)) c = "None" cnts.append(c)