Fixes incorrect ID generation for identical chunks in RecursiveDocumentSplitter#9517
Merged
mpangrazzi merged 3 commits intodeepset-ai:mainfrom Jun 16, 2025
Merged
Conversation
mpangrazzi
reviewed
Jun 16, 2025
Contributor
mpangrazzi
left a comment
There was a problem hiding this comment.
Looks good, but I've left some comments below.
| meta = deepcopy(doc.meta) | ||
| meta["parent_id"] = doc.id | ||
| meta["split_id"] = split_nr | ||
| meta["split_idx_start"] = current_position |
Contributor
There was a problem hiding this comment.
Since you've added this, you need to remove:
new_doc.meta["split_idx_start"] = current_positionline below
| meta["split_idx_start"] = current_position | ||
| new_doc = Document(content=chunk, meta=meta) | ||
| new_doc.meta["split_idx_start"] = current_position | ||
| new_doc.meta["_split_overlap"] = [] if self.split_overlap > 0 else None |
Contributor
There was a problem hiding this comment.
For consistency with the fix's intent, I would set all metadata should before Document creation, not after. WDYT?
Contributor
Author
There was a problem hiding this comment.
you’re right. I’ve moved split_idx_start and _split_overlap.
| • `split_id` values must be 0, 1, 2, … | ||
| """ | ||
| from haystack import Document | ||
| from haystack.components.preprocessors.recursive_splitter import RecursiveDocumentSplitter |
Contributor
There was a problem hiding this comment.
Those imports are already present at the top of the file. Please remove them.
| def test_recursive_splitter_generates_unique_ids_and_correct_meta(): | ||
| """ | ||
| • Every produced chunk must have a unique `id`. | ||
| • Each chunk must carry `parent_id` = original doc’s ID. |
Contributor
There was a problem hiding this comment.
I think this docstring is not strictly needed (the test name and the comments are already descriptive enough).
…ect overlap information
Collaborator
Pull Request Test Coverage Report for Build 15689509354Details
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
Proposed Changes:
The issue occurred because
Document.idis generated based on thecontentandmetaat creation time.However, meta fields like
split_idandparent_idwere added after theDocumentwas instantiated, causing chunks with identical content and meta to produce identicalids.How did you test it?
test_recursive_splitter_generates_unique_ids_and_correct_metaNotes for the reviewer
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.