cd /news/developer-tools/chunk-lite-token-aware-text-chunking… · home topics developer-tools article
[ARTICLE · art-112686] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

chunk-lite: token-aware text chunking for RAG pipelines that doesn't cut mid-sentence

Developer Tejas released chunk-lite, an open-source JavaScript library for token-aware text chunking in RAG pipelines that respects sentence and paragraph boundaries to avoid cutting mid-thought. The library returns start and end offsets for traceability, supports custom tokenizers, and includes 26 tests. It is available on GitHub and npm.

read1 min views1 publishedAug 27, 2026

Package #5 in my small open-source series, and the first one with a direct RAG/AI angle.

Every RAG pipeline starts the same way: take a long document, split it into pieces small enough to embed, and hope the split points don't wreck the meaning inside each piece. A naive fixed-size split has no idea where a sentence or paragraph actually ends, so it happily cuts a chunk in half mid-thought - and a chunk that starts "...and that's why the deadline was moved" with no antecedent for "that" embeds as a blurry average of two unrelated ideas. It retrieves worse for both.

chunk-lite makes the boundary-aware version the default.

import { chunkText } from 'chunk-lite';

const chunks = chunkText(longDocument, {
  maxTokens: 300,
  overlapTokens: 50,
});

chunks[0];
// { text: "...", startOffset: 0, endOffset: 1180, tokenCount: 298, index: 0 }

A few design notes:

startOffset

/endOffset

into the source text, so you can always trace a retrieved chunk back to exactly where it came from - for citations, highlighting, or re-chunking later without losing the mapping.tokenCounter

(tiktoken, a model's own endpoint, whatever) if you need exact counts.Fully typed, zero required runtime dependencies, 26 tests covering overlap correctness, sentence/paragraph boundaries, oversized-sentence fallback, and custom tokenizer injection.

GitHub: https://github.com/tejas821/chunk-lite

npm: npm i chunk-lite

Full reasoning on chunk boundaries and the overlap trade-off is in the repo's CASE_STUDY.md. Feedback welcome, especially if you've hit a boundary case this doesn't handle well.

── more in #developer-tools 4 stories · sorted by recency
── more on @chunk-lite 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/chunk-lite-token-awa…] indexed:0 read:1min 2026-08-27 ·