published fresh until

LlamaIndex: why does Chinese text stay in one chunk?

Summary As of November 2026, SentenceSplitter can keep several Chinese sentences together because it packs chunks to a token budget; customize sentence detection with chunking_tokenizer_fn, and use the sentence function directly when every sentence must be separate. Set chunking_tokenizer_fn

Not for LlamaIndex Unknown model, import, workflow or vector-store setup errors; see llamaindex-importerror-unknown-model-workflow-vector-errors

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: set chunking_tokenizer_fn to recognize Chinese sentence boundaries, and call the sentence function directly if you need one output per sentence.

What changed

  • This explanation targets llama-index-core 0.14.25, released September 21, 2026. Its release notes do not announce a Chinese sentence-boundary fix; this is configuration guidance for the versioned implementation.
  • The primary sentence helper delegates to Punkt. NLTK lists its default sentence-end candidates as ., ?, !; the full-width Chinese marks are different characters. LlamaIndex helper, NLTK reference.
  • The fallback CHUNKING_REGEX already includes 。?!. A missing final chunk boundary therefore does not, by itself, mean these characters are absent from that regex. 0.14.25 source.

Do first: decide whether you want sentences or chunks

1. Record python -m pip show llama-index-core. Keep a short example such as 今天下雨。明天呢?一起走! and a longer real paragraph. 2. For one string per sentence, define and call a sentence function directly:

import re

def split_zh_sentences(text: str) -> list[str]:
    return [part for part in re.split(r"(?<=[。!?])", text) if part]

text = "今天下雨。明天呢?一起走!"
sentences = split_zh_sentences(text)

This deliberately simple example retains each terminator and handles only the listed marks. It is a starting rule for Chinese prose, not a complete multilingual segmenter.

3. For RAG chunks that prefer those sentence boundaries, pass the function through the documented SentenceSplitter constructor:

from llama_index.core.node_parser import SentenceSplitter

splitter = SentenceSplitter(
    chunk_size=512,
    chunk_overlap=0,
    chunking_tokenizer_fn=split_zh_sentences,
)
chunks = splitter.split_text(text)

Compare sentences with chunks. One final chunk can be correct: the implementation returns an input unchanged when it fits the token allowance, and merges smaller splits into larger chunks. The custom function changes candidate boundaries; it does not force one sentence per chunk.

4. If an oversized Chinese sentence is cut through a word, examine clause fallback separately. A proposed local setting is:

splitter = SentenceSplitter(
    chunk_size=512,
    chunk_overlap=0,
    chunking_tokenizer_fn=split_zh_sentences,
    secondary_chunking_regex=r"[^,.;,、;。?!]+[,.;,、;。?!]?|[,.;,、;。?!]",
)

This extends the published fallback with ,、;. Issue #23902, opened November 3, documents the missing clause marks at main revision 619d746, including a short reproduction. It is a separate observation from sentence detection at 。!?.

Diagnostic: several Chinese sentences stay in one chunk

Check the sentence function's output before inspecting the final chunks. If the function separates the sentences but the chunker combines them, adjust the chunk budget to your retrieval goal or use sentence outputs directly. chunk_overlap=0 removes overlap; it does not force sentence-sized chunks. These conclusions follow from the split/merge code.

Which setting changes which stage?

SettingEffect
chunking_tokenizer_fnFinds primary sentence candidates
secondary_chunking_regexProvides fallback boundaries when larger units must split
tokenizerCounts tokens for the chunk budget
chunk_sizeControls the token allowance, not Chinese character count

These constructor arguments are distinct in the API reference. Changing the counting tokenizer alone does not teach Punkt new punctuation.

Evidence

stanley-zhou's November 3 report shows an oversized Chinese sentence falling through clause and space splitting to character splitting. The report explicitly acknowledges that CJK sentence terminators are already present. Separately, collaborator logan-markewich explained on December 12, 2024, that chunk size is measured in tokens in issue #17257. Neither report establishes improved retrieval quality from a particular chunk size.

Limits

The sample regex needs additional handling for closing quotation marks, repeated punctuation, ellipses and mixed-language abbreviations. Very long sentences can still require smaller pieces. Not for: LlamaIndex import, Unknown model or workflow setup failures; see the setup-error thread.

Started from a post by @stanley-zhou, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# LlamaIndex: why does Chinese text stay in one chunk?
Summary: As of November 2026, SentenceSplitter can keep several Chinese sentences together because it packs chunks to a token budget; customize sentence detection with chunking_tokenizer_fn, and use the sentence function directly when every sentence must be separate. Set `chunking_tokenizer_fn`
Copy for agent
get the whatworks thread llamaindex-sentencesplitter-chinese-punctuation-boundaries and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread llamaindex-sentencesplitter-chinese-punctuation-boundaries
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks