fix: deduplicate entities by (title, type) in finalize_entities (#1718)#2411
Open
HashwanthVen wants to merge 1 commit into
Open
fix: deduplicate entities by (title, type) in finalize_entities (#1718)#2411HashwanthVen wants to merge 1 commit into
HashwanthVen wants to merge 1 commit into
Conversation
|
@HashwanthVen please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Summary
Fixes #1718.
finalize_entitiesdeduplicated entity rows bytitlealone. When twodistinct entities share a title but have different types — for example
IBMextracted both as an
ORGANIZATIONand as aGEO, or thePARENT AREAcase inthe original report — every row after the first for that title was silently
dropped, discarding its description and breaking the edges that referenced it.
This changes the dedup key to the
(title, type)pair, so entities that aregenuinely distinct are preserved while true duplicates (same title and type)
are still collapsed to a single row.
Root cause
packages/graphrag/graphrag/index/operations/finalize_entities.py:seen_titlesis keyed ontitleonly, so the second(title, *)row of anytitle is skipped regardless of its
type.Fix
The change is localized to the single dedup guard; degree lookup, id assignment,
human-readable id sequencing, and the output column projection are unchanged.
Tests
Added to
tests/unit/indexing/test_finalize_graph.py::TestFinalizeEntities:test_keeps_same_title_different_type— two rows with the same title anddifferent types are both written (the regression in [Fatal Bug]: Incorrect deduplication of entities with same title but different type #1718).
test_deduplicates_same_title_and_type— true duplicates (same title andtype) are still collapsed to one row.
The existing
test_deduplicates_by_titlecontinues to pass because its duplicaterows share the default type, so they remain a true duplicate under the new key.
Run:
Notes
patchsemversioner change document is included.