Repository navigation
Description
Describe the bug
RecursiveChunker.chunk() returns duplicate chunk IDs when a long paragraph is split into several sentence groups. Three different returned chunks can all have id: "recursive-0". An ingestion application that keys records by the returned ID cannot distinguish those chunks; this report does not claim to have tested a particular vector database.
Steps To Reproduce
Using the unchanged public exports of @voltagent/rag on upstream main at 72a46c76b4507e1f98b41d5050a92bd30587eb70:
import { RecursiveChunker, whitespaceTokenizer } from "@voltagent/rag";
const chunks = new RecursiveChunker(whitespaceTokenizer).chunk(
"Alpha one. Beta two. Gamma three. Delta four.",
{ maxTokens: 4 },
);
console.log(chunks.map(({ id, content }) => ({ id, content })));
console.log(new Set(chunks.map((chunk) => chunk.id)).size, chunks.length);Actual output:
recursive-0: Alpha one. Beta two.
recursive-0: Beta two. Gamma three.
recursive-0: Gamma three. Delta four.
1 3
Expected behavior
IDs should distinguish each chunk returned by one call, including sentence groups and token fallback chunks across paragraphs. Chunk contents and overlap behavior should stay the same.
Packages
@voltagent/rag 1.0.2 source on current main; Node.js 24.19.0, Windows. Reproduced with the actual package source and its declared js-tiktoken dependency, not a recreated implementation. No model, API key, or external service is involved.
Additional Context
The sentence-group expansion computes IDs from chunks.length before any expanded chunks are appended. I plan to assign final IDs after expansion and add public-API regressions for sentence-only and mixed sentence/token output. Searched existing issues and open PRs for RecursiveChunker and chunk IDs; did not find a matching fix. PR #893 introduces a separate document utility package, while #1459 and #1463 address JSON handling.
AI disclosure: Codex investigated and reproduced this under LJK-ikun's direction. This report describes the observed local output; it does not assert independent human testing.
Activity