fix: deduplicate entities by (title, type) to preserve same-name different-type entities#2339
Open
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
Open
Conversation
…erent-type entities (fixes microsoft#1718) Previously, finalize_entities only tracked seen titles, causing entities with the same title but different type to be incorrectly deduplicated. Change the dedup key to the (title, type) compound tuple so that e.g. "Python" as a LANGUAGE and "Python" as a CONCEPT are both preserved. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
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 #1718
Problem
finalize_entitiestracked only the entitytitlein its deduplication set, so two entities with the same title but different types (e.g."Python"asLANGUAGEand"Python"asCONCEPT) were incorrectly collapsed into one. The second entity was silently dropped, causing ~10% data loss in graphs with polymorphic entity names.Solution
Change the dedup key from
title(astr) to(title, type)(atuple[str, str]), matching the approach already used infinalize_relationshipswhich deduplicates by(source, target).Before:
After:
Testing
test_deduplicates_by_titledocstring to clarify it covers same(title, type)duplicates.test_preserves_same_title_different_typewhich directly exercises the bug scenario: three entities where two share the title"Python"but have typesLANGUAGEandCONCEPT; all three must survive finalization.