Guide
Cross-restaurant matching
On this page
Price comparison starts with knowing that "Phở Gà" on one menu and "Pho Ga (Chicken Noodle Soup)" on another are the same dish. POST /match answers that for pairs of item names, across misspellings, transliterations, promo noise and languages.
- Endpoint
POST /match- Plans
- Every plan
- Try it
- Run it in the playground
What you bring
You send item names from menus you already hold, and the prices stay on your side. /match tells you which pairs are the same dish, and the price comparison is your own code.
How it works
- Load the menus you want to compare, with your own item IDs and prices.
- Build candidate pairs. /match judges the pairs you give it and doesn't look for pairs itself.
- Send the pairs to /match, up to 100 per request.
- Keep pairs where
matchis true and both conflict flags are false. - Compare prices on the pairs you kept.
Check a few pairs
import os
import requests
BASE = "https://dish-embed.latimal.com"
headers = {"X-API-Key": os.environ["LATIMAL_API_KEY"], "Content-Type": "application/json"}
pairs = [
{"text_a": "Phở Gà", "text_b": "Pho Ga (Chicken Noodle Soup)"},
{"text_a": "Shakshuka", "text_b": "شكشوكة"},
{"text_a": 'Margherita Pizza 12"', "text_b": "Pizza Margherita"},
{"text_a": "Pad Kra Pao Chicken", "text_b": "Pad Kra Pao Tofu"},
]
resp = requests.post(f"{BASE}/match", headers=headers, json={"pairs": pairs})
resp.raise_for_status()
for r in resp.json()["results"]:
flags = [name for name in ("dietary_conflict", "protein_conflict") if r[name]]
verdict = "same dish" if r["match"] else "different"
print(f"{r['text_a']} | {r['text_b']} | {verdict} {flags}")Example output:
Phở Gà | Pho Ga (Chicken Noodle Soup) | same dish []
Shakshuka | شكشوكة | same dish []
Margherita Pizza 12" | Pizza Margherita | same dish []
Pad Kra Pao Chicken | Pad Kra Pao Tofu | different ['dietary_conflict', 'protein_conflict']Each result also carries cosine and reranker_score. See the reference for what they mean.
Build candidate pairs
Pairing every item with every other item grows fast: two 300-item menus make 90,000 pairs. Narrow the candidates first. Two ways to do it, which you can combine:
- Block on what you already know. Compare items within the same category or cuisine. Cuisine tagging gives you a cuisine label to block on.
- Shortlist by vector. Embed both menus with POST /embed, and for each item take the few closest items on the other menu. Vectors are L2-normalized, so a dot product gives cosine similarity.
import numpy as np
def embed(items, batch_size=512):
vectors = []
for i in range(0, len(items), batch_size):
resp = requests.post(f"{BASE}/embed", headers=headers,
json={"items": items[i:i + batch_size]})
resp.raise_for_status()
vectors.extend(resp.json()["embeddings"])
return np.array(vectors)
def candidate_pairs(menu_a, menu_b, per_item=3):
"""Pair each item on menu A with its closest items on menu B."""
va = embed([m["name"] for m in menu_a])
vb = embed([m["name"] for m in menu_b])
sims = va @ vb.T
pairs = []
for i, row in enumerate(sims):
for j in np.argsort(-row)[:per_item]:
pairs.append((i, int(j)))
return pairsMatch in batches of 100
Results come back in the order you sent the pairs, so you can line them up with your own IDs by position.
def match_pairs(menu_a, menu_b, pairs, batch_size=100):
kept = []
for k in range(0, len(pairs), batch_size):
batch = pairs[k:k + batch_size]
body = {"pairs": [{"text_a": menu_a[i]["name"], "text_b": menu_b[j]["name"]}
for i, j in batch]}
resp = requests.post(f"{BASE}/match", headers=headers, json=body)
resp.raise_for_status()
for (i, j), r in zip(batch, resp.json()["results"]):
if r["match"] and not r["dietary_conflict"] and not r["protein_conflict"]:
kept.append((i, j))
return keptCompare prices
The prices here are your data. The API never sees them.
menu_a = [
{"id": "a1", "name": "Phở Gà", "price_usd": 14.50},
{"id": "a2", "name": "Pad Kra Pao Chicken", "price_usd": 13.00},
{"id": "a3", "name": "Shakshuka", "price_usd": 12.00},
]
menu_b = [
{"id": "b1", "name": "Pho Ga (Chicken Noodle Soup)", "price_usd": 15.75},
{"id": "b2", "name": "Pad Kra Pao Tofu", "price_usd": 12.00},
{"id": "b3", "name": "شكشوكة", "price_usd": 11.50},
]
pairs = candidate_pairs(menu_a, menu_b, per_item=2)
for i, j in match_pairs(menu_a, menu_b, pairs):
a, b = menu_a[i], menu_b[j]
diff = b["price_usd"] - a["price_usd"]
print(f"{a['name']} ${a['price_usd']:.2f} | {b['name']} ${b['price_usd']:.2f} | {diff:+.2f}")If one item matches several items on the other menu, pick one by your own rule or send the group to review.
Sizes and portions
The API strips serving sizes and prices from item text before it compares names, so Margherita Pizza 12" and Margherita Pizza 16" read as the same dish. That answers the dish question. For price comparison, portions matter too: keep size as its own field on your side, from your menu data or your own parsing, and compare prices only between matching sizes.
Dietary and protein conflicts
dietary_conflict is true when one item is vegetarian and the other is non-vegetarian. protein_conflict is true when the two items contain different listed protein words, like chicken and tofu. An item whose name contains none of the words listed in Dietary detection has no dietary signal, so it sets neither flag. Treat either flag as a hard stop before you merge listings.
Tuning the threshold
cosine_threshold defaults to 0.85. Raise it when a false merge costs you more than a missed one. Lower it to catch more variants, and review the extra matches. Test changes on a labeled sample of pairs from your own menus.
resp = requests.post(f"{BASE}/match", headers=headers,
json={"pairs": pairs, "cosine_threshold": 0.90})On the benchmark
On the public FoodEval benchmark, Latimal is first on all seven matching tasks, with a mean best-F1 of 0.851. Test /match on pairs from your own menus to set your threshold. Read about FoodEval.
Tips
- Send raw item names. Promo text, prices and serving sizes are stripped before comparison.
- Keep your item IDs on your side. /match echoes the text you sent, so join results back by position.
- For duplicates inside one menu, Menu deduplication shows how to cluster the whole list in one call.
Limits
- Pairs: 1 to 100 per request
- 500 characters per text
- Results in submission order