fix(rag): split paragraphs with Windows line endings
GT
4d ago+25+25+01234567890123456789-1-1-0123456789
PR Checklist
- The commit message follows the Conventional Commit guidelines.
Bugs / Features
- Related issue linked.
- Regression tests added.
- Docs added or updated.
- Patch changeset added for
@voltagent/rag.
What is the current behavior?
RecursiveChunker treats a blank line made of LF characters as a paragraph boundary. The same text with CRLF or CR produces one chunk for two short paragraphs.
What is the new behavior?
Recognize LF, CRLF, and CR when splitting paragraphs. CRLF counts as one line break. The original text supplies the chunk offsets, and single line breaks inside a paragraph stay intact.
Fixes #1566.
Notes for reviewers
- On the upstream code, the new CRLF and CR cases failed and the LF case passed.
- With the fix, 50 RAG tests passed across 19 files. A smoke test against the built public ESM entry verified paragraph contents and source ranges for all three line endings.
- Biome, changeset formatting, focused strict TypeScript checks, and the CommonJS, ESM, and declaration builds passed.
- The package-wide TypeScript check reports the same three diagnostics on the upstream revision and on this branch, in
code-chunker.spec.tsandlate-chunker.spec.ts.
Codex assisted with investigation, implementation, tests, and drafting. All checks above were run locally without a model or external service.
Summary by cubic
Fixes RecursiveChunker so blank lines with CRLF or CR endings split paragraphs the same way LF endings already did.
- The previous split regex only matched LF pairs, so text using CRLF or CR merged separate short paragraphs into one chunk.
- The new regex treats
\r\nas a single line break, preserves source offsets, and leaves single line breaks inside a paragraph intact. - Adds regression tests covering LF, CRLF, and CR, and a patch changeset for
@voltagent/rag. Fixes #1566.
Summary by CodeRabbit
- Bug Fixes
- Paragraphs separated by blank lines are now preserved during recursive text chunking when content uses LF, CRLF, or CR line endings.
- Chunk offsets continue to correspond to the matching content in the original text.