Metadata-Version: 2.5
Name: entmatch
Version: 0.3.0rc1
Summary: Typed, calibrated, auditable entity matching and comparison library.
Project-URL: Source, https://github.com/CreAI-mx/match
Project-URL: Changelog, https://github.com/CreAI-mx/match/blob/master/CHANGELOG.md
Author: CreAI-mx
License-Expression: Apache-2.0
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
Keywords: dedupe,embeddings,entity-linking,entity-matching,record-linkage
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: numpy>=1.26
Requires-Dist: pydantic<3,>=2.6
Requires-Dist: pyyaml>=6.0
Provides-Extra: all
Requires-Dist: anthropic>=0.30; extra == 'all'
Requires-Dist: boto3>=1.34; extra == 'all'
Requires-Dist: faiss-cpu>=1.8; extra == 'all'
Requires-Dist: fastapi>=0.110; extra == 'all'
Requires-Dist: gliner>=0.2; extra == 'all'
Requires-Dist: hnswlib>=0.8; extra == 'all'
Requires-Dist: networkx>=3; extra == 'all'
Requires-Dist: openai>=1.30; extra == 'all'
Requires-Dist: openpyxl>=3.1; extra == 'all'
Requires-Dist: pandas>=2; extra == 'all'
Requires-Dist: pdf2image>=1.17; extra == 'all'
Requires-Dist: pillow>=10; extra == 'all'
Requires-Dist: polars>=1; extra == 'all'
Requires-Dist: pyarrow>=14; extra == 'all'
Requires-Dist: pypdf>=4; extra == 'all'
Requires-Dist: pypdfium2>=4; extra == 'all'
Requires-Dist: rapidfuzz>=3; extra == 'all'
Requires-Dist: sentence-transformers>=3; extra == 'all'
Requires-Dist: sentence-transformers>=6.3; extra == 'all'
Requires-Dist: spacy>=3.7; extra == 'all'
Requires-Dist: torch>=2; extra == 'all'
Requires-Dist: transformers>=4.40; extra == 'all'
Requires-Dist: uvicorn>=0.29; extra == 'all'
Provides-Extra: anthropic
Requires-Dist: anthropic>=0.30; extra == 'anthropic'
Provides-Extra: arrow
Requires-Dist: pyarrow>=14; extra == 'arrow'
Provides-Extra: assign
Requires-Dist: scipy>=1.11; extra == 'assign'
Provides-Extra: bedrock
Requires-Dist: boto3>=1.34; extra == 'bedrock'
Provides-Extra: dedupe
Requires-Dist: btrees<6; extra == 'dedupe'
Requires-Dist: dedupe>=3; extra == 'dedupe'
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: httpx>=0.27; extra == 'dev'
Requires-Dist: hypothesis>=6; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pandas-stubs; extra == 'dev'
Requires-Dist: pandas>=2; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Requires-Dist: twine>=5; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.25; extra == 'docs'
Provides-Extra: faiss
Requires-Dist: faiss-cpu>=1.8; extra == 'faiss'
Provides-Extra: fast
Requires-Dist: faiss-cpu>=1.8; extra == 'fast'
Requires-Dist: rapidfuzz>=3; extra == 'fast'
Provides-Extra: gliner
Requires-Dist: gliner>=0.2; extra == 'gliner'
Provides-Extra: graph
Requires-Dist: networkx>=3; extra == 'graph'
Provides-Extra: hnsw
Requires-Dist: hnswlib>=0.8; extra == 'hnsw'
Provides-Extra: lite
Requires-Dist: openpyxl>=3.1; extra == 'lite'
Requires-Dist: pandas>=2; extra == 'lite'
Requires-Dist: rapidfuzz>=3; extra == 'lite'
Provides-Extra: local
Requires-Dist: sentence-transformers>=3; extra == 'local'
Provides-Extra: openai
Requires-Dist: openai>=1.30; extra == 'openai'
Provides-Extra: pandas
Requires-Dist: pandas>=2; extra == 'pandas'
Provides-Extra: pdf
Requires-Dist: pdf2image>=1.17; extra == 'pdf'
Requires-Dist: pillow>=10; extra == 'pdf'
Requires-Dist: pypdf>=4; extra == 'pdf'
Requires-Dist: pypdfium2>=4; extra == 'pdf'
Provides-Extra: polars
Requires-Dist: polars>=1; extra == 'polars'
Provides-Extra: r2
Requires-Dist: huggingface-hub>=0.24; extra == 'r2'
Requires-Dist: sentence-transformers>=6.3; extra == 'r2'
Provides-Extra: sbert
Requires-Dist: sentence-transformers>=3; extra == 'sbert'
Provides-Extra: serve
Requires-Dist: fastapi>=0.110; extra == 'serve'
Requires-Dist: sentence-transformers>=6.3; extra == 'serve'
Requires-Dist: uvicorn>=0.29; extra == 'serve'
Provides-Extra: spacy
Requires-Dist: spacy>=3.7; extra == 'spacy'
Provides-Extra: tables
Requires-Dist: pillow>=10; extra == 'tables'
Requires-Dist: torch>=2; extra == 'tables'
Requires-Dist: transformers>=4.40; extra == 'tables'
Provides-Extra: train
Requires-Dist: scikit-learn>=1.3; extra == 'train'
Requires-Dist: sentence-transformers[train]>=3; extra == 'train'
Requires-Dist: torch>=2; extra == 'train'
Provides-Extra: xlsx
Requires-Dist: openpyxl>=3.1; extra == 'xlsx'
Requires-Dist: pandas>=2; extra == 'xlsx'
Description-Content-Type: text/markdown

# entmatch

<p align="center"><b>Typed, calibrated, auditable entity matching and comparison library.</b><br>
Domain-agnostic. Core deps: pydantic v2 + numpy.</p>

<p align="center">
  <img alt="python" src="https://img.shields.io/badge/python-3.11%2B-4f46e5">
  <img alt="licence" src="https://img.shields.io/badge/licence-Apache--2.0-0d9488">
  <img alt="mypy" src="https://img.shields.io/badge/mypy-strict-4f46e5">
  <img alt="deps" src="https://img.shields.io/badge/core%20deps-3-64748b">
</p>

[Install](#install) | [Quickstart](#60-second-quickstart) | [CLI](#outputs)

Pre-release (alpha). Links to `github.com/CreAI-mx/match` point to the source repository, which is private: they open only with access.

---

## What it does

You give entmatch a messy line of text and a catalog of official entries. It returns the entry it thinks you meant, a confidence from 0 to 100%, and one decision: **Sure**, **Not sure** or **Not in catalog**. When it is unsure, it says so and asks a human, instead of guessing.

Messy input goes in; a decision with a confidence comes out.

---

## Business glossary: teach entmatch your company's words

Clients write `GFR`, `TDC`, `SAT`, `x`, brand names and internal codes. No model can guess them. The **business glossary** is a file where you register what those terms mean (acronyms, synonyms, brands, codes, `value_map` yes/no values). Domain terms are expanded before scoring, so the ranker sees both forms.

- **Deterministic**: exact term lookup, no model call, no training.
- **Only `status=approved` rows act.** Proposed and rejected rows are ignored. An empty status counts as approved (a human wrote the row).
- **No acronym is assumed.** Unknown terms are listed in `unknown_terms.md` on every run for the client to answer.
- **No glossary = byte-identical output** (empty file or only non-approved rows too).

Register it (file formats `.csv`, `.tsv`, `.yaml`/`.yml`, `.json`; columns `term, expansion, type, field, client, direction, lang, status`):

```csv
term,expansion,type,field,client,direction,lang,status
GFR,Gerencia de Finanzas Regional,acronym,departamento,,both,es,approved
@bool,,value_map,activo,,,,approved
```

```python
from entmatch import Catalog
rows = [{"term": "GFR", "expansion": "Gerencia de Finanzas Regional", "type": "acronym",
         "field": "departamento", "status": "approved"}]
cat = Catalog(generator="lexical", glossary=rows)   # or glossary="glossary.csv"
```

Command line (works on the base install; add `--client NAME` for client-scoped rows):

```bash
entmatch match --preset lexical --catalog refs.jsonl --queries queries.csv --out out/results.csv --glossary glossary.csv
```

`refs.jsonl` holds one catalog entry per line (`{"id": "o1", "name": "Acme Industries"}`); `queries.csv` needs a `query` column.

Measured (R2 frozen protocol, English, `acronym_collision`, n=750, synthetic): top-1 0.129 off -> 0.973 with glossary alone. Warning from the same run: enabling every feature together (`all_on`) fell to 0.001 (cause unknown). Turn features on one at a time and measure. A later lexical run did not reproduce the drop (`all_on` 1.000), so the R2 loss is an open item. Synthetic data, not client data.

Full reference (file format, scoping, unknown-terms loop, caveats): [docs/skill/references/glossary.md](https://github.com/CreAI-mx/match/blob/master/docs/skill/references/glossary.md).

---

## Install

```bash
pip install entmatch
```

While only pre-releases exist you can pin one: `pip install entmatch==0.3.0rc1`.

| Extra | Adds |
|---|---|
| `entmatch[xlsx]` | `.xlsx` input and output |
| `entmatch[lite]` | xlsx / pandas ingest and a faster lexical matcher, no torch |
| `entmatch[r2]` | ENTMATCH-R2 model |
| `entmatch[serve]` | ENTMATCH-R2 plus HTTP API (CPU) |

The trained ENTMATCH-R2 model ([felipedjrg3/entmatch-r2](https://huggingface.co/felipedjrg3/entmatch-r2), 2.4 GB) is not inside the package: with `[r2]` or `[serve]` it downloads on first use, then runs offline. CPU only, no GPU. For CPU-only torch, install it first from the PyTorch CPU index.

The source repository also ships a coding-agent skill ([docs/skill](https://github.com/CreAI-mx/match/blob/master/docs/skill/SKILL.md)) with playbooks and a quality gate; it is not part of the package.

---

## How it works

Real output of [hero_plans.py](https://github.com/CreAI-mx/match/blob/master/docs/examples/hero_plans.py), offline basic mode.

<table width="100%">
  <tr>
    <th align="left">What was typed</th>
    <th align="left">Decision</th>
    <th align="left">Catalog entry</th>
    <th align="right">Confidence</th>
  </tr>
  <tr><td><code>INV-2291 | GOLD PLUS PPO | 2026 | $412.00</code></td><td>🟢 Sure</td><td>GOLD-PPO</td><td align="right">91%</td></tr>
  <tr><td><code>Hola, el empleado pasa al plan Oro Plus PPO…</code></td><td>🟡 Not sure</td><td>GOLD-PPO (probably)</td><td align="right">75%</td></tr>
  <tr><td><code>Gold Plus</code></td><td>🟡 Not sure</td><td>GOLD-PPO or GOLD-HMO?</td><td align="right">63%</td></tr>
  <tr><td><code>Platinum Max EPO</code></td><td>⚪ Not in catalog</td><td>none</td><td align="right">32%</td></tr>
</table>

Scores of the 4 inputs above against the default thresholds. Source: [QUICKSTARTS.md](https://github.com/CreAI-mx/match/blob/master/docs/examples/QUICKSTARTS.md).

Default thresholds ([threshold.py:32-34](https://github.com/CreAI-mx/match/blob/master/src/entmatch/builtin/deciders/threshold.py)): Sure >= 80% (`match`), Not sure 50-80% (`review`), Not in catalog < 50% (`abstain`).

---

## Results on 100 records

Run with the benchmark script in the source repository (not part of the package).

<table width="100%">
  <tr>
    <th align="left">100 synthetic inputs vs a 100-entry catalog (85 in it, 15 not)</th>
    <th align="right">ENTMATCH-R2</th>
    <th align="right">Lexical baseline</th>
  </tr>
  <tr><td>Top-1 accuracy (the 85 in catalog)</td><td align="right">97.6% (83/85)</td><td align="right">80.0%</td></tr>
  <tr><td>Auto-accept precision</td><td align="right">100.0% (30/30)</td><td align="right">79.2% (19/24)</td></tr>
  <tr><td>Not-in-catalog auto-rejected (of 15)</td><td align="right">0 (all 15 sent to review)</td><td align="right">0</td></tr>
</table>

Synthetic data, n=100, 70 of 100 went to a human. Source: [bench100 results](https://github.com/CreAI-mx/match/blob/master/docs/examples/bench100/README.md) (3 identical runs, CPU).

---

## 60-second quickstart

After [install](#install). No extra needed.

```python
import entmatch as em

# The catalog: the official list you match against.
catalog = [
    {"id": "o1", "name": "Acme Industries", "aliases": ["ACME Ind."]},
    {"id": "o2", "name": "Borealis Logistics"},
    {"id": "o3", "name": "Cobalt Mining Co"},
]

# Link messy names (one or many) to catalog entries.
found, typo, unknown = em.link(["Acme Industries Inc", "Borealis Logistic", "Zzz Unknown Ltd"], catalog)

# Each result has .chosen_id: the catalog id, or None when nothing fits.
print(found.chosen_id)    # o1   -> matched
print(typo.chosen_id)     # o2   -> matched despite the typo
print(unknown.chosen_id)  # None -> not in the catalog
print(em.explain(found))  # why, in plain words
```

<details>
<summary><b>More examples</b> (rank with history, reconcile documents, run all)</summary>

See [QUICKSTARTS.md](https://github.com/CreAI-mx/match/blob/master/docs/examples/QUICKSTARTS.md).

</details>

---

## Outputs

One result per input. Pick the view: JSONL for code, CSV for a reviewer, XLSX for an owner, Markdown for a PR.

```bash
# many inputs from a file -> one row per input, top-5 candidates side by side, empty reviewer column
entmatch match --preset lexical --catalog refs.jsonl --queries queries.csv --out review.csv
```

Without `--preset` the CLI uses `entmatch-r2`, which needs `pip install "entmatch[serve]"`.

<table width="100%">
  <tr><th align="left">Format</th><th align="left">What you get</th><th align="left">How</th></tr>
  <tr><td><code>jsonl</code></td><td>Raw result dicts, every field</td><td>default (stdout) or <code>--out r.jsonl</code></td></tr>
  <tr><td><code>csv</code></td><td>1 row per input, top-5 flattened, plain-words reason, empty <code>reviewer_decision</code></td><td><code>--out r.csv</code></td></tr>
  <tr><td><code>csv-long</code></td><td>1 row per (input, rank): pivot-ready</td><td><code>--out r.csv --format csv-long</code></td></tr>
  <tr><td><code>xlsx</code></td><td>summary + results (colour per decision) + topk sheets</td><td><code>--out r.xlsx</code> (<code>[xlsx]</code> extra)</td></tr>
  <tr><td><code>md</code></td><td>Report: counts, thresholds, alerts, top-5 per input</td><td><code>--out r.md</code></td></tr>
</table>

<p align="center"><sub>All fields, a real input vs the registered catalog with its top-5, and the cost per format: <a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/outputs.md">outputs.md</a>.</sub></p>

---

## Architecture

One base model, **R2** (preset `entmatch-r2`), finds the top candidates. A **client rules layer after R2** applies each client's knowledge (glossary, typed values, field weights, filters, never-match pairs) without retraining R2. Every client stage is off by default: off = byte-identical output.

Flow: messy input -> glossary expand -> R2 top-K retrieval -> client rules layer (canon, weights, filters, must_match, never_match) -> calibrator and thresholds -> `match` / `review` / `nil` + outputs. Unknown terms go to a reviewer, whose answers feed the knowledge pack used by the glossary and rules.

Full ladder (one diagram per level), stage table, which rule wins when rules conflict, and what is parked: [architecture.md](https://github.com/CreAI-mx/match/blob/master/docs/skill/references/architecture.md).

## Features

<table width="100%">
  <tr><th align="left">Feature</th><th align="left">Status</th><th align="left">Docs</th></tr>
  <tr><td>R2 retrieval, calibrated decision <code>match</code> / <code>review</code> / <code>nil</code>, NIL detector</td><td>on</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/nil-and-abstain.md">nil-and-abstain</a></td></tr>
  <tr><td>Export <code>jsonl</code> / <code>csv</code> / <code>csv-long</code> / <code>xlsx</code> / <code>md</code></td><td>on</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/outputs.md">outputs</a></td></tr>
  <tr><td>Unknown terms report on every <code>entmatch match</code> run</td><td>on</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/glossary.md">glossary</a></td></tr>
  <tr><td>Client glossary (acronyms, codes, yes/no values), field and client scoped</td><td>opt-in</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/glossary.md">glossary</a></td></tr>
  <tr><td>Typed value canon (bool, date, number, money, unit, phone, id)</td><td>opt-in</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/values.md">values</a></td></tr>
  <tr><td>Business field weights and <code>must_match</code></td><td>opt-in</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/business-weights.md">business-weights</a></td></tr>
  <tr><td>Semantic weights, category filters, <code>agreement</code>, <code>discard_if_differs</code></td><td>opt-in</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/semantic-rules.md">semantic-rules</a></td></tr>
  <tr><td>Versioned client knowledge pack (overlays, never-match, rollback), <code>entmatch pack</code></td><td>opt-in</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/knowledge-pack.md">knowledge-pack</a></td></tr>
  <tr><td>Exact code / ID channel</td><td>opt-in</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/feature-inventory.md">feature-inventory</a></td></tr>
  <tr><td>Eval protocol (prereg, exact McNemar, headroom, seeds, calibration)</td><td>dev tool</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/eval-protocol.md">eval-protocol</a></td></tr>
  <tr><td>Learned client reranker (L2)</td><td>parked</td><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/GRAVEYARD.md">GRAVEYARD</a></td></tr>
</table>

<p align="center"><sub>Full status with evidence and numbers per feature: <a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/feature-inventory.md">feature-inventory.md</a>.</sub></p>

---

## Supported languages

| language | status | evidence |
|---|---|---|
| English | measured | R2 frozen protocol, 5 seeds, n=750 per cell |
| Spanish | measured | same protocol and slices |
| mixed Spanish/English input | unmeasured | no mixed-language slice exists |
| other languages | unmeasured | no data; base-model coverage not documented here |

Measured on synthetic slices, not client data. Known weak spot: Spanish acronyms sit at the floor (top-1 .008-.025) until a glossary is on. Evidence and per-slice numbers: [languages.md](https://github.com/CreAI-mx/match/blob/master/docs/skill/references/languages.md).

## Glossary and business rules

Client knowledge the model cannot know, all opt-in (off = byte-identical output):

- **Glossary**: `--glossary glossary.csv` (columns `term, expansion, type, field, client, direction, lang, status`). Field-scoped, only `approved` rows act, acronyms are never assumed: every run writes `unknown_terms.md` for the client to answer, then `entmatch glossary import`.
- **Business rules** (one YAML, `business_weights:`): per-field weights, `must_match`, semantic weights, category filters, `agreement`, `discard_if_differs`; never-match pairs live in the client pack.
- Measured effect per rule, config examples and what is still unmeasured: [business-rules.md](https://github.com/CreAI-mx/match/blob/master/docs/skill/references/business-rules.md).

## No GPU needed

ENTMATCH-R2 (hosted on Hugging Face: [felipedjrg3/entmatch-r2](https://huggingface.co/felipedjrg3/entmatch-r2), 2.4 GB) runs on CPU. The first run downloads it once (2.4 GB), then it is cached. Only training needs a GPU, and you do not need to train.

Needs `pip install "entmatch[serve]"`:

```bash
CUDA_VISIBLE_DEVICES="" OMP_NUM_THREADS=8 entmatch match --catalog refs.jsonl --query "Oro Plus PPO plan" --preset entmatch-r2 --device cpu --threads 8
```

<table width="100%">
  <tr><th align="left">What</th><th align="right">Measured</th></tr>
  <tr><td>One query, median</td><td align="right">229.2 ms</td></tr>
  <tr><td>Worst usual case (p95)</td><td align="right">292.0 ms</td></tr>
  <tr><td>Sustained</td><td align="right">5.63 queries/s</td></tr>
  <tr><td>Machine</td><td align="right">8 CPU cores, no GPU, 3.42 GB RAM</td></tr>
</table>

Fewer than 8 cores not measured. Deploy details: [HOW_TO_USE](https://github.com/CreAI-mx/match/blob/master/docs/HOW_TO_USE.md#10-deploy-on-a-cpu-vm-16-gb-ram-8-cores-no-gpu).

---

## Learn more

<table width="100%">
  <tr><td width="35%"><a href="https://github.com/CreAI-mx/match/blob/master/docs/HOW_TO_USE.md"><b>HOW_TO_USE</b></a></td><td>Step-by-step deep dive: install to deploy, client onboarding, unknown-terms loop, knowledge pack, eval protocol</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/REFERENCE.md"><b>REFERENCE</b></a></td><td>CLI, catalog workflow, output fields, ENTMATCH-R2, troubleshooting, dev setup</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/examples/QUICKSTARTS.md"><b>Examples</b></a> and <a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/SKILL.md"><b>skill</b></a></td><td>Runnable examples, and the <code>match</code> skill</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/outputs.md"><b>Outputs</b></a></td><td>Every output format, all fields, a worked top-5 example</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/languages.md"><b>Languages</b></a> and <a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/business-rules.md"><b>business rules</b></a></td><td>Supported languages with evidence; glossary and client rules, measured effects</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/skill/references/architecture.md"><b>Architecture</b></a></td><td>R2 + client rules layer after R2, stage order, rule precedence</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/ACCURACY.md"><b>Accuracy and charts</b></a></td><td>Measured results</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/site/quickstart.md"><b>Site docs</b></a></td><td>Quickstart pages</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/site/troubleshooting.md"><b>Troubleshooting</b></a></td><td>Common problems and fixes</td></tr>
  <tr><td><a href="https://github.com/CreAI-mx/match/blob/master/docs/REFERENCE.md#contribute"><b>Contributing</b></a></td><td>Dev setup. License: Apache-2.0</td></tr>
</table>
