Skip to content

fix(rag): assign unique IDs after recursive chunk expansion - #1466

Open
LJK-ikun wants to merge 1 commit into
VoltAgent:mainfrom
LJK-ikun:fix/recursive-chunk-ids
Open

LJK-ikun wants to merge 1 commit into
VoltAgent:mainfrom
LJK-ikun:fix/recursive-chunk-ids

Conversation

@LJK-ikun

@LJK-ikun LJK-ikun commented Oct 21, 2026 •

Copy link
Copy Markdown

PR Checklist

  • The commit message follows the conventional commit guidelines.

Bugs / Features

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.

View guided diff

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.

@changeset-bot

changeset-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bf10da0

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 Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ffe56833-685b-40b1-8ba7-59a6c0342809
📥 Commits

Reviewing files that changed from the base of the PR and between 72a46c7 and bf10da0.

📒 Files selected for processing: 3
  • .changeset/unique-recursive-chunk-ids.md
  • packages/rag/src/__tests__/recursive-chunker.spec.ts
  • packages/rag/src/chunkers/recursive-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.

📝 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.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low

Possibly related issues

Suggested reviewers: omeraplak

Merge Risk: ⚪ Minimal · up to bf10d

No actionable merge-blocking risk was identified in the reviewed change.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: assigning unique IDs after recursive chunk expansion.
Description check Passed 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 Passed 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 Passed 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 Passed 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@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] rag: recursive chunk expansion returns duplicate IDs

1 participant