Skip to content

fix(rag): split paragraphs with Windows line endings - #1567

Open
gtdd123 wants to merge 1 commit into
VoltAgent:mainfrom
gtdd123:fix/rag-crlf-paragraphs
Open

gtdd123 wants to merge 1 commit into
VoltAgent:mainfrom
gtdd123:fix/rag-crlf-paragraphs

Conversation

@gtdd123

@gtdd123 gtdd123 commented Nov 25, 2026 •

Copy link
Copy Markdown

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.ts and late-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\n as 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 [BUG] RecursiveChunker merges paragraphs separated by Windows line endings #1566.

Written for commit fc94678. Summary will update on new commits.

View guided diff

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.

@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fc94678

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/rag Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The recursive chunker now preserves paragraph boundaries when text uses LF, CRLF, or CR line endings. Regression tests check paragraph content and chunk offsets against the original text.

Changes: Paragraph splitting

Layer / File(s) Summary
Line-ending-aware paragraph splitting
packages/rag/src/utils/text.ts, packages/rag/src/__tests__/recursive-chunker.spec.ts, .changeset/rag-paragraph-line-endings.md
splitIntoParagraphs recognizes blank-line separators using LF, CRLF, and CR. Tests check paragraph content and chunk offsets. The changeset declares a patch release for @voltagent/rag.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: omeraplak

Merge Risk: Minimal · up to fc946

This fix makes paragraph splitting work for text with Windows (CRLF) or old Mac (CR) line endings while keeping chunk offsets relative to the original text. The change is small and tested, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(rag): split paragraphs with Windows line endings" matches the main change. The changeset and code update splitIntoParagraphs in packages/rag/src/utils/text.ts to treat LF, CRLF, and…
Description check Passed The description follows the repository template. It includes the PR checklist, the bug/feature checklist with linked issue, regression tests, and changeset, plus the current behavior, new behavior wit…
Linked Issues check Passed [#1566] requires a blank line made of LF, CRLF, or CR to separate paragraphs in RecursiveChunker, with chunk offsets that refer to the original text. At the reviewed head, splitIntoParagraphs in packa…
Out of Scope Changes check Passed The PR changes three files according to the summary: .changeset/rag-paragraph-line-endings.md (patch changeset for @voltagent/rag), packages/rag/src/tests/recursive-chunker.spec.ts (regression tes…
Full details: Title check

Explanation

The title "fix(rag): split paragraphs with Windows line endings" matches the main change. The changeset and code update splitIntoParagraphs in packages/rag/src/utils/text.ts to treat LF, CRLF, and lone CR as paragraph breaks. The title names the bug area (@voltagent/rag), the behavior, and the cause. It is concise and follows a conventional commit style.

Full details: Description check

Explanation

The description follows the repository template. It includes the PR checklist, the bug/feature checklist with linked issue, regression tests, and changeset, plus the current behavior, new behavior with 'Fixes #1566', and reviewer notes. The 'Docs added or updated' item is unchecked, which is acceptable for a non-critical item. The description states the problem and the fix clearly and gives verification details.

Full details: Linked Issues check

Explanation

[#1566] requires a blank line made of LF, CRLF, or CR to separate paragraphs in RecursiveChunker, with chunk offsets that refer to the original text. At the reviewed head, splitIntoParagraphs in packages/rag/src/utils/text.ts splits on /(?:\r?\n|\r(?!\n)){2,}/. This pattern treats CRLF as one line break, matches bare CR pairs, and matches mixed forms such as \r\n\r. A single CRLF or LF inside a paragraph does not match, so it stays intact. Offsets come from text.indexOf on the trimmed part, and text is sliced from the original input, so the original line endings are preserved. The PR summary reports a new parameterized test in recursive-chunker.spec.ts covering \n, \r\n, and \r, which checks paragraph contents and offsets. That test and the smoke test were not read directly. The wiring from RecursiveChunker to splitIntoParagraphs was not confirmed by a repository read, because the history lookup for packages/rag/src/chunker/recursive-chunker.ts returned no result. Nothing in the evidence contradicts the requirement. No non-coding requirement applies beyond the changeset, which the PR adds.

Full details: Out of Scope Changes check

Explanation

The PR changes three files according to the summary: .changeset/rag-paragraph-line-endings.md (patch changeset for @voltagent/rag), packages/rag/src/tests/recursive-chunker.spec.ts (regression test for the three line endings and offsets), and packages/rag/src/utils/text.ts (paragraph split regex). Each change connects directly to #1566. The changeset is the release note for the fix. The test supports the required behavior. The text.ts change is the fix itself. No unrelated change was identified. The whole-PR diff for text.ts could not be read, so the base content comparison relies on the head file and the summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7fad33d4-d8de-498a-8869-0d85abac35f0
Commits

Reviewing files that changed from the base of the PR and between e9fc599 and fc94678.

Files selected for processing: 3

  • .changeset/rag-paragraph-line-endings.md
  • packages/rag/src/__tests__/recursive-chunker.spec.ts
  • packages/rag/src/utils/text.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

View guided diff | Re-trigger cubic

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] RecursiveChunker merges paragraphs separated by Windows line endings

1 participant