semantica.deduplication detects and merges duplicate entities across sources to produce a clean, single-source-of-truth knowledge graph:
- Four v2 strategies up to 7× faster than v1:
blocking_v2, hybrid_v2, semantic_v2
ClusterBuilder uses Union-Find and hierarchical clustering for batch deduplication at scale
EntityMerger preserves original source provenance on every merged entity
MergeStrategyManager supports per-property rules and conflict resolution
- All workflows operate on plain Python dicts: no ORM or schema required
Exported Classes
What You Get
- DuplicateDetector — Pairwise, batch, incremental, and group detection modes. Returns scored candidates with reasons.
- EntityMerger — Five merge strategies: keep first, last, most complete, highest confidence, or merge all fields.
- SimilarityCalculator — Multi-factor scoring across string edit distance, property overlap, relationship overlap, and embeddings.
- ClusterBuilder — Union-Find and hierarchical clustering for batch deduplication at scale: handles 100k+ entity sets.
- MergeStrategyManager — Per-property merge rules with conflict resolution priorities. Apply different strategies to different fields.
- v2 Strategies —
blocking_v2, hybrid_v2, semantic_v2: up to 7× faster than v1 for large entity sets.
Getting Started
Normalize entity names before deduplication. Canonical forms such as "Apple Inc." vs "apple inc" may score below threshold due to case alone. Run EntityNormalizer or TextNormalizer first for reliable matching.
DuplicateDetector
Find duplicate entity pairs:
Tune similarity_threshold before confidence_threshold. The similarity threshold gates which entity pairs are even considered. The confidence threshold further filters those pairs based on multi-factor scoring. Start with similarity_threshold=0.7 and raise it to reduce false positives.
Use detect_duplicate_groups() when you need to merge. The "group" detection strategy uses union-find to form transitive clusters: if A≈B and B≈C, all three land in the same group. Plain detect_duplicates() returns individual pairs without transitivity.
detect_duplicates() detection methods
The method= parameter of the detect_duplicates() convenience function controls how
the comparison is performed. These are independent of the SimilarityCalculator string
method used internally:
DuplicateCandidate fields
DuplicateCandidate fields are entity1, entity2, similarity_score: not entity_a, entity_b, similarity. Accessing the wrong field names raises AttributeError.
DuplicateGroup fields
EntityMerger
Merges detected duplicate groups into canonical entities:
merge_entities() and EntityMerger.merge_duplicates() return List[MergeOperation], not a list of entity dicts. Access .merged_entity on each operation to get the merged dict.
Merge strategies
Pass as a string to strategy= on merge_duplicates() or merge_entity_group():
Per-property merge rules
Per-property rules are set on EntityMerger.merge_strategy_manager using
add_property_rule(). Rules take a MergeStrategy enum value:
PropertyMergeRule is a dataclass, not an Enum. The merge strategy Enum is MergeStrategy (KEEP_FIRST, KEEP_LAST, KEEP_MOST_COMPLETE, KEEP_HIGHEST_CONFIDENCE, MERGE_ALL). Per-property rules are added via merger.merge_strategy_manager.add_property_rule(name, strategy).
MergeOperation fields
SimilarityCalculator
Compute multi-factor similarity scores between entity pairs:
SimilarityResult fields
ClusterBuilder
Build entity clusters for large-scale batch deduplication:
Cluster fields
Convenience Functions
Custom Similarity Functions
Register domain-specific similarity logic and use it via the method registry:
Common Workflows
Basic Deduplication
Group-based Batch
Large-scale Clustering
Incremental
- Conflicts — Detect value conflicts between non-duplicate entities.
- Knowledge Graph — GraphBuilder uses deduplication during construction.
- Normalize — Normalize entity names before deduplication.
- Provenance — Track merged entity lineage.