Repository navigation
test(chunker): lock non-text segments as standalone on merge (closes #17889) - #17896
yuzhichang merged 1 commit into
Conversation
… for infiniflow#17889) Add TestTokenChunker_InvokeJSONPayload_KeepsNonTextStandalone asserting that a [text, table, text, image, text] JSON payload yields five standalone chunks with the correct doc_type_kwd order. The Go merge already enforces this via itemDocType (common.go:138), chunkFromItem (token.go:756) and mergeByTokenSizeFromJSON (token.go:1050, token.go:991). Closes infiniflow#17889.
📝 WalkthroughWalkthroughThis pull request adds one regression test for ChangesJSON payload chunking regression
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 `@internal/ingestion/component/chunker/token_test.go`:
- Around line 252-259: Update the token chunking test around the existing item
sequence in token_test.go to cover directly adjacent non-text items by adding a
table/image pair with no text between them, or create a focused dedicated test
for that case. Use the existing chunking assertions to verify the two items stay
in document order and remain standalone chunks with their respective table and
image types, while keeping the current text/non-text coverage intact.
🪄 Autofix
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 Plus
Run ID: 14ed45c5-3d94-4ddb-9594-21a63e82d2c7
📒 Files selected for processing (1)
internal/ingestion/component/chunker/token_test.go
| // text, table, text, image, text — in document order. | ||
| items := []map[string]any{ | ||
| {"text": "Alpha section text content", "doc_type_kwd": "text"}, | ||
| {"text": "<table>caption</table>", "doc_type_kwd": "table"}, | ||
| {"text": "Beta section text content", "doc_type_kwd": "text"}, | ||
| {"text": "[image]", "doc_type_kwd": "image"}, | ||
| {"text": "Gamma section text content", "doc_type_kwd": "text"}, | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add an adjacent table and image case.
The current sequence separates table and image with a text item. It verifies text/non-text boundaries, but it cannot detect a merge of directly adjacent non-text items. Add an adjacent table/image pair, or add a dedicated test, and assert their order and standalone chunk types. The stated issue objective requires this case.
🤖 Prompt for 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.
In `@internal/ingestion/component/chunker/token_test.go` around lines 252 - 259,
Update the token chunking test around the existing item sequence in
token_test.go to cover directly adjacent non-text items by adding a table/image
pair with no text between them, or create a focused dedicated test for that
case. Use the existing chunking assertions to verify the two items stay in
document order and remain standalone chunks with their respective table and
image types, while keeping the current text/non-text coverage intact.
|
LGTM |
Background
Issue #17889 asks that, when merging adjacent segments, the chunker first
checks each segment's type and only merges text segments — table,
image, and any other non-text type must each remain a standalone chunk
and must never be merged with a neighbouring segment.
Why this PR closes #17889 (no Go code change required)
After tracing the Go TokenChunker, the requirement is already satisfied
on the structured (JSON / chunks) path. The type-aware rule is enforced at
three layers in
internal/ingestion/component/chunker/:common.go:138itemDocTypederives the type fromdoc_type_kwd(
"table"->"table","image"->"image", anything else ->"text").It does not depend on the
ck_typefield being populated, so the typesurvives even when only
doc_type_kwdis set (e.g. upstreamTitle/Group/Hierarchy chunks).
token.go:756chunkFromItememits a non-text item as a single standalonechunk before the merge loop ever runs.
token.go:1050mergeByTokenSizeFromJSONforces any non-text chunkstandalone (
if ck.CKType != "text"); andtoken.go:991starts a freshtext chunk after a non-text chunk, so text on either side of a
table/image is never merged across it.
The only path without type information is the raw markdown/text/html string
path (
PayloadFormatMarkdown/Text/HTML), where the input is by contract anuntyped string and
applyChildrenDelimhard-codesCKType: "text"somerging is correct. There is no non-text segment to merge there, so this is
out of #17889's scope (which is about the merge logic).
Why the Python side is deferred
The Python
naiveparser path does not thread ack_typethrough tomerge_paragraphs/naive_merge/naive_merge_with_images(
rag/nlp/__init__.py): its parsers emit flat(text, pos)sections plus aparallel
section_imageslist, and the type-aware_merge_cksrule(
rag/nlp/__init__.py:1749) is only wired into the docx path. Propagatingck_typeend-to-end across every Python parser is a large refactor, so it isintentionally not part of this PR. The Go engine is the active ingestion
path, and it already honors the rule.
This PR
Adds a regression-lock (characterization) test, not a fix:
TestTokenChunker_InvokeJSONPayload_KeepsNonTextStandalonefeeds a[text, table, text, image, text]structured payload and asserts itproduces exactly five standalone chunks in the order
text, table, text, image, text— proving tables/images stay standaloneand text on either side is not merged across them.
Verified green:
Related