fix(knowledge): 修复 general parser 分块超限导致 LightRAG 索引失败#670
Merged
xerrors merged 1 commit intoxerrors:mainfrom May 3, 2026
Merged
fix(knowledge): 修复 general parser 分块超限导致 LightRAG 索引失败#670xerrors merged 1 commit intoxerrors:mainfrom
xerrors merged 1 commit intoxerrors:mainfrom
Conversation
naive_merge 不保证输出 chunk 在 token 上限内,当单行内容超过 chunk_token_num 时会产生超大 chunk,导致 LightRAG 报错 "Chunk token length 3140 exceeds chunk_token_size 1200"。 - nlp.py: 新增 hard_split_by_token_limit 公共硬切分函数 - general.py: 新增 _ensure_chunk_token_limit 兜底保护 - laws.py: 删除本地重复函数,改用 nlp 版本(DRY)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
naive_merge在单行内容超过chunk_token_num时产生超大 chunk,导致 LightRAG 报错Chunk token length 3140 exceeds chunk_token_size 1200的问题nlp.hard_split_by_token_limit()公共硬切分函数(从laws.py提升,DRY)general.py添加_ensure_chunk_token_limit()兜底保护Background
LightRAG 上游有多个相关 issue(HKUDS/LightRAG#2387、#102、#2126)均未合并修复,需在预分块阶段自行兜底。
Test plan
pytest test/unit/test_chunking_token_limit.py— 16/16 passed