Skip to content

feat(go): drop empty and duplicate chunks in postprocess filter - #16049

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
Crystora:feat/go-chunk-filter-dedup
Jul 6, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
Crystora:feat/go-chunk-filter-dedup

Conversation

@Crystora

@Crystora Crystora commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

The Go chunk pipeline's PostprocessOperator filter stage (internal/ingestion/chunk/postprocess.go) only filtered by length (min_length/max_length). It could not drop empty/whitespace-only chunks or duplicate chunks — both standard RAG post-processing steps (blank chunks shouldn't be indexed; identical chunks waste embedding compute and add redundant retrieval results).

This adds two optional, default-off booleans to the filter config:

  • drop_empty — drop chunks whose content is empty or whitespace-only.
  • drop_duplicates — drop chunks whose exact content already appeared (order-preserving; the first occurrence is kept).

They compose with the existing length bounds and are reflected in String() for plan explainability. Also adds the first unit tests for the postprocess filter (length bounds, drop_empty, drop_duplicates, combined, exact-content matching, and config parsing).

Validation: gofmt clean, go vet ./internal/ingestion/chunk/ clean, go build ok, go test ./internal/ingestion/chunk/ — all tests pass.

Closes #16048

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. 🧪 test Pull requests that update test cases. labels Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

filterConfig gains two boolean fields (drop_empty, drop_duplicates). NewPostprocessOperator parses them from the config map, PostprocessOperator.String() emits them, and filterChunks is extended to skip whitespace-only chunks and remove exact-content duplicates (order-preserving). A new test file covers all filter behaviors and config parsing.

Changes

drop_empty and drop_duplicates filter flags

Layer / File(s) Summary
filterConfig fields, parsing, String(), and filterChunks logic
internal/ingestion/chunk/postprocess.go
filterConfig gains DropEmpty and DropDuplicates bool fields. NewPostprocessOperator reads both from the config map. String() emits them under filter:. filterChunks conditionally skips whitespace-only chunks and, when enabled, tracks a seen content set to drop later exact duplicates while preserving first occurrence.
Unit tests for filter behavior and config parsing
internal/ingestion/chunk/postprocess_test.go
Adds runFilter test helper and six test functions covering length bounds, drop_empty, drop_duplicates, their combined effect, exact-content duplicate detection (whitespace-sensitive), and NewPostprocessOperator config parsing with String() output assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hippity-hop through the chunk parade,
Empty and clones now must be afraid!
drop_empty sweeps the blank ones away,
drop_duplicates sends twins off to play.
First seen, first kept — that's the rabbit's decree,
Clean chunks for indexing, hooray, yippee! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature added: enabling the postprocess filter to drop empty and duplicate chunks in the Go pipeline.
Linked Issues check ✅ Passed All coding requirements from issue #16048 are met: drop_empty and drop_duplicates boolean flags implemented, default-off behavior maintained, composition with length bounds preserved, order-preserving deduplication with first occurrence kept, and comprehensive unit tests added.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the requirements: modifications to postprocess.go add the two filter options, and new postprocess_test.go provides required test coverage with no extraneous alterations.
Description check ✅ Passed The PR description comprehensively addresses the problem statement, includes required section headings, type of change selection, validation details, and issue closure reference.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@Crystora

Copy link
Copy Markdown
Contributor Author

@yingfeng @JinHai-CN would appreciate review this PR.

@xugangqiang

Copy link
Copy Markdown
Contributor

This code is being actively migrated and will be fully migrated to go. For now we don't have plan to change inside task_executor_refactor folder. Thank you.

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 6, 2026
@yuzhichang
yuzhichang force-pushed the feat/go-chunk-filter-dedup branch from af1097f to 19d1547 Compare July 6, 2026 05:49
@yuzhichang yuzhichang added the ci Continue Integration label Jul 6, 2026
@yuzhichang
yuzhichang merged commit b633ff0 into infiniflow:main Jul 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: postprocess filter should drop empty and duplicate chunks

4 participants