You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(rag): report original offsets for split fenced code - #1534
The proposed commit message follows Conventional Commits.
Bugs / Features
Related issue(s) linked. Reproduced directly on main.
Tests for the changes have been added.
Docs have been added or updated.
A patch changeset for @voltagent/rag has been added.
What is the current behavior?
When the parser returns no blocks and a fenced block exceeds maxTokens, CodeChunker returns token offsets relative to the fence body. With prose before the fence, using text.slice(chunk.start, chunk.end) can return prose while chunk.content contains code. The line and column metadata is also relative to the fence body.
What is the new behavior?
Translate the split chunks' start and end offsets to the original document and use those offsets to compute line and column metadata. Regression tests exercise LF and CRLF documents with prose before the fence.
Notes for reviewers
Both new regression cases fail on upstream main and pass with this patch.
vitest run --typecheck passed all 49 RAG tests in 20 files.
OpenAI Codex assisted with reproduction, implementation and local validation.
Summary by cubic
Fixes CodeChunker reporting token offsets relative to the fence body when a fenced code block exceeds maxTokens and is split by the fallback. Offsets and line/column metadata now point to the original document, so text.slice(chunk.start, chunk.end) returns the code content instead of possibly prose before the fence. Adds regression tests for LF and CRLF documents with prose before the fence.
Written for commit 68fb472. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Corrected position reporting for code chunks created when oversized code blocks are split as a fallback. Chunk offsets now point to the corresponding text in the original document, with line and column positions consistent across LF and CRLF line endings. This makes it easier to locate each chunk’s content in the source document.
No actionable comments were generated in the recent review.
Walkthrough
Token-fallback chunks from fenced code now report offsets and metadata positions relative to the full input document. Tests cover LF and CRLF input when the parser returns no results. A Changeset declares a patch release for @voltagent/rag.
Token-fallback chunk offsets and metadata positions now include the code segment’s starting offset. Tests check chunks, source slices, and line and column positions for LF and CRLF input. The Changeset declares a patch release for @voltagent/rag.
Split fenced-code chunks now report offsets relative to the original document, so slicing the document returns the chunk's code. The change is small and tested, and no merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix in the rag package: CodeChunker reports original-document offsets for split fenced code. This matches the main change in the code-chunker.ts summary and the PR objectives, so t…
Description check
The description follows the template. It fills in the checklist, the current and new behavior sections, and reviewer notes. It leaves the 'Related issue(s) linked' and 'Docs have been added or updated…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the fix in the rag package: CodeChunker reports original-document offsets for split fenced code. This matches the main change in the code-chunker.ts summary and the PR objectives, so the title is related to the main change and specific enough to scan.
Full details: Description check
Explanation
The description follows the template. It fills in the checklist, the current and new behavior sections, and reviewer notes. It leaves the 'Related issue(s) linked' and 'Docs have been added or updated' items unchecked and gives no 'fixes (issue)' reference. The changeset and test items are checked, and the behavior is explained clearly, so the description is mostly complete.
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: d2c8bc4e-53cc-4da9-ae1e-2337739d944d
Commits
Reviewing files that changed from the base of the PR and between e9fc599 and 68fb472.
Files selected for processing: 3
.changeset/fenced-code-document-offsets.md
packages/rag/src/chunkers/code-chunker.spec.ts
packages/rag/src/chunkers/code-chunker.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Bugs / Features
@voltagent/raghas been added.What is the current behavior?
When the parser returns no blocks and a fenced block exceeds
maxTokens,CodeChunkerreturns token offsets relative to the fence body. With prose before the fence, usingtext.slice(chunk.start, chunk.end)can return prose whilechunk.contentcontains code. The line and column metadata is also relative to the fence body.What is the new behavior?
Translate the split chunks' start and end offsets to the original document and use those offsets to compute line and column metadata. Regression tests exercise LF and CRLF documents with prose before the fence.
Notes for reviewers
vitest run --typecheckpassed all 49 RAG tests in 20 files.OpenAI Codex assisted with reproduction, implementation and local validation.
Summary by cubic
Fixes
CodeChunkerreporting token offsets relative to the fence body when a fenced code block exceedsmaxTokensand is split by the fallback. Offsets and line/column metadata now point to the original document, sotext.slice(chunk.start, chunk.end)returns the code content instead of possibly prose before the fence. Adds regression tests for LF and CRLF documents with prose before the fence.Written for commit 68fb472. Summary will update on new commits.
Summary by CodeRabbit