Skip to content

fix(rag): drop blank chunks in TextChunker output - #3734

Open
aiyili wants to merge 2 commits into
agentscope-ai:mainfrom
aiyili:fix/chunker-blank-chunks
Open

aiyili wants to merge 2 commits into
agentscope-ai:mainfrom
aiyili:fix/chunker-blank-chunks

Conversation

@aiyili

@aiyili aiyili commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #3305

What

  • Blank input (isBlank) now returns an empty chunk list instead of List.of("").
  • Whitespace-only chunks within mixed text are dropped after chunking; surviving chunks keep their original content and order.
  • TextReader needs no change: createDocuments numbers chunkIds by index over the (now-filtered) chunk list, so IDs stay sequential.

Downstream effect: blank Documents no longer enter SimpleKnowledge.addDocuments, so no embedding request is spent on nothing-to-embed content.

- 空白输入(isBlank)返回空列表:空/纯空白块流入 RAG 管道会产生
  无可嵌入内容的 Document,部分 embedding 提供方直接拒绝
- 拼块结果过滤纯空白块,保留存活块的内容与顺序(chunkId 由
  TextReader.createDocuments 对过滤后列表顺序编号,天然连续)
testChunkEmptyText 与 testEmptyText 断言旧行为(空文本产出 1 个空
Document);契约已改为空白输入不产出块/文档,同步更新并新增
whitespace-only 中间块被丢弃的用例。
@aiyili

aiyili commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

The two CI failures are existing assertions of the old contract — TextChunkerTest.testChunkEmptyText and TextReaderTest.testEmptyText expected empty input to produce one empty chunk/Document. Updated both to the new contract (blank input → no chunks / no documents) and added the whitespace-only-middle-chunk case from the issue ("abc def" → ["abc", "def"]). 4bb9b52, formatting-clean.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TextChunker emits blank chunks into the RAG embedding pipeline

1 participant