fix(cli): copy chunk metadata before id assignment to break dict aliasing - #8
Merged
Merged
Conversation
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.
Fixes #7.
Problem
Chunkers can return chunks for one file that alias the same metadata dict object. Both
LeannCLI._assign_chunk_idsandLeannCLI._assign_unique_chunk_idswrote each per-chunk id into that shared dict viasetdefault, so the last chunk's id overwrote all previous ones.LeannBuilder.add_textresolves the passage id frommetadata["id"], so every chunk of a multi-chunk file got the last chunk's id — corruptingpassages.idxand the faiss id map, and failingleann verifywith "id appears with different text" on every multi-file incremental build.Fix
Copy the metadata dict at id-assignment time in both assigners:
c["metadata"] = {**c.get("metadata", {}), "id": sid}.Verification
tests/test_incremental_build.py::test_assign_unique_chunk_ids_with_shared_metadata_dict,::test_assign_chunk_ids_with_shared_metadata_dict) — red on base, green with fix.--sync-key, 2 files then +3 multi-chunk files, 59 chunks each) —leann verifyexits 0, all 295 passage ids distinct, zero duplicate-id lines.ruff check/ruff format --checkclean; TDD exit gate PASS (0 self-inflicted test/lint findings).