Repository navigation
fix(nlp): prevent dotted-number cross-references from being classified as headings in Laws chunker - #16626
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR updates Chinese cross-reference handling so multi-level numeric references ending in ChangesCross-reference classification
Estimated code review effort: 1 (Trivial) | ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rag/nlp/__init__.py`:
- Around line 211-215: The new not_bullet pattern for three-or-more-level clause
cross-references is too broad because the `中` branch matches legitimate headings
that merely start with that character. Tighten the regex in
`rag/nlp/__init__.py` so `r"[0-9]+(\.[0-9]+){2,}[的中]"` only excludes the real
body-text cross-reference form, and verify the change against the `not_bullet`
rule by keeping `的`/`中` handling specific enough to avoid headings like
`3.1.1中华人民共和国民法典` and `3.1.1中国人民银行`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 605008c1-53de-4b07-932f-a299e6c40552
📒 Files selected for processing (1)
rag/nlp/__init__.py
|
Thanks for the quick PR. I tested the patch against the minimal reproduction in #16595, but it still returns 3 With this patch applied, the minimal case still outputs: I think the reason is that not_bullet() is used by bullets_category(), but tree_merge().get_level() directly matches |
|
Good catch, @HAOHANZHOU — you're right. Fixed in the latest push: added the same |
…d as headings
In the Laws chunker (and any code using bullets_category/tree_merge),
a line like "11.5.14.2的试验适用于ST12外护套。" was matched as a
section heading by the BULLET_PATTERN regex, causing the Laws chunker
to emit header-only chunks and split cross-reference body text into
separate chunks.
Root cause: BULLET_PATTERN uses re.match (prefix-only), so
"[0-9]{,2}\.[0-9]{,2}\.[0-9]{,2}\.[0-9]{,2}" matches "11.5.14.2"
at the start of "11.5.14.2的试验...", and not_bullet() had no rule
to reject it.
Fix: add a pattern to not_bullet() that identifies a three-or-more-level
dotted numeric prefix immediately followed by the Chinese possessive/
locative particles 的 or 中 as a body-text cross-reference rather than
a heading:
r"[0-9]+(\.[0-9]+){2,}[的中]"
This correctly classifies:
- "11.5.14.2的试验..." → cross-reference (not_bullet = True)
- "11.5.14.1 通则" → heading (not_bullet = False, space before CJK)
- "3.2.1说明" → heading (not_bullet = False, no 的/中)
- "3.1.1中的规定" → cross-ref (not_bullet = True)
- "1.2的规定" → unchanged (only 2-level, below {2,} threshold)
Fixes infiniflow#16595
21d9abc to
685c723
Compare
|
Correction: the previous reply was inaccurate. The prior commit only added the pattern to Just pushed the actual fix to - if re.match(title, text.strip()):
+ if re.match(title, text.strip()) and not not_bullet(text):Verified against all three lines from the minimal reproduction:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16626 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|

Summary
The Laws chunker (and any code using
bullets_category/tree_merge) was misclassifying Chinese cross-references as section headings, causing:Root Cause
BULLET_PATTERNusesre.match(prefix-only), so patterns like[0-9]{,2}\\.[0-9]{,2}\\.[0-9]{,2}\\.[0-9]{,2}match the leading11.5.14.2in"11.5.14.2的试验适用于ST12外护套。". The existingnot_bullet()had no rule to reject these cross-references.Fix
Add one pattern to
not_bullet():r"[0-9]+(\.[0-9]+){2,}[的中]"This identifies a three-or-more-level dotted numeric prefix immediately followed by the Chinese possessive/locative particles
的or中as body-text cross-reference (not a heading).Verification
11.5.14.2的试验适用于ST12外护套。11.5.14.3的试验应按4.4 c)…11.5.14.1 通则3.2.1说明3.1.1中的规定Fixes #16595