Wiring BM25 to Chinese text with split(): four tokenizer variants, 2/12 versus 10/12 recall
Environment: Python 3.12.11, jieba 0.42.1, a hand-written BM25 (k1=1.2, b=0.75). Corpus: body text of the 20 Chinese articles on this site, split on blank lines, passages with at least 60 Han characters kept — 89 passages total. Queries: 12 hand-written natural-language paraphrases, single annotator, 1–2 labelled passages each. Metrics: Recall@k and MRR@10. Fully deterministic, no random seed. Verified 2026-11-28.
Port an English BM25 implementation to Chinese, and the usual move is text.lower().split(). Harmless in English; in Chinese it turns an entire sentence into one token. Rather than leave the conclusion at "that can't work in theory", I ran it: four tokenization variants over the same corpus and the same queries.
Result: nine of twelve queries score zero across the corpus
| Tokenization | Vocabulary | Tokens per passage | Queries with zero score everywhere | Recall@1 | Recall@5 | MRR@10 |
|---|---|---|---|---|---|---|
split() whitespace | 1,035 | 15.6 | 9/12 | 1/12 | 2/12 | 0.114 |
| Character 1+2-grams | 5,553 | 193.9 | 0/12 | 7/12 | 10/12 | 0.683 |
| jieba accurate mode | 1,964 | 70.5 | 0/12 | 4/12 | 8/12 | 0.522 |
| jieba search mode | 2,033 | 73.6 | 0/12 | 4/12 | 8/12 | 0.510 |
The "zero score everywhere" column is the number worth staring at: for 9 of 12 queries, every BM25 score across the 89 passages is exactly 0. Nothing is mis-ranked — nothing can produce a non-zero score at all. The returned top-10 is just index order; the retriever is not working.
The 3 queries that do score depend on the Latin words they carry: RRF, rerank, token. In other words, the only surviving channel under whitespace tokenization is Latin script; the Chinese part never participates. The single Recall@1 hit is precisely the query containing RRF.
Why character 1+2-grams beat segmentation
This row is counter-intuitive: no segmentation at all, just Han characters plus adjacent character pairs, reaches 7/12 Recall@1 against jieba's 4/12. The reason is not tokenizer quality but query shape: all 12 queries are paraphrases, not restatements of the source. Word-level matching demands the exact same word appear; change one character ("标称窗口" versus "窗口上限") and it misses. Character pairs tolerate partial overlap: the bigram "窗口" survives on both sides.
jieba's search mode — described upstream as splitting long words again on top of accurate mode, "improving recall, suited to search-engine tokenization" — did not help on this sample: Recall@1 stayed 4/12 and MRR dropped from 0.522 to 0.510. Adding sub-words fixes word-form mismatch, not vocabulary mismatch.
One failure that shows the mechanism plainly: the query "长上下文到底贵在哪一笔账上" is segmented into 长 / 上下文 / 到底 / 贵在 / 哪 / 一笔 / 账上. "上下文" appears in 22 of 89 passages and "哪" in 9 — both are diluted to near-zero discrimination, and the target passage never enters the top 10.
The cost: 2.8x the vocabulary, 2.75x the passage length
Character 1+2-grams buy that accuracy with index size: vocabulary 5,553 versus 1,964 (2.8x), average tokens per passage 193.9 versus 70.5 (2.75x). Bigger postings, more scoring work, more memory and latency. At millions of passages this multiplier is not a rounding error.
A minimal reproducible implementation
import re, math, jieba
from collections import Counter
LAT = re.compile(r'[a-z0-9][a-z0-9_.\-]*')
def tok_ws(t): # the counter-example: one token per sentence
return re.findall(r'[^\s]+', t.lower())
def tok_char2(t): # latin words + single Han chars + adjacent pairs
out = LAT.findall(t.lower())
for run in re.findall(r'[\u4e00-\u9fff]+', t):
out += list(run) + [run[i:i+2] for i in range(len(run)-1)]
return out
def bm25(docs, tokfn, k1=1.2, b=0.75):
toks = [tokfn(d) for d in docs]
tf = [Counter(x) for x in toks]
dl = [len(x) for x in toks]; avg = sum(dl) / len(dl)
df = Counter(); [df.update(c.keys()) for c in tf]
idf = {w: math.log(1 + (len(docs)-n+0.5)/(n+0.5)) for w, n in df.items()}
def score(q, i):
return sum(idf.get(w, 0) * tf[i][w] * (k1+1) /
(tf[i][w] + k1*(1-b+b*dl[i]/avg)) for w in tokfn(q) if tf[i][w])
return scoreThe idf term is log(1 + (N − df + 0.5)/(df + 0.5)), matching the implementation documented for Lucene's BM25Similarity; k1=1.2 and b=0.75 are its defaults. Swap in your own 89 passages and 12 queries and the numbers should reproduce.
A second-order damage: it skews RRF fusion
Whitespace tokenization is not merely "that branch does nothing". In a hybrid retriever the BM25 branch still returns 10 results — ranked by index order, unrelated to the query. RRF reads ranks, not scores, so it hands those 10 passages a 1/(k+rank) vote each, pushing genuinely relevant vector results down the list. A broken branch is not silent; it keeps voting.
How to choose
- Paraphrased natural-language queries (end-user questions, support tickets): character 1+2-grams, or a word + bigram mix. Do not count on word-level exact matches.
- Queries carrying model names, part numbers, error codes (
gpt-6.2-sol, order ids, error codes): keep a word-level branch plus a raw exact-string branch; bigrams shred long codes. - Tight index budget: build with bigrams, measure vocabulary and latency, then try the mixed variant. Decide both on the same 200 labelled queries.
Closing
The sample here is small — 89 passages, 12 queries, one annotator — so it indicates a direction, not a leaderboard. But it names a common failure precisely: Chinese BM25 quality does not depend on how fancy the tokenizer is, it depends on whether your query and your documents share the same string. Under whitespace tokenization that probability is near zero, and those 9 zero-score queries are the evidence.