Say two tables describe the same products, papers or restaurants, with different columns, different spelling and no shared key. The classic recipe to find matching entries between the two tables is a blocking pass, a bag of string similarity features, and a classifier trained on labelled pairs. Most of that is avoidable. Embed each row with a general-purpose sentence model, index one table in a KD-tree, and ask each row of the other table for its nearest neighbour. One number — how far is close enough — is all you need to learn.
Rows as text
Every field is lowercased and stripped, the row is serialized as JSON, and the whole string goes through the embedding model. Nothing is told which field is a name and which is a price; the model has seen enough product listings to work that out.
pl.struct(fields).struct.json_encode().map_batches(embed, ...)I’m using the 256-dim Matryoshka representation from embeddinggemma-300m here. Because every vector is unit length, cosine similarity and Euclidean distance carry the same information:
\[\|a - b\|_2 = \sqrt{2\,(1 - a \cdot b)}\]
which matters only because KD-trees want a metric, not a dot product:
def dist_unit_norm():
return ((1 - pl.col("embedding").arr.dot(pl.col("embedding_right")))* 2)**0.5So distances live in \([0, 2]\), and the whole model is a cut point on that interval.
Training is a quantile
The labelled pairs are only used to answer one question: how far apart are two rows that are the same thing? Take the distance of every known match and keep the 99th percentile. Any threshold at least that large retains 99% of matches.
def train(pairs, a, b):
d = (pairs.lazy().join(a.lazy(), left_on="ltable_id", right_on="id")
.join(b.lazy(), left_on="rtable_id", right_on="id"))
return d.select(dist_unit_norm()).quantile(RECALL).collect().item()That is the entire fit: one scalar, no optimizer, no held-out tuning loop.
Prediction is one KD-tree query
These datasets are one-to-one — a row in A has at most one partner in B — so there is nothing to score and rank. The nearest neighbour is the only candidate, and the threshold decides whether to take it. KDTree.query does both jobs in one call: distance_upper_bound makes a too-far neighbour come back as index len(b), which is the “no match” answer.
def predict(thresh, a, b):
dist, best = KDTree(b["embedding"].to_numpy()).query(
a["embedding"].to_numpy(), distance_upper_bound=thresh)
keep = best < b.height
return pl.DataFrame({"ltable_id": a["id"].to_numpy()[keep],
"rtable_id": b["id"].to_numpy()[best[keep]]})There’s blocking stage because this is the blocking stage. The structure that a blocker is normally built to exploit — most pairs are obviously unrelated — is already the thing a spatial index gives away for free.
Does it work?
| dataset | threshold | recall | precision |
|---|---|---|---|
| restaurants1 | 0.57 | 1.00 | 1.00 |
| DBLP-ACM | 0.54 | 0.99 | 0.99 |
| Abt-Buy | 0.80 | 0.92 | 0.94 |
Competitive with trained pair classifiers! Two plots explain why so little machinery suffices.

For each row of A, the distance to its nearest row in B, split by whether that row is the true match. The two datasets fail in opposite ways. DBLP-ACM has no ranking errors at all: every matched row finds its partner, and the orange group is the 81 rows with no partner in B, where refusing is the right answer and the threshold alone decides. Abt-Buy has no unmatched rows, so all 15 in its orange group are rows that lost to a wrong listing — shared boilerplate (“Sony”, “black”, “with remote”) pulling unrelated products together.

Sweeping the threshold shows how little rides on it. Both datasets have a wide plateau where precision and recall are near their maximum, and the 99th-percentile pick lands inside it.