Skip to content

fix(chunk): report chunk size in runes after postprocess - #22317

Open
laoyyu wants to merge 1 commit into
infiniflow:mainfrom
laoyyu:fix/chunk-size-runes
Open

laoyyu wants to merge 1 commit into
infiniflow:mainfrom
laoyyu:fix/chunk-size-runes

Conversation

@laoyyu

@laoyyu laoyyu commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary

PostprocessOperator.Execute re-indexes the chunks it emits and recomputes ChunkData.Size with len(content), i.e. bytes. Every other measurement in internal/parser/chunk is in runes: splitByLength writes a rune count into Size, mergeChunks compares against a rune target_size, filterChunks applies a rune min_length, and split_test.go asserts Size == utf8.RuneCountInString(content).

So enabling any postprocess option (merge or filter) silently changed the reported size of non-ASCII chunks: 知识点 came back with Size = 9 instead of 3, and ragflow-cli chunk printed that inflated number as "Chunk size".

Fix

Re-index with RuneCount so the unit stays consistent with the rest of the package.

Test

Added TestPostprocessSizeCountsRunes in internal/parser/chunk/postprocess_test.go. It fails on the current code (Size = 9, want 3) and passes with the fix.

go test ./internal/parser/chunk/ -count=1
ok  ragflow/internal/parser/chunk

The postprocess stage re-indexed the chunks it emits and set Size with
len(content), i.e. bytes, while every other place in the package measures a
chunk in runes: splitByLength fills Size with a rune count, mergeChunks
compares against a rune budget and filterChunks applies a rune min_length.

A CJK chunk therefore came back from a pipeline with postprocess enabled three
times longer than the same chunk without it (9 instead of 3 for "知识点"),
and ragflow-cli printed that inflated value as the chunk size.
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Postprocessing now records each output chunk’s size as a rune count instead of a byte count. Sequential indexing remains unchanged. A regression test checks the size of the three-rune CJK text 知识点.

Changes: Chunk Size

Layer / File(s) Summary
Rune-based size and regression coverage
internal/parser/chunk/postprocess.go, internal/parser/chunk/postprocess_test.go
PostprocessOperator.Execute sets each output chunk’s Size to its rune count and retains sequential indexes. A regression test checks that postprocessing 知识点 produces a size of 3.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: yuzhichang

Merge Risk: Minimal · up to 0db92

Reported chunk sizes for non-ASCII content now count characters instead of bytes, which keeps them consistent with other chunk measurements. A regression test covers the change. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: postprocess now reports chunk size in runes instead of bytes. It matches the raw summary, the PR description, and the objectives. It follows the conventional-commit st…
Description check Passed The description covers the problem, the fix, and the test. It explains the byte-versus-rune inconsistency, gives a concrete example (知识点 reported as 9 instead of 3), and lists the test and its result.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: postprocess now reports chunk size in runes instead of bytes. It matches the raw summary, the PR description, and the objectives. It follows the conventional-commit style and is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description covers the problem, the fix, and the test. It explains the byte-versus-rune inconsistency, gives a concrete example (知识点 reported as 9 instead of 3), and lists the test and its result. It uses a Summary heading, which matches the repository template. The template asks only for a summary, and this description provides one with background context.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

A rabbit counts each rune with care,
Three CJK marks are tallied there.
The chunks keep their indexes in line,
Their sizes now match each rune’s sign.
A test checks the count is right,
Then hops away into the night.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ebb6fe24-cd2b-472a-a8ed-2c26520a8d6b
Commits

Reviewing files that changed from the base of the PR and between 5cc37f8 and 0db92dc.

Files selected for processing: 2

  • internal/parser/chunk/postprocess.go
  • internal/parser/chunk/postprocess_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator
  • Checked the complete two-file diff at 0db92dcba794f0ffc5d86b0d9e8c011868947ce1. Size now stays in the same rune unit used by length splitting and the merge/filter budgets; sequential indexing is unchanged.
  • The actual internal/parser/chunk package passed in 20 fresh processes with CGO_ENABLED=0 GOMAXPROCS=4 go test -p 4 ./internal/parser/chunk -count=1. I also exercised ASCII, CJK, emoji, combining characters and empty content across no-option, filter and merge configurations in a temporary local test. The unchanged package has 37 passing test cases and no skips.
  • Negative control: reverting only the new RuneCount assignment to len makes the committed CJK regression and the local Unicode probe fail in two separate runs (9 bytes versus 3 runes). Restoring this head passes again; no review changes were committed.
  • Native validation remains a caveat: bash build.sh --test ./internal/parser/chunk/... stopped because ld.lld is unavailable. The package tests above exercise the real Go chunk code without CGO; I did not verify a native server build or the CLI display. No blocker found in this scoped size correction, not a blanket approval or merge recommendation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants