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): assign unique IDs after recursive chunk expansion - #1466
Docs added / updated (not needed: restores distinct IDs without changing the API).
Patch Changeset added for @voltagent/rag.
What is the current behavior?
Splitting one paragraph into several sentence groups gives each group the same recursive-N ID. A mixed sentence/token expansion also reuses IDs, because the outer chunks array has not grown while flatMap expands the paragraph. The public reproduction in #1465 returns three different chunks with only one distinct ID.
What is the new behavior?
Assign final IDs after the complete paragraph expansion, using the existing chunk count plus each expanded chunk's index. Sentence groups and token fallback chunks receive distinct IDs within a call. Splitting and overlap behavior are unchanged.
Notes for reviewers
Validation on Windows with Node.js 24.19.0, against upstream 72a46c76b4507e1f98b41d5050a92bd30587eb70:
New regressions on unchanged runtime: 2 failed, with unique/total counts of 1/3 and 4/8; the existing 2 recursive tests passed.
Fixed RAG suite: 45 tests passed across 18 files (vitest run --config packages/rag/vitest.config.mts packages/rag/src/__tests__).
Biome check of both changed TypeScript files: passed.
Strict TypeScript check of both changed TypeScript files: passed.
Package tsup build: CommonJS, ESM and declaration builds passed.
git diff --check: passed.
The package-wide tsc --project packages/rag/tsconfig.json --noEmit reports 3 pre-existing errors in code-chunker.spec.ts and late-chunker.spec.ts. The identical errors reproduce on the untouched upstream checkout with the same dependencies. They are outside this fix. This is not a claim that the full package type check passes.
Dependencies were installed in an isolated tool directory using versions compatible with the repo; tests execute the actual source. No implementation was recreated and no runtime collaborator was patched. Full monorepo tests and live model/vector-store integration were not run. CI has not been verified.
AI assistance: Codex authored, ran and inspected this focused change under LJK-ikun's direction. The report distinguishes local automated validation from human review; it does not assert independent human testing.
Summary by cubic
Fixes duplicate recursive-N IDs in @voltagent/rag when one paragraph expands into multiple chunks. IDs are now assigned after the full paragraph expansion, so sentence groups and token fallback chunks each get a distinct ID. Splitting and overlap behavior are unchanged; regression tests added.
Written for commit bf10da0. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Recursive document chunking now assigns unique, sequential IDs to expanded sentence and token chunks, preventing identifier collisions across multiple texts.
Improved consistency when chunks are created through different recursive expansion paths.
Tests
Added coverage confirming that recursively expanded chunks receive distinct IDs under constrained token limits.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
RecursiveChunker assigns sequential IDs to expanded sentence and token chunks after expansion. Parameterized tests check ID uniqueness, and a patch changeset records the update.
Changes: Recursive chunk ID uniqueness
Layer / File(s)
Summary
Assign and verify expanded chunk IDs packages/rag/src/chunkers/recursive-chunker.ts, packages/rag/src/__tests__/recursive-chunker.spec.ts, .changeset/unique-recursive-chunk-ids.md
The chunker assigns sequential IDs after sentence and token expansion. Parameterized tests check that each returned chunk has a unique ID. A patch changeset documents the change.
No actionable merge-blocking risk was identified in the reviewed change.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly and concisely describes the primary change: assigning unique IDs after recursive chunk expansion.
Description check
The description covers the checklist, linked issue, tests, changeset, current behavior, new behavior, validation results, and reviewer notes. It also explains the documented pre-existing type-check er…
Linked Issues check
Issue #1465 requires distinct IDs for all chunks returned by one RecursiveChunker.chunk() call, including sentence groups and token fallback chunks, while preserving content and overlap behavior. In…
Out of Scope Changes check
The changed files contain only the recursive ID fix, focused regression tests, and a patch changeset for @voltagent/rag. These changes directly support issue #1465. No unrelated product behavior or …
Docstring Coverage
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Description check
Explanation
The description covers the checklist, linked issue, tests, changeset, current behavior, new behavior, validation results, and reviewer notes. It also explains the documented pre-existing type-check errors and unverified CI scope.
Full details: Linked Issues check
Explanation
Issue #1465 requires distinct IDs for all chunks returned by one RecursiveChunker.chunk() call, including sentence groups and token fallback chunks, while preserving content and overlap behavior. In packages/rag/src/chunkers/recursive-chunker.ts, expanded chunks receive IDs after expansion with recursive-${chunks.length + idx}. This produces distinct sequential IDs across paragraphs and expansion paths. The existing splitting and overlap logic remains in place. recursive-chunker.spec.ts adds public-API regression coverage for sentence expansion and mixed sentence/token expansion.
Full details: Out of Scope Changes check
Explanation
The changed files contain only the recursive ID fix, focused regression tests, and a patch changeset for @voltagent/rag. These changes directly support issue #1465. No unrelated product behavior or unrelated package changes are shown. The repository diff operation was unavailable because changed blobs were missing, so this assessment uses the supplied change summary and the available head file contents.
Full details: Docstring Coverage
Explanation
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)
✨ 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.
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/rag.What is the current behavior?
Splitting one paragraph into several sentence groups gives each group the same
recursive-NID. A mixed sentence/token expansion also reuses IDs, because the outerchunksarray has not grown whileflatMapexpands the paragraph. The public reproduction in #1465 returns three different chunks with only one distinct ID.What is the new behavior?
Assign final IDs after the complete paragraph expansion, using the existing chunk count plus each expanded chunk's index. Sentence groups and token fallback chunks receive distinct IDs within a call. Splitting and overlap behavior are unchanged.
Notes for reviewers
Validation on Windows with Node.js 24.19.0, against upstream
72a46c76b4507e1f98b41d5050a92bd30587eb70:vitest run --config packages/rag/vitest.config.mts packages/rag/src/__tests__).tsupbuild: CommonJS, ESM and declaration builds passed.git diff --check: passed.tsc --project packages/rag/tsconfig.json --noEmitreports 3 pre-existing errors incode-chunker.spec.tsandlate-chunker.spec.ts. The identical errors reproduce on the untouched upstream checkout with the same dependencies. They are outside this fix. This is not a claim that the full package type check passes.Dependencies were installed in an isolated tool directory using versions compatible with the repo; tests execute the actual source. No implementation was recreated and no runtime collaborator was patched. Full monorepo tests and live model/vector-store integration were not run. CI has not been verified.
AI assistance: Codex authored, ran and inspected this focused change under LJK-ikun's direction. The report distinguishes local automated validation from human review; it does not assert independent human testing.
Summary by cubic
Fixes duplicate
recursive-NIDs in@voltagent/ragwhen one paragraph expands into multiple chunks. IDs are now assigned after the full paragraph expansion, so sentence groups and token fallback chunks each get a distinct ID. Splitting and overlap behavior are unchanged; regression tests added.Written for commit bf10da0. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Tests