Skip to content

fix(medcat): Keep each name's status and the preferred name in merge_cdb - #680

Merged
mart-r merged 1 commit into
CogStack:mainfrom
chenyangsu:fix/merge-cdb-name-status
Nov 26, 2026
Merged

mart-r merged 1 commit into
CogStack:mainfrom
chenyangsu:fix/merge-cdb-name-status

Conversation

@chenyangsu

Copy link
Copy Markdown
Contributor

merge_cdb takes the status of whichever name of a cdb2 concept the names set yields first, and passes it to _add_concept for all of that concept's names, so the result depends on the hash seed. For a cdb2 concept with names diabetes~mellitus (P), diabetes (A) and dm (N), merged into a CDB without it:

PYTHONHASHSEED=1  all three names -> P, preferred_name 'diabetes'
PYTHONHASHSEED=2  all three names -> A, preferred_name ''
PYTHONHASHSEED=3  all three names -> N, preferred_name ''

When cdb1 has the same concept, a P from cdb2 can also overwrite cdb1's N or A on the other names. cdb2's preferred name ("Diabetes mellitus") is lost in every case, because _add_concept only sets one from a P name.

The names are now grouped by their own status in cdb2, with one _add_concept call per status, and a concept that is new to the merged CDB takes cdb2's preferred_name. Names without an entry in cdb2.name2info get 'A', the existing default.

Testing: the new test_merge_cdb_keeps_status_of_each_name (cdb1 empty, and cdb1 holding the same concept) fails on main and passes here. python -m unittest tests.utils.test_cdb_utils: 16 tests OK under PYTHONHASHSEED 1 to 4. ruff check medcat --preview and mypy pass.

…erge_cdb

merge_cdb passed one status, that of whichever name of the cdb2 concept
the set yielded first, to _add_concept for all of the concept's names,
so a name marked N in cdb2 could become P and the reverse, depending on
the hash seed. The preferred name of a concept only in cdb2 was also
replaced by one of its names or left empty. Add the names grouped by
their own status and copy cdb2's preferred name for new concepts.

@mart-r mart-r left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution and the thorough description!

Good catch on this one as well! And good PR!

Thanks.

PS: [Again] We haven't used CDB merge in production too much so we haven't been able to catch this. Thanks again!

@mart-r
mart-r merged commit 9fe348c into CogStack:main Nov 26, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants