[Bug]: TokenChunker never terminates when chunking overlap >= size (no validation of size/overlap)
维护者通常 5 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 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 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/graphrag 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
microsoft/graphrag#2626 · 1 条评论 ·
维护者通常 5 天内回复
-
[Bug]: response_format_json_object=True is silently dropped, so JSON mode never reaches the model未关闭bug triage
难度 2/5 1-3 小时 新手友好度 72/100
microsoft/graphrag#2625 · 1 条评论 ·
维护者通常 5 天内回复
-
难度 1/5 1 小时以内 新手友好度 95/100
维护者通常 5 天内回复
-
[Bug]: JsonCache.get() crashes with unhandled AttributeError on non-dict or invalid envelope JSON payloads可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/graphrag#2614 · 2 条评论 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
microsoft/graphrag#2594 · 1 条评论 ·
维护者通常 5 天内回复
查看 microsoft/graphrag 的全部 Issue
相似的 Issue
-
bug
难度 1/5 1 小时以内 新手友好度 78/100
splunk/security_content#4418 ·
维护者通常 1 天内回复
-
[Bug / Enhancement]: Improve teleop_robot CLI with configurable timeout, robust input validation, and clean ROS shutdown可能已有人在做 @muskan-creates352 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 3 天内回复
-
bug(pipelines): shortcode stripping deletes text between a {{< >}} shortcode and the next {{% %}}可能已有人在做 @Ashborne-lab 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
kubeflow/docs-agent#293 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
Imbad0202/academic-research-skills#1093 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
pierreaubert/gpui-toolkit#114 ·
维护者通常 1 天内回复