Skip to content

fix(rag): preserve structurally empty Word paragraph boundaries - #2969

Open
liugy789 wants to merge 2 commits into
agentscope-ai:mainfrom
liugy789:fix/wordreader-structural-empty-paragraphs
Open

fix(rag): preserve structurally empty Word paragraph boundaries#2969
liugy789 wants to merge 2 commits into
agentscope-ai:mainfrom
liugy789:fix/wordreader-structural-empty-paragraphs

Conversation

@liugy789

@liugy789 liugy789 commented Sep 3, 2026

Copy link
Copy Markdown

AgentScope-Java Version

2.0.3-SNAPSHOT (current main)

Description

Word represents a blank line as an empty w:p paragraph. WordReader now preserves that structural boundary so paragraph chunking receives \n\n between surrounding text.

The blank-paragraph check is deliberately structural: a paragraph containing only w:pPr properties remains blank, while a paragraph with any other OOXML body element (for example a run containing w:br) is not treated as an extra blank-line boundary. This prevents trim-normalized but structurally non-empty paragraphs from changing chunk boundaries.

Testing

  • WordReaderTest: 15 tests, 0 failures, 0 errors.
  • Includes real Apache POI round-trip coverage for empty paragraphs, w:pPr-only paragraphs, and break-only paragraphs.
  • spotless:check and git diff --check pass.

Checklist

  • Code formatting verified with mvn spotless:check
  • All relevant tests are passing
  • Javadoc comments follow project conventions; no public API changed
  • Related documentation is not required for this internal behavior fix
  • Code is ready for review

…ader

In .docx files a blank line is stored as an empty <w:p> element.
WordReader.getDataBlocks() skipped empty paragraphs entirely, so
consecutive paragraphs were joined with a single "\n". As a result
TextChunker's PARAGRAPH_SEPARATOR regex (\n\s*\n) never matched and
the PARAGRAPH split strategy degenerated into character-based hard
splitting at chunkSize, cutting paragraphs mid-sentence.

Append a "\n" for blank paragraphs under the same merge conditions
as non-empty text, so that adjacent paragraphs are joined with
"\n\n" and the paragraph boundary is preserved for chunking.
@CLAassistant

CLAassistant commented Sep 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...java/io/agentscope/core/rag/reader/WordReader.java 84.61% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@zouyx zouyx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sign ICLA pls bro.

@liugy789

liugy789 commented Sep 5, 2026

Copy link
Copy Markdown
Author

sign ICLA pls bro.

Thanks! I’ve signed the ICLA now, and the CLA check is green.

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.

3 participants