Repository navigation
fix: count distinct chunk IDs so doc.chunk_num matches actual indexed chunks - #17182
Conversation
… 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.
|
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 (2)
📝 WalkthroughWalkthroughPipeline 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. ChangesDistinct chunk count reporting
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 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 |
wangq8
left a comment
There was a problem hiding this comment.
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.
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 causeddoc.chunk_numin the database to diverge from the actual number of indexed chunks.Changes:
countDistinctChunkIDs()ininternal/ingestion/task/pipeline_executor.goto count unique chunk IDs afterProcessChunksForPipelineassigns deterministic IDs viaChunkID.processOutputnow uses the deduplicated count forPipelineResult.ChunkCount, so bothdoc.chunk_numandkb.chunk_numaccurately reflect the effective number of chunks in the search index.TestCountDistinctChunkIDscovering empty, all-unique, with-duplicates, and missing-id cases.