[Bug]: Bm25 splits Tamil, Hindi, Sinhala and other words on their combining marks

オープン
#886 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

@Nipuna-Lakruwan がすでに取り組んでいます。

2026年11月19日 から。

  • #887 @Nipuna-Lakruwan による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
backend, search

調査の方向性

The issue identifies remove_non_alphanumeric and SimpleTokenizer as the two places that split combining marks, and links open PR #887 for this fix. Read those tokenizer paths and the proposed tests in the PR; verify Tamil and other listed scripts stay intact, while text without combining marks keeps its existing token ids.

索引モデルが issue の本文から書いたものです。

説明

What happened?

Qdrant/bm25 breaks words that contain combining marks into fragments. That covers Tamil (a supported language), Hindi, Sinhala, Bengali, Thai and Arabic with diacritics.

Two places strip the marks before the stemmer ever sees the words:

  • remove_non_alphanumeric uses [^\w\s];
  • SimpleTokenizer uses [^\w].

Python's \w does not include combining marks (Unicode categories Mn and Mc). The vowel signs and the virama in "தமிழ்" (Tamil) are therefore treated as separators, and the word becomes ["தம", "ழ"].

The fragments are shared by unrelated words, which causes false matches. With language="tamil", a query for "தமிழ்" (Tamil) also matches a document that only contains "தம்" (own) and "மழை" (rain):

from fastembed import SparseTextEmbedding

m = SparseTextEmbedding("Qdrant/bm25", language="tamil")
print(m.model.tokenizer.tokenize("தமிழ் மொழி அழகானது"))
# ['தம', 'ழ', 'ம', 'ழ', 'அழக', 'னத']   expected ['தமிழ்', 'மொழி', 'அழகானது']

tamil, rain = m.embed(["தமிழ் மொழி", "தம் ஊரில் மழை"])
query = next(m.query_embed("தமிழ்"))
print(set(query.indices) & set(rain.indices))   # not empty: the "rain" document matches

Other scripts, with disable_stemmer=True:

Input Tokens now Expected
हिन्दी भाषा (Hindi) ह न द भ ष हिन्दी भाषा
ශ්‍රී ලංකාව (Sinhala) ශ ර ල ක ව ශ්‍රී ලංකාව
كَتَبَ الطالب (Arabic, voweled) ك ت ب الطالب كَتَبَ الطالب

The Snowball Tamil stemmer never receives a whole word, so language="tamil" cannot work as intended.

What is the expected behaviour?

Combining marks (and the zero-width joiner and non-joiner used in Indic and Sinhala conjuncts) should stay inside the word, as nltk.wordpunct_tokenize and LangChain's BM25 preprocessing already do.

A minimal reproducible example

See above.

What Python version are you on? e.g. python --version

Python 3.12

FastEmbed version

v0.8.1 (also on main)

What os are you seeing the problem on?

MacOS

Relevant stack traces and/or logs

No response

I have a fix with tests ready and can open a PR. It would change token ids only for text that contains combining marks, so Latin-script English and other text without them hashes exactly as before.

主要言語
Python
スター
3.3k
フォーク
314
平均マージ
5日 7時間
マージ済み PR(30日)
23

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

qdrant/fastembed のほかの issue

qdrant/fastembed の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。