Skip to content

fix: count distinct chunk IDs so doc.chunk_num matches actual indexed chunks - #17182

Merged
xugangqiang merged 1 commit into
infiniflow:mainfrom
euvre:fix/chunk-count
Jul 23, 2026
Merged

xugangqiang merged 1 commit into
infiniflow:mainfrom
euvre:fix/chunk-count

Conversation

@euvre

@euvre euvre commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary:

PipelineResult.ChunkCount was using len(chunks) from the raw pipeline output, but chunks with identical text share the same ChunkID (xxhash of text+docID). The search engine upserts by _id, so chunks with duplicate text collapse to a single document in the index. This caused doc.chunk_num in the database to diverge from the actual number of indexed chunks.

Changes:

  • Added countDistinctChunkIDs() in internal/ingestion/task/pipeline_executor.go to count unique chunk IDs after ProcessChunksForPipeline assigns deterministic IDs via ChunkID.
  • processOutput now uses the deduplicated count for PipelineResult.ChunkCount, so both doc.chunk_num and kb.chunk_num accurately reflect the effective number of chunks in the search index.
  • Added unit test TestCountDistinctChunkIDs covering empty, all-unique, with-duplicates, and missing-id cases.

… chunks

PipelineResult.ChunkCount was using len(chunks) from the raw pipeline
output, but chunks with identical text share the same ChunkID (xxhash).
The search engine upserts by _id, so duplicate-text chunks collapse to a
single document in the index. This caused doc.chunk_num in the database
(50) to diverge from the actual indexed chunk count (27).

Add countDistinctChunkIDs() to deduplicate by id after
ProcessChunksForPipeline assigns ChunkIDs, and use the distinct count
for ChunkCount. Also add unit test covering empty, all-unique,
with-duplicates, and missing-id cases.
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 21, 2026
@euvre euvre added the ci Continue Integration label Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bd51f915-ecdb-4ef1-a406-7eb66ec92a25

📥 Commits

Reviewing files that changed from the base of the PR and between edeb47c and 9015da6.

📒 Files selected for processing (2)
  • internal/ingestion/task/pipeline_executor.go
  • internal/ingestion/task/pipeline_executor_test.go

📝 Walkthrough

Walkthrough

Pipeline output now reports the number of distinct non-empty chunk IDs instead of the number of processed chunks. Unit tests cover unique, duplicate, missing, and nil chunk inputs.

Changes

Distinct chunk count reporting

Layer / File(s) Summary
Distinct chunk counting and validation
internal/ingestion/task/pipeline_executor.go, internal/ingestion/task/pipeline_executor_test.go
processOutput uses a helper that counts unique non-empty chunk IDs, with tests covering nil input, unique IDs, duplicates, and missing IDs.

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

Suggested reviewers: xugangqiang, qinling0210

Poem

I’m a rabbit counting chunks in a row,
Skipping empty IDs as I go.
Duplicates hop out of sight,
Unique ones shine bright—
A tidy result for the pipeline flow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: counting distinct chunk IDs to match indexed chunk totals.
Description check ✅ Passed The description includes the required summary and adds clear context plus change details, matching the template well.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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.

@euvre
euvre requested a review from wangq8 July 21, 2026 09:57

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. The root cause analysis is correct — chunks with identical text share the same ChunkID (xxhash of text+docID) and the search engine upserts by _id, so len(chunks) overcounts. The countDistinctChunkIDs function correctly mirrors the index-side deduplication. Test covers empty, all-unique, with-duplicates, and missing-id cases.

@wangq8
wangq8 requested a review from xugangqiang July 22, 2026 04:10
@xugangqiang
xugangqiang merged commit 3733da2 into infiniflow:main Jul 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants