Taxonomy Deduplication & Gap Fill
Problem Statement
After scaling the document corpus to 573 PDF brochures and running multiple extraction rounds, the published taxonomy accumulated 12,997 entities, but 79% of those were duplicates (the project's own count at the time). The root cause was cross-version extraction: each new pipeline run produced a new taxonomy version and published it, adding new copies of entities that already existed under an earlier version number.
The result was a bloated published store where, for example, "Cardiologie" appeared as 8 separate records (one per published version), each with its own identifier. Query enrichment that looked up entities by name would match all 8, causing unpredictable behaviour depending on which was returned first. Downstream, the published relationships mirrored this inflation: 6,821 of 12,997 entities had no relationships at all (orphans), so the RAG pipeline could not route queries about those conditions or treatments to any department.
Two one-time database migrations addressed this in sequence:
| Step | Scope |
|---|---|
| Dedup of published entities | Collapse duplicates, remap relationships, remove stale records |
| SNOMED relationship gap fill | Re-attach orphaned condition, treatment and examination entities using the SNOMED hierarchy, with a Dutch manual-seed fallback |
Step 1: Entity Deduplication
Flow
Step-by-Step Details
Step 1: Backup. Before any change, full backup copies of the published entities and relationships are taken, together with a mapping from every losing entity to the entity that survives. These backups persist after the migration so operators can audit the changes, and they are used for rollback.
Step 2: Group and score. All entities are loaded with their relationship count and grouped by hospital, entity type and canonical name. Within each group a survivor is selected as the best representative.
Step 3: Remap relationships. Any relationship that referenced a losing entity (as source or target) is updated to point to the survivor. This preserves all navigational and medical relationships; only the identifier changes.
Step 4: Deduplicate relationships. After remapping, several relationships may be identical (same hospital, source, target and type). The duplicates are removed, keeping one.
Step 5: Delete losers. All entities that lost their group are deleted. Only the survivors remain.
Step 6: Remove orphaned doctors. Doctors without any relationship (no department, no campus) are deleted, because a doctor not linked to a department or campus has no value in the knowledge graph. Orphaned conditions, treatments and examinations are intentionally preserved at this point; the gap-fill step attempts to repair them.
Survivor Selection
Candidates in a group are ranked by three criteria, in order:
- the number of existing relationships (the most connected wins),
- whether a SNOMED concept ID is present (present beats absent), and
- a shorter display name.
The intuition: a well-connected entity with a SNOMED code and a concise name is the canonical representation.
Rollback
The migration can be reversed exactly: the published entities and relationships are emptied and restored from the backup copies, and the temporary tables are dropped.
Step 2: SNOMED Relationship Gap Fill
After deduplication, orphaned condition, treatment and examination entities still exist with no relationship to any department. The gap-fill step restores those connections using two strategies: walking the SNOMED hierarchy, then falling back to a curated Dutch manual seed dictionary.
Flow
SNOMED Hierarchy Walk
A pre-computed table stores the ancestor/descendant pairs for all concepts in the SNOMED CT release. The gap filler uses it to bridge the gap between a clinical concept and a hospital department:
- Direct map. For each published department that carries a SNOMED concept ID, record the concept-to-department link.
- Expand via hierarchy. Look up all descendants of those department concepts. Each descendant concept is now also mapped to that department.
- Orphan lookup. For each orphan with a SNOMED concept ID, check whether its concept (or any of its ancestors) appears in the expanded map. The first match at the shallowest depth wins.
The result is that a condition such as myocardial infarction ("hartinfarct"), which is a descendant of the cardiology branch of SNOMED, is automatically linked to the Cardiologie department even if no explicit relationship was ever extracted.
Manual Seed Fallback
For orphans with no SNOMED concept ID, or whose SNOMED ancestors do not intersect any mapped department, the filler falls back to a curated dictionary keyed on the entity's lower-cased name. It contains 27 common condition-to-department pairs, for example:
| Condition | Department |
|---|---|
| borstkanker | oncologie |
| beroerte | neurologie |
| hartfalen | cardiologie |
| diabetes | endocrinologie |
| longontsteking | pneumologie |
| psoriasis | dermatologie |
| glaucoom | oogheelkunde |
| heupfractuur | orthopedie |
The seed lookup is case-insensitive and exact on the name. If a department with the returned name exists for that hospital, a new relationship is created.
Relationship Type Assignment
| Entity Type | Relationship Created |
|---|---|
| Condition | Department to condition |
| Treatment | Department performs treatment |
| Examination | Department performs examination |
Tracking and Rollback
All relationships created by this step are recorded in a tracking table. That table is the sole basis for rollback: reversing the step deletes only those relationships. Unlike the deduplication step, it does not restore backups, so the deduplicated state is preserved.
Before / After Results
These figures are the project's own counts from the cleanup run.
| Metric | Before | After |
|---|---|---|
| Total published entities | 12,997 | about 2,700 |
| Duplicate entities | about 10,297 (79%) | 0 |
| Orphaned condition, treatment and examination entities | 6,821 | about 200 (residual) |
| Orphaned doctor entities | included in orphan count | 0 (deleted) |
| Campus entities | 25 (including 13 duplicates) | 12 |
| Relationships remapped | not applicable | all preserved via the mapping |
| New seed-derived relationships | 0 | up to 27 seed terms matched |
Residual orphans are condition, treatment and examination entities that carry no SNOMED concept ID and whose names match no seed. They remain in the taxonomy as isolated nodes and are candidates for future manual linking or an expanded seed list.
Relationship to the Draft-Publish Lifecycle
The two cleanup steps were one-time operations targeting the bloated state that accumulated before per-version isolation was enforced. In the current draft-publish pipeline (SP-5), each publish cycle creates a clean snapshot:
Going forward, the deduplication logic is available as a library function that the publish step can invoke incrementally, preventing the same accumulation from recurring. The SNOMED gap filler can likewise be run as a scheduled maintenance pass after each publish cycle if new orphans are detected.
Campus entities are always excluded from deduplication: they are populated from the authoritative campus list and keep stable identifiers across publish versions.
Department Co-Reference Clustering (shipped 2026-06-09)
The cleanup steps above deduplicate entities by version within the published store. A separate, complementary problem exists in the draft taxonomy: the same real-world department can be recorded as several distinct entities. For example, the oral and maxillofacial surgery department existed as 5 separate department entities, but only one of them carried the 7 works-in doctor links. Before this fix, a roster query that resolved to any of the zero-doctor variants returned an empty list and fell back to the help desk.
What Shipped
The solution is non-destructive co-reference clustering. Each department entity gets two extra attributes:
| Attribute | Purpose |
|---|---|
| Cluster identifier | A shared key; all co-referent entities in one cluster carry the same value |
| Primary flag | Marks the canonical representative within a cluster: the entity with the most doctors, with the shortest name as tiebreaker |
No entities are deleted and no merge pointer is written, so the clustering is fully reversible.
Three Components
A two-phase offline job, separated by a human review step:
- Propose. Loads all active department entities for a hospital, runs pairwise token-subset co-reference detection (see below) and writes a proposals file. Nothing is written to the database in this phase.
- Apply. Reads the human-reviewed proposals file, validates that every entity exists as an active department for the given hospital, then writes the cluster attributes. The job is idempotent: re-running it is a no-op when the values are already correct.
The human review gate is the only trust boundary for the write path. No automated path can set a cluster without a reviewed proposals file.
A full re-ingest can reset the cluster attributes on rebuilt entities (a known issue that has since been fixed). The clustering job must be re-run and re-applied after any full re-ingest.
Co-reference criterion: token-subset only. Two candidates are co-referent if, after folding the clinical term (case, accents, punctuation), one's set of significant words is a non-empty subset of the other's. Stopwords such as "dienst", "afdeling", "de", "het", "en", "van" and "voor" are removed before comparison.
This is deliberately conservative:
- Punctuation, suffix and parenthetical variants merge (a short and a long spelling of the same department name).
- True synonyms with different root words do not auto-merge ("chirurgie" versus "heelkunde"); they must be confirmed by a qualified taxonomy owner.
- Bare abbreviations that share no significant word do not auto-merge.
A fuzzy-matching tier was considered and dropped: the domain guard it relied on cannot distinguish Cardiologie from Cardiochirurgie, removing the only property that justified allowing approximate matches. The co-reference logic is purely structural.
An alias-only department resolver (no database access). A pure function takes a free-text department name and a caller-supplied list of candidate departments, and returns a match through a deterministic cascade:
| Tier | Logic | Confidence |
|---|---|---|
| Guard | Blank term or no candidates | No input |
| Exact | Folded names are equal | 1.0 |
| Token | Significant-word subset relation | 0.9 |
| Alias | Folded alias equals the folded term | 0.85 |
The term-folding step was extended to also treat punctuation as spaces, which directly fixes a June 2026 case in which a hyphenated department name failed to match, as well as earlier failures involving ligatures and longest-name selection. Every resolution emits a structured log line recording the term, the match, the tier and the number of candidates considered, following the project's silent-failure discipline.
Cluster-aware roster aggregation. When the matched entity belongs to a cluster, the roster query expands to cover all entities in the trusted cluster, not just the matched entity. A query that resolves to any variant, including a zero-doctor duplicate, therefore still returns the full doctor roster of the canonical primary. When there is no cluster, behaviour is identical to the pre-clustering path (single-entity match).
The department resolver cascade and the cluster-aware roster aggregation are gated behind a feature setting that is off by default. With it off, each surface uses its legacy per-surface matching and the roster query does not expand across the cluster, so co-reference clustering only changes answers once the setting is enabled (and a cluster has been applied via the human-gated job above).
Data Flow
free-text department term
-> each surface fetches all department candidates
(candidates carry doctor count, cluster and aliases)
-> department resolver matches the term to a candidate
-> matched entity (and its cluster, if any)
-> roster query: if a cluster exists, gather works-in links across the cluster
otherwise, single-entity match (unchanged)
-> non-empty roster ? answer with names : graceful fallback (department phone and transfer)
Relationship to the Cleanup Steps
The cleanup steps were one-time operations against the old, bloated published store. Department co-reference clustering operates on the current draft taxonomy and is a runtime, ongoing maintenance task rather than a one-time migration. The two mechanisms are complementary: the cleanup collapsed cross-version duplicates within the published taxonomy; clustering reconciles entity fragmentation within the live extraction graph.
Related Pages
- Taxonomy Extraction Pipeline: how entities are extracted and published
- Medical Knowledge Architecture: entity type definitions and relationships
- Entity Resolution: dedup and SNOMED matching at extraction time