[Bug]: TokenChunker never terminates when chunking overlap >= size (no validation of size/overlap)

オープン 初心者向け
#2,593 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

評価

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

調査の方向性

graphrag_chunking/token_chunker.py の TokenChunker.__init__ と、split_text_on_tokens のウィンドウループから始めてください。ここでは chunk_size - chunk_overlap のステップがゼロや負になる可能性があります。あわせて graphrag_chunking/chunking_config.py の size と overlap フィールドも確認してください。呼び出し回数を数え、1000 回で停止する decode のラッパーで再現します。完了の条件は、size が正でない場合、または overlap が 0 <= overlap < size の範囲外の場合にコンストラクタが ValueError を送出することです。等しい値、より大きい値、ゼロ、負の値についての単体テストを追加してください。

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

説明

Do you need to file an issue?
  • I have searched the existing issues and this bug is not already filed.
  • My model is hosted on OpenAI or Azure. If not, please look at the "model providers" issue and don't file a new one here. (Not applicable: the bug is in chunking, before any model call.)
  • I believe this is a legitimate bug, not just a question. If this is a question, please use the Discussions area.
Describe the bug

split_text_on_tokens advances the window with start_idx += chunk_size - chunk_overlap (token_chunker.py#L65). When overlap == size the step is 0, so cur_idx never reaches len(input_tokens) and the while loop keeps appending chunks to result without ever exiting. When overlap > size the step is negative, start_idx moves backwards, and the loop also never terminates. size <= 0 has the same problem.

ChunkingConfig.size and ChunkingConfig.overlap are bare int fields with no validators (chunking_config.py#L25-L32), and TokenChunker.__init__ does not check them either (token_chunker.py#L20-L29). A settings.yaml with, say, size: 100 and overlap: 100 therefore gives a chunking step that hangs with no error message. The config value is operator-controlled, so this is a usability/robustness problem, not a security one.

A negative overlap is also accepted and silently skips tokens between consecutive windows.

Steps to reproduce
from graphrag_chunking.token_chunker import TokenChunker

enc = lambda s: [ord(c) for c in s]
dec = lambda t: "".join(chr(x) for x in t)
TokenChunker(size=10, overlap=10, encode=enc, decode=dec).chunk("abcdefghijklmnopqrstuvwxyz")  # never returns

The same happens with overlap=15 or size=0.

I did not let the real call run to exhaustion. Instead I ran split_text_on_tokens with a decode wrapper that raises after 1000 calls: for both overlap=10 and overlap=15 (size 10) the cap was hit, i.e. the loop kept calling decode and appending chunks well past the 3 windows that 26 characters need. In the real loop result grows without bound.

Expected Behavior

A clear ValueError at config load / chunker construction when the values are invalid: require size > 0 and 0 <= overlap < size.

GraphRAG Config Used
chunking:
  type: tokens
  size: 100
  overlap: 100
Logs and screenshots

No output: the process does not return.

Additional Information
  • GraphRAG Version: 3.3.0 (graphrag-chunking at 5faaaf4f)
  • Operating System: macOS
  • Python Version: 3.11
  • Related Issues: #2589 (a different TokenChunker bug, about decoding at token boundaries, in the same function)

Suggested minimal fix: validate in ChunkingConfig (Field(gt=0) on size, Field(ge=0) on overlap, plus a validator enforcing overlap < size) and raise ValueError in TokenChunker.__init__ so direct library use is covered too, with unit tests for equal, greater, zero and negative values. Happy to open a PR if that approach is fine.

主要言語
Python
スター
36.6k
フォーク
3.9k
平均マージ
4日 11時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

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

microsoft/graphrag のほかの issue

microsoft/graphrag の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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