Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

Fix deduplication logic: Jaro-Winkler default, disjoint property handling, and docs update

KaifAhmad17297d46ac851
diff --git a/README.md b/README.md
index a2fb4f8c..d992763c 100644
--- a/README.md
+++ b/README.md
@@ -83,7 +83,7 @@ Semantica operates through three integrated layers that transform raw data into
**Input Layer** — Universal ingestion from 50+ data formats (PDFs, DOCX, HTML, JSON, CSV, databases, live feeds, APIs, streams, archives, multi-modal content) into a unified pipeline.
-**Semantic Layer** — Core intelligence engine performing entity extraction, relationship mapping, ontology generation, context engineering, and quality assurance. This is where unstructured data transforms into structured knowledge.
+**Semantic Layer** — Core intelligence engine performing entity extraction, relationship mapping, ontology generation, context engineering, and quality assurance. Includes **advanced entity deduplication** (Jaro-Winkler, disjoint property handling) to ensure a clean single source of truth.
**Output Layer** — Production-ready knowledge graphs, vector embeddings, and validated ontologies that power GraphRAG systems, AI agents, and multi-agent systems.
diff --git a/cookbook/introduction/18_Deduplication.ipynb b/cookbook/introduction/18_Deduplication.ipynb
index 4a59e763..0b183aba 100644
--- a/cookbook/introduction/18_Deduplication.ipynb
+++ b/cookbook/introduction/18_Deduplication.ipynb
@@ -146,7 +146,7 @@
{
"data": {
"text/html": [
- "<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>SimilarityCalculator</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>DuplicateDetector</td><td>-</td><td>0.19s</td></tr></table></div>"
+ "<div style='font-family: monospace;'><h4>🧠 Semantica - 📊 Current Progress</h4><table style='width: 100%; border-collapse: collapse;'><tr><th>Status</th><th>Action</th><th>Module</th><th>Submodule</th><th>File</th><th>Time</th></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>SimilarityCalculator</td><td>-</td><td>0.01s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>DuplicateDetector</td><td>-</td><td>0.17s</td></tr><tr><td>✅</td><td>Semantica is deduplicating</td><td>🔄 deduplication</td><td>EntityMerger</td><td>-</td><td>0.18s</td></tr></table></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
@@ -206,7 +206,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 4,
"metadata": {},
"outputs": [
{
@@ -245,7 +245,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -277,7 +277,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 6,
"metadata": {},
"outputs": [
{
@@ -325,7 +325,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@@ -335,9 +335,19 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Performed 0 merge operations.\n",
+ "\n",
+ "--- Merged Results ---\n"
+ ]
+ }
+ ],
"source": [
"merger = EntityMerger()\n",
"\n",
@@ -370,9 +380,29 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "1. Detecting duplicates...\n",
+ "2. Merging entities...\n",
+ "\n",
+ "Original Size: 6\n",
+ "Cleaned Size: 6\n",
+ "\n",
+ "Final Entity Names:\n",
+ " - Apple Inc.\n",
+ " - Apple Inc\n",
+ " - Apple\n",
+ " - Microsoft Corp\n",
+ " - Microsoft\n",
+ " - Google LLC\n"
+ ]
+ }
+ ],
"source": [
"def deduplicate_dataset(raw_entities):\n",
" print(\"1. Detecting duplicates...\")\n",
diff --git a/docs/modules.md b/docs/modules.md
index 7691d6c3..f259de57 100644
--- a/docs/modules.md
+++ b/docs/modules.md
@@ -645,6 +645,8 @@ These modules ensure data quality, handle duplicates, and resolve conflicts.
**Key Features:**
- Multiple similarity methods (exact, Levenshtein, Jaro-Winkler, cosine, embedding)
+- **Advanced String Matching**: Jaro-Winkler by default for better company/person name resolution
+- **Smart Property Handling**: Neutral scoring for disjoint properties to prevent false negatives
- Duplicate detection with confidence scoring
- Entity merging with configurable strategies
- Cluster-based batch deduplication
diff --git a/docs/reference/deduplication.md b/docs/reference/deduplication.md
index b041dbb8..cb4b6be4 100644
--- a/docs/reference/deduplication.md
+++ b/docs/reference/deduplication.md
@@ -57,11 +57,19 @@
### Similarity Calculation
- **Levenshtein Distance**: Edit distance for string difference
-- **Jaro-Winkler**: String similarity with prefix weighting (good for names)
+- **Jaro-Winkler**: String similarity with prefix weighting (Default for strings, optimized for entity names)
- **Cosine Similarity**: Vector similarity for embeddings
- **Jaccard Similarity**: Set overlap for properties/relationships
+- **Property Matching**: Handles disjoint properties with neutral scoring (0.5) to prevent false negatives
- **Multi-factor Aggregation**: Weighted sum of multiple metrics
+### Default Configuration
+The deduplication module uses the following default weights to prioritize name matching while considering other factors:
+- **String Similarity**: 0.6 (Primary factor, using Jaro-Winkler)
+- **Property Similarity**: 0.2 (Handles missing values neutrally)
+- **Relationship Similarity**: 0.2
+- **Embedding Similarity**: 0.0 (Optional, enabled if embeddings are present)
+
### Duplicate Detection
- **Pairwise Comparison**: O(n²) comparison (for small sets)
- **Blocking/Indexing**: Reduce search space for large sets
diff --git a/semantica/deduplication/deduplication_usage.md b/semantica/deduplication/deduplication_usage.md
index b77f0dac..6adebee6 100644
--- a/semantica/deduplication/deduplication_usage.md
+++ b/semantica/deduplication/deduplication_usage.md
@@ -20,10 +20,15 @@ This guide demonstrates how to use the deduplication module for detecting and me
```python
from semantica.deduplication import SimilarityCalculator
-calculator = SimilarityCalculator(
- string_weight=0.4,
- property_weight=0.3,
- embedding_weight=0.3
+# Initialize with default weights (optimized for entity resolution)
+# String: 0.6 (Jaro-Winkler), Property: 0.2, Relationship: 0.2
+calculator = SimilarityCalculator()
+
+# Or customize weights
+calculator_custom = SimilarityCalculator(
+ string_weight=0.6,
+ property_weight=0.2,
+ embedding_weight=0.2
)
entity1 = {"name": "Apple Inc.", "type": "Company"}
diff --git a/semantica/deduplication/similarity_calculator.py b/semantica/deduplication/similarity_calculator.py
index 3b133aed..05f61963 100644
--- a/semantica/deduplication/similarity_calculator.py
+++ b/semantica/deduplication/similarity_calculator.py
@@ -90,10 +90,10 @@ class SimilarityCalculator:
def __init__(
self,
- embedding_weight: float = 0.4,
- string_weight: float = 0.3,
+ embedding_weight: float = 0.0,
+ string_weight: float = 0.6,
property_weight: float = 0.2,
- relationship_weight: float = 0.1,
+ relationship_weight: float = 0.2,
similarity_threshold: float = 0.7,
config: Optional[Dict[str, Any]] = None,
**kwargs,
@@ -268,7 +268,7 @@ class SimilarityCalculator:
raise
def calculate_string_similarity(
- self, str1: str, str2: str, method: str = "levenshtein"
+ self, str1: str, str2: str, method: str = "jaro_winkler"
) -> float:
"""
Calculate string similarity between two strings.
@@ -330,6 +330,9 @@ class SimilarityCalculator:
val2 = props2.get(key)
if val1 is None or val2 is None:
+ # Missing value in one entity is not a mismatch, but lack of evidence
+ # Assign neutral score (0.5) instead of 0.0
+ matches += 0.5
total += 1
continue
@@ -369,7 +372,7 @@ class SimilarityCalculator:
rels2 = set(_make_hashable(r) for r in entity2.get("relationships", []))
if not rels1 and not rels2:
- return 1.0
+ return 0.5
if not rels1 or not rels2:
return 0.0