Prompt
How do I use embeddings for deduplication of near-duplicate records?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
To deduplicate near-duplicate records with embeddings, you typically:
-
Convert each record to text
- For structured data, concatenate the important fields into a consistent string.
- Example:
name: Acme Corp | address: 123 Main St | phone: 555-1234
-
Generate embeddings
- Use an embedding model to map each record into a vector.
- Similar records should have vectors close together.
-
Measure similarity
- Commonly use cosine similarity.
- Pairs with similarity above a threshold are treated as likely duplicates.
-
Find candidate matches efficiently
- For small datasets, compare all pairs.
- For larger datasets, use approximate nearest neighbor search:
- FAISS
- Annoy
- hnswlib
- vector databases
-
Cluster or pair records
- You can:
- mark each record’s nearest neighbors above threshold as duplicates
- cluster records and choose a canonical representative per cluster
- You can:
-
Review and tune
- Thresholds depend on the data and model.
- Validate on labeled examples and tune for precision vs recall.
Typical workflow
1) Prepare the text
Make the representation stable and consistent:
- normalize casing
- strip punctuation if useful
- standardize abbreviations
- order fields consistently
- include only relevant fields
Example:
company_name: acme corporation
address: 123 main street, springfield
email: info@acme.com
2) Embed
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")
texts = [
"company_name: acme corporation address: 123 main street",
"company_name: acme corp address: 123 main st."
]
embeddings = model.encode(texts, normalize_embeddings=True)
3) Compare similarities
import numpy as np
sim = np.dot(embeddings[0], embeddings[1]) # cosine similarity if normalized
print(sim)
4) Decide duplicate threshold
Example rule:
similarity > 0.85→ probable duplicate0.75–0.85→ review< 0.75→ different
These numbers vary a lot by dataset.
Important caveats
- Embeddings are best for semantic similarity, not exact matching.
- For deduplication, embeddings often work well for:
- product descriptions
- company names with variations
- messy free text
- customer support tickets
- They may be weaker for:
- exact IDs
- numeric fields
- highly structured records where rules/fuzzy matching are better
Best practice: combine embeddings with rules
A strong dedup system often uses both:
- rules/fuzzy matching for exact/near-exact fields
- embeddings for semantic similarity
- optional human review for borderline cases
Example hybrid logic:
- if email matches exactly → duplicate
- else if embedding similarity high and name/address close → duplicate
- else not duplicate
If you want, I can also show:
- a full Python example using FAISS or pandas
- a clustering-based dedup pipeline
- how to choose thresholds and evaluate precision/recall