Content hash: 7c67d2e88a7cc50ac0d8d30b0e415d2e65623f89b7d8fcbaf445382a50ce7cba
# Entity Resolution Strategies
## The problem
Multiple text mentions referring to the same real-world entity:
- "J. Smith", "John Smith", "Dr. Smith" → one Person node
- "ACMECorp", "Acme Corp.", "ACME Corporation" → one Organization node
- "123 Main St" and "Joe's Building Co LLC" → same business
Unresolved entities fragment your graph and break multi-hop traversal.
## Resolution approaches (least to most sophisticated)
### 1. Name normalization
```python
def normalize(name: str) -> str:
return name.lower().strip().rstrip(".").replace("corp.", "corporation")
```
### 2. Fuzzy matching
```python
from difflib import SequenceMatcher
def is_same_entity(a: str, b: str, threshold: float = 0.85) -> bool:
return SequenceMatcher(None, normalize(a), normalize(b)).ratio() > threshold
```
### 3. Embedding-based clustering
```python
# Cluster entity mentions by their context embedding similarity
from sklearn.cluster import DBSCAN
embeddings = embed([mention.context for mention in mentions])
clusters = DBSCAN(eps=0.3).fit_predict(embeddings)
```
### 4. LLM-based resolution
```
Given these entity mentions, tell me which refer to the same real-world entity:
1. "J. Smith" - mentioned as the CTO
2. "John Smith" - mentioned as a board member
3. "Dr. Jane Doe" - mentioned as the lead researcher
Respond with groups of equivalent mentions.
```
## Coreference resolution
Before entity resolution, resolve intra-document references:
- "Alice joined in 2020. She now leads the ML team." → "She" = "Alice"
- Use spaCy's `neuralcoref` or LLM-based coref
## Verification checklist
- [ ] Count near-duplicate entities per known real-world entity (should be ≈1)
- [ ] Spot-check a sample: do the canonical entities make sense?
- [ ] Run a multi-hop query that would fail without resolution; confirm it succeeds
- [ ] Measure false-merge rate (incorrectly merged distinct entities)