[BUG] rag: sentence content can cross the reported sentence boundaries
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- nodejs, typescript
Research direction
Start by locating SentenceChunker and reading how it turns sentence match ranges into chunk content. Reproduce the reported boundary mismatch with the default tokenizer, then add regression coverage for that example and sentence overlap. Done means content matches each reported source range while sentence grouping, token accounting, and overlap behavior remain unchanged.
Written by the indexing model from the issue text.
Description
Describe the bug
SentenceChunker computes character ranges from sentence matches, but constructs content using token counts of independently encoded prefixes as indexes into the full document's BPE tokens. Prefix tokenization is not additive: a token can extend beyond a sentence boundary. Returned content can include part of the next sentence and omit part of its own reported source range. This affects sentence-level context grouping and consumers that use the returned range to highlight retrieved content.
Steps To Reproduce
On current main 72a46c76b4507e1f98b41d5050a92bd30587eb70, using the real default tokenizer:
import { SentenceChunker } from "@voltagent/rag";
const text = "foo.bar baz.qux end.";
const chunks = new SentenceChunker().chunk(text, { maxTokens: 3 });
console.log(chunks.map(c => ({
content: c.content,
source: text.slice(c.start, c.end),
})));
Actual pairs are foo.bar / foo., baz.qu / bar baz., and x end. / qux end.. A second reproduction, First sentence.\n\nSecond sentence! Last one? at the same budget, puts the two newlines in the first chunk's content while its range excludes them; the next range includes the newlines while its content excludes them.
Expected behavior
Sentence chunk content should match the already-computed sentence character range. It should not cut into an adjacent sentence because an independently encoded prefix has a different token boundary. Existing sentence grouping, token accounting and overlap options should stay unchanged.
Packages
@voltagent/rag 1.0.2 source at the baseline above; Node.js 24.19.0 on Windows, js-tiktoken 1.0.21 (within the declared range). Reproduced through exported public classes, without a model/provider or patched collaborators.
Additional Context
I plan to work on a scoped fix that slices the original text by the computed sentence range, with regressions using the real default BPE tokenizer and sentence overlap. This follows the contribution guide's request to mention work in an issue before implementation. This is independent of #1466 (recursive IDs) and #1468 (table delegation offsets); neither of those changes SentenceChunker's content construction. Exact SentenceChunker/prefix/boundary searches and the current open-PR list found no active fix for this defect. No downstream production incident is claimed.
AI assistance: Codex performed the source inspection and local reproduction under LJK-ikun's direction. Automated verification is distinguished from human review.
- Dominant language
- TypeScript
- Stars
- 10.9k
- Forks
- 1.3k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 2
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from VoltAgent/voltagent
-
[BUG] rag: recursive chunk expansion returns duplicate IDsPossibly taken @LJK-ikun claimed this 2 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
[BUG] rag: detectFormat never recognizes top-level JSON arrays, so "auto" chunking skips the JSON chunkerPossibly taken @Theater-ahyeon claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
[BUG] updateAllPackages missing command injection protection present in updateSinglePackagePossibly taken @octo-patch claimed this 181 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
VoltAgent/voltagent#1205 · 3 comments · 6 reactions ·
Maintainers usually reply within 1 day
-
[BUG] Elysia server provider test suite entirely broken — stale mocks after Node.js HTTP refactorPossibly taken @Koushik-Salammagari claimed this 161 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
VoltAgent/voltagent#1204 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
Maintainers usually reply within 1 day
All issues in VoltAgent/voltagent
Similar issues
-
area: image-engine bug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
snapotter-hq/SnapOtter#3885 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 3 days
-
pending triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug P3 UI/UX
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
openclaw/openclaw#182077 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day