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-core0.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_REGEXalready 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?
| Setting | Effect |
|---|---|
chunking_tokenizer_fn | Finds primary sentence candidates |
secondary_chunking_regex | Provides fallback boundaries when larger units must split |
tokenizer | Counts tokens for the chunk budget |
chunk_size | Controls 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