custmatch-server 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. custmatch_server-0.1.0/LICENSE +202 -0
  2. custmatch_server-0.1.0/NOTICE +24 -0
  3. custmatch_server-0.1.0/PKG-INFO +289 -0
  4. custmatch_server-0.1.0/README.md +259 -0
  5. custmatch_server-0.1.0/custmatch_server/__init__.py +7 -0
  6. custmatch_server-0.1.0/custmatch_server/__main__.py +92 -0
  7. custmatch_server-0.1.0/custmatch_server/api.py +869 -0
  8. custmatch_server-0.1.0/custmatch_server/auth.py +86 -0
  9. custmatch_server-0.1.0/custmatch_server/db.py +279 -0
  10. custmatch_server-0.1.0/custmatch_server/health.py +127 -0
  11. custmatch_server-0.1.0/custmatch_server/loader.py +166 -0
  12. custmatch_server-0.1.0/custmatch_server/matcher.py +834 -0
  13. custmatch_server-0.1.0/custmatch_server/migrations/env.py +7 -0
  14. custmatch_server-0.1.0/custmatch_server/migrations/script.py.mako +22 -0
  15. custmatch_server-0.1.0/custmatch_server/migrations/versions/0001_initial.py +135 -0
  16. custmatch_server-0.1.0/custmatch_server/migrations/versions/0002_overrides.py +43 -0
  17. custmatch_server-0.1.0/custmatch_server/migrations/versions/0003_api_keys.py +31 -0
  18. custmatch_server-0.1.0/custmatch_server/migrations/versions/0004_stewardship.py +70 -0
  19. custmatch_server-0.1.0/custmatch_server/migrations/versions/0005_decisions.py +52 -0
  20. custmatch_server-0.1.0/custmatch_server/scheduler.py +147 -0
  21. custmatch_server-0.1.0/custmatch_server/schema.py +206 -0
  22. custmatch_server-0.1.0/custmatch_server/static/dashboard.html +1046 -0
  23. custmatch_server-0.1.0/custmatch_server/worker.py +160 -0
  24. custmatch_server-0.1.0/custmatch_server.egg-info/PKG-INFO +289 -0
  25. custmatch_server-0.1.0/custmatch_server.egg-info/SOURCES.txt +29 -0
  26. custmatch_server-0.1.0/custmatch_server.egg-info/dependency_links.txt +1 -0
  27. custmatch_server-0.1.0/custmatch_server.egg-info/entry_points.txt +2 -0
  28. custmatch_server-0.1.0/custmatch_server.egg-info/requires.txt +10 -0
  29. custmatch_server-0.1.0/custmatch_server.egg-info/top_level.txt +1 -0
  30. custmatch_server-0.1.0/pyproject.toml +34 -0
  31. custmatch_server-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,24 @@
1
+ custmatch
2
+ Copyright 2026 Andrew Goodchild
3
+
4
+ Licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ patches/ditto-mps-and-fixes.patch modifies Ditto (https://github.com/megagonlabs/ditto),
7
+ Copyright Megagon Labs, licensed under the Apache License, Version 2.0. The patch contains
8
+ lines of Ditto's source as diff context.
9
+
10
+ No third-party datasets are included in the current tree. (Earlier commits in the history
11
+ contained the nickname list below and a Wikidata name list, CC0, since removed.) custmatch
12
+ downloads it into ~/.cache/custmatch (or $CUSTMATCH_DATA) when first needed:
13
+
14
+ - nicknames.csv: the carltonnorthern/nicknames list (https://github.com/carltonnorthern/nicknames,
15
+ commit ed160b3), Copyright its contributors, licensed under the Apache License, Version 2.0.
16
+ Downloaded unmodified on first use and checked against its SHA-256.
17
+
18
+
19
+ Other datasets used by the research scripts are not included either. Scripts download or generate them (FEBRL and
20
+ historical_50k via recordlinkage and splink, the Magellan / DeepMatcher and MatchGPT
21
+ benchmarks from their own repositories, synthetic people via pseudopeople, name frequencies
22
+ from the US Census and Social Security via the FiveThirtyEight data repository (CC BY 4.0)
23
+ for the Australian test file), each under its own licence; see docs/reproducing.md. Files in results/ are metrics and logs computed from
24
+ them.
@@ -0,0 +1,289 @@
1
+ Metadata-Version: 2.4
2
+ Name: custmatch-server
3
+ Version: 0.1.0
4
+ Summary: custmatch as a self-hosted service: scheduled batch runs, real-time matching, a steward dashboard
5
+ Author: Andrew Goodchild
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/andrewgoodchild/custmatch
8
+ Project-URL: Documentation, https://github.com/andrewgoodchild/custmatch/blob/main/server/README.md
9
+ Project-URL: Issues, https://github.com/andrewgoodchild/custmatch/issues
10
+ Keywords: entity resolution,record linkage,customer matching,master data management,data stewardship
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Topic :: Database
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ License-File: NOTICE
20
+ Requires-Dist: custmatch>=0.1.0
21
+ Requires-Dist: sqlalchemy>=2
22
+ Requires-Dist: alembic
23
+ Requires-Dist: fastapi
24
+ Requires-Dist: uvicorn
25
+ Requires-Dist: psycopg[binary]
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest; extra == "test"
28
+ Requires-Dist: httpx; extra == "test"
29
+ Dynamic: license-file
30
+
31
+ # custmatch-server: operator guide
32
+
33
+ custmatch-server runs custmatch as a service next to your data: it keeps your customer records
34
+ and their loads in one database, matches them in batch on a schedule, answers "who is this?" in
35
+ real time, and gives data stewards a dashboard to review and correct matches. One image, one
36
+ database (Postgres in production, SQLite for a trial). How it works is below; what it was
37
+ measured at is in the report's chapter on the service
38
+ ([docs/report/12-the-service.md](https://github.com/andrewgoodchild/custmatch/blob/main/docs/report/12-the-service.md)).
39
+
40
+ | Process | Command | What it does |
41
+ | --- | --- | --- |
42
+ | API and dashboard | `custmatch-server serve` | Lookups, real-time matching, overrides, the dashboard at `/dashboard` |
43
+ | Scheduler | `custmatch-server schedule ...` | Loads files dropped in an inbox, runs the batch at set times, checks health, alerts |
44
+ | One-off jobs | `load`, `batch`, `key`, `check` | The same work by hand |
45
+
46
+ All processes share the database (`CUSTMATCH_DB_URL`) and a data directory for run files
47
+ (`CUSTMATCH_DATA_DIR`). Run one API process and one scheduler; the API scales to more copies for
48
+ lookups, but only one holds the write lease for real-time matching at a time.
49
+
50
+ ## How it works
51
+
52
+ ```
53
+ ┌─────────────────────────── custmatch-server ──────────────────────────┐
54
+ files ──► inbox│ scheduler ── load ──────────────┐ │
55
+ │ │ ▼ │
56
+ │ └─ batch run ──publish──► ┌──────────── the database ───────────┐ │
57
+ │ (the custmatch │ source records and every version, │ │
58
+ │ library) │ loads, runs (which one is current), │ │
59
+ your apps ────►│ API: lookups, POST /match ◄──►│ customers, links, golden records, │ │
60
+ │ matcher: one writer, │ history, steward decisions, │ │
61
+ │ index in memory │ audit log, API keys │ │
62
+ stewards ─────►│ dashboard ◄──────────────────►└─────────────────────────────────────┘ │
63
+ └───────────────────────────────────────────────────────────────────────┘
64
+ ```
65
+
66
+ - **One database holds everything shared:** the source records and their loads, the runs and
67
+ which one is current, the results, stewards' decisions and the matcher's lock. Postgres for
68
+ production (many readers and writers, advisory locks, managed everywhere); SQLite on a
69
+ persistent disk for a trial or one small team. The code targets both, so moving from trial to
70
+ production is configuration.
71
+ - **Loads keep history.** A load is full (records missing from it are marked deleted, not
72
+ removed) or incremental. The current version of every record is kept, and every earlier
73
+ version, so "what did this record look like at load N" has an answer. Only the mapped fields
74
+ are stored.
75
+ - **The batch run is the truth.** It is `custmatch run` over every live record - loaded from
76
+ files or arrived through the API - with labels and stewards' decisions read from the database,
77
+ and customer IDs carried over from the current run. It publishes in **one transaction**:
78
+ readers see the old run or the new one, never a mix. The current run and one before it are kept.
79
+ - **Real-time matching is provisional.** `POST /match` scores a record against the current run's
80
+ model in memory - a compact index of hashed blocking keys, built from the batch blocker's own
81
+ key definition - and joins it to the customer it fits: it must match at least half of that
82
+ customer's records, not just one. It merges a second customer only on a link of 0.9 or more.
83
+ Exactly one process writes (a lease); lookups keep working without it. Stewards' decisions,
84
+ trusted IDs, the twin guard and duplicate-free sources apply at once; the next batch run
85
+ reconciles everything, and changes reach users as merges and splits in the history.
86
+ - **The tables** (`custmatch_server/schema.py`, created by versioned migrations):
87
+
88
+ | Table | Holds |
89
+ | --- | --- |
90
+ | `loads` | Every load: source, origin (a file or `api:<day>`), full or incremental, and what it inserted, updated, deleted and left unchanged |
91
+ | `source_records`, `source_record_versions` | The current version of every record, with a content hash and `deleted_at`; and every earlier version |
92
+ | `runs`, `current_run` | The catalog of runs, and the one readers see |
93
+ | `customers`, `record_customer`, `links`, `customer_events` | Per run: golden records, which customer each record is in, the accepted links with evidence, and merges and splits (partitioned by run on Postgres) |
94
+ | `realtime_records`, `realtime_merges`, `realtime_moves` | The API's matching decisions, replayed when the matcher restarts, until a batch run reconciles them |
95
+ | `overrides`, `steward_log`, `golden_pins`, `review_claims` | Stewards' decisions and their approval, the audit log (with each action's note), pinned golden values, and review pairs held by the steward working on them |
96
+ | `api_keys`, `leases` | Hashed API keys with roles, and the matcher's write lease |
97
+
98
+ ## Start it
99
+
100
+ A trial on your machine, with Postgres and the demo data:
101
+
102
+ ```sh
103
+ docker compose -f server/docker-compose.yml up -d --build db api
104
+ docker compose -f server/docker-compose.yml run --rm api key create me --role admin # shown once: keep it
105
+ ```
106
+
107
+ Load the demo (or your own files, below) and run a first batch - one scheduler pass, done by hand:
108
+
109
+ ```sh
110
+ for s in web app store; do cp examples/demo/$s.csv server/inbox/$s.full.csv; done
111
+ docker compose -f server/docker-compose.yml run --rm scheduler \
112
+ schedule /demo/config.json --labels /demo/labels.csv --inbox /inbox --once
113
+ ```
114
+
115
+ Then start the scheduler, which from now on loads what arrives in the inbox and runs the batch
116
+ at 02:00 UTC (only one scheduler works at a time, so a `--once` pass while it runs does nothing
117
+ and says so):
118
+
119
+ ```sh
120
+ docker compose -f server/docker-compose.yml up -d scheduler
121
+ ```
122
+
123
+ Then open http://localhost:8765/dashboard and paste a key with the `steward` (or `admin`) role.
124
+
125
+ The image holds the library's default model only. For the opt-in `"matcher_model":
126
+ "forest_catboost"` (docs/report/03-which-matcher.md "Which classifier"), build it with CatBoost: `CUSTMATCH_EXTRAS=catboost
127
+ docker compose -f server/docker-compose.yml build`, or `docker build --build-arg CUSTMATCH_EXTRAS=catboost
128
+ ...`. A run trained with it cannot be served by an image without it; the API says so.
129
+
130
+ For production, run the same image three ways (API, scheduler, and Postgres you already manage)
131
+ on whatever runs containers for you, with your config and labels mounted where the commands
132
+ point. Without Docker: `pip install ./ ./server` from the repository.
133
+
134
+ ## Configuration
135
+
136
+ | Variable | Default | Meaning |
137
+ | --- | --- | --- |
138
+ | `CUSTMATCH_DB_URL` | `sqlite:///custmatch.db` | The database. Postgres: `postgresql+psycopg://user:password@host/db` |
139
+ | `CUSTMATCH_DATA_DIR` | `data` (`/data` in the image) | Run files: each run's inputs, outputs and model. Shared by every process |
140
+ | `CUSTMATCH_AUTH` | on | `off` answers anyone who can reach the API: a local trial only |
141
+ | `CUSTMATCH_ALERT_WEBHOOK` | none | Where the scheduler posts alerts: any URL taking a JSON POST (`{"text": ..., "checks": [...]}`; Slack incoming webhooks read `text`) |
142
+ | `CUSTMATCH_MAX_RUN_AGE_HOURS` | 36 | Warn when the current run is older |
143
+ | `CUSTMATCH_MAX_CUSTOMER_CHANGE` | 5 | Warn when the customer count moves by more than this % between runs |
144
+ | `CUSTMATCH_MAX_REVIEW` | 1000 | Warn when the review queue is longer |
145
+ | `CUSTMATCH_FOUR_EYES` | off | `on`: a steward's decisions, merges, splits and revocations wait until a different steward approves them (Decisions tab). Needs authentication on |
146
+ | `CUSTMATCH_DB_PASSWORD` | `custmatch` | The Compose file's Postgres password: set it for anything but a local trial |
147
+
148
+ The matching itself is configured by the custmatch config file (sources, columns, rules) and the
149
+ labels file: see the [guide](https://github.com/andrewgoodchild/custmatch/blob/main/docs/guide.md). The database creates and upgrades its own tables
150
+ when any process starts.
151
+
152
+ ## API keys
153
+
154
+ ```sh
155
+ custmatch-server key create NAME --role ROLE # prints the key once; only its hash is stored
156
+ custmatch-server key list
157
+ custmatch-server key revoke NAME # stops working within 30 seconds
158
+ ```
159
+
160
+ | Role | Can |
161
+ | --- | --- |
162
+ | `read` | Look up records and customers, read runs, loads, decisions and health |
163
+ | `match` | Also match records in real time (`POST /match`) |
164
+ | `steward` | Also record decisions (`POST /overrides`): the dashboard's role |
165
+ | `admin` | Everything |
166
+
167
+ Give each person and each system its own key: a steward's decisions are recorded under their
168
+ key's name. `server/sql/roles.sql` sketches least-privilege database roles for Postgres.
169
+
170
+ ## Getting records in
171
+
172
+ **The inbox** (with the scheduler running): drop a file named `<source>.<mode>.<csv|parquet>` -
173
+ `web.full.csv`, `store.incremental.2026-10-05.parquet` - where `source` is a source in your config
174
+ and `mode` is:
175
+
176
+ - `full`: the source's complete contents. Records missing from it are marked deleted (kept, with
177
+ their history, but left out of matching).
178
+ - `incremental`: new and changed records only.
179
+
180
+ The scheduler waits until a file's size has stopped changing, loads it, and moves it to
181
+ `inbox/done/` (or `inbox/failed/`, with an alert). The image runs as user 10001: on Linux, make the
182
+ inbox folder writable by it (`chown 10001 inbox`). Each load is recorded: what it inserted,
183
+ updated, deleted and left unchanged, and every version of every record.
184
+
185
+ **By hand:** `custmatch-server load CONFIG SOURCE FILE [--full]`.
186
+
187
+ **Through the API:** records matched with `POST /match` and `"write": true` are stored as that
188
+ day's API load and included in the next batch run.
189
+
190
+ ## Batch runs and the schedule
191
+
192
+ `custmatch-server schedule CONFIG --labels LABELS --inbox DIR --batch-at 02:00` loads the inbox as
193
+ files arrive and runs the batch at 02:00 UTC daily (repeat `--batch-at` for more). A batch run
194
+ matches every live record, keeps customer IDs stable from the previous run, publishes in one
195
+ transaction (readers see the old run or the new one, never a mix), keeps the previous run for
196
+ rollback, and runs the health checks. Only one scheduler works at a time, even if two are started.
197
+
198
+ With your own scheduler (cron, a Kubernetes CronJob, Airflow), run
199
+ `custmatch-server schedule ... --once` instead: one pass - load the inbox, run a batch, check -
200
+ exiting 0 (ok), 1 (warnings) or 2 (failed).
201
+
202
+ **Stewards' decisions train the model.** Each "same" or "different" a steward records overrides
203
+ that pair at once, and the next batch run also trains on it. Measured on the demo
204
+ (`server/learning_test.py`, `results/server_learning.json`): starting from 200 random labels,
205
+ three rounds of answering the review queue lifted clustered F1 from 79.5 to 88.8 when decisions
206
+ train the model, against 84.1 when they only override their own pairs.
207
+
208
+ ## The dashboard
209
+
210
+ `/dashboard`, with a `steward` key:
211
+
212
+ - **Overview**: health, the current run, loads, recent decisions.
213
+ - **Model & data**: the threshold and accuracy estimates, score distribution, what the model
214
+ relies on, completeness and common values by source, records too sparse to link, blocking,
215
+ runs compared.
216
+ - **Customers**: search for a person; browse customers worth a second look (largest, weakest
217
+ link, ...); sample links by score. A customer shows its golden record, its records as a network
218
+ of links, and why each link scored what it did.
219
+ - **Review**: the uncertain pairs, most uncertain first: same person, different people, or skip
220
+ (keys S, D, K). Filter by source, the model's call or score; a list mode decides many at once;
221
+ a note goes with each decision. Pairs shown to one steward are held from the others for 15
222
+ minutes.
223
+ - **Decisions**: every decision with its author and note; revoke one, approve or reject proposals
224
+ (with `CUSTMATCH_FOUR_EYES=on`), download them as CSV; steward activity, including how often
225
+ each steward overturned the model.
226
+
227
+ In a customer: golden-record lineage (which records hold each value) and pinning a value, which
228
+ beats survivorship in this and every later run; merging with another customer and splitting a
229
+ record out, both previewed before they happen and applied at once; the household; every steward
230
+ action on its records. Under Customers, **Compare** puts any two records side by side and says
231
+ whether blocking would ever compare them (why they did not match); **Find possible matches**
232
+ scores a person you type in, without saving anything. Every panel has an (i) explaining what it
233
+ shows, how it is calculated and what good looks like.
234
+
235
+ ## Monitoring
236
+
237
+ `GET /health` (no key) says the process is up. `GET /status` and `custmatch-server check` run the
238
+ health checks; the scheduler runs them after every batch and posts anything not ok to
239
+ `CUSTMATCH_ALERT_WEBHOOK`.
240
+
241
+ | Check | Warns or fails when |
242
+ | --- | --- |
243
+ | run | there is no published run, or the latest run failed |
244
+ | run_age | the current run is older than `CUSTMATCH_MAX_RUN_AGE_HOURS` |
245
+ | customers | the customer count moved more than `CUSTMATCH_MAX_CUSTOMER_CHANGE` % between runs: look at the run's merges and splits before trusting it |
246
+ | review | the review queue is over `CUSTMATCH_MAX_REVIEW`, or growing fast |
247
+ | loads | a load failed in the last day, or has run for over two hours |
248
+ | realtime | a real-time record has waited longer than the run age limit for a batch run |
249
+
250
+ ## Backup and restore
251
+
252
+ Back up two things together: the database and the data directory.
253
+
254
+ ```sh
255
+ pg_dump -Fc "$DATABASE" > custmatch-$(date +%F).dump # Postgres
256
+ tar czf custmatch-runs-$(date +%F).tgz -C "$CUSTMATCH_DATA_DIR" runs
257
+ ```
258
+
259
+ With SQLite, stop the processes and copy the `.db` file (or use `sqlite3 custmatch.db ".backup copy.db"`).
260
+ Restore both from the same time: the database names the run directories it uses. Only the
261
+ current run and the one before it are kept, so older run directories can be deleted or archived.
262
+
263
+ ## Upgrading
264
+
265
+ 1. Back up (above).
266
+ 2. Stop the scheduler, so no batch run is in progress.
267
+ 3. Start the new image's processes: the database upgrades itself at start (migrations).
268
+ 4. Run `custmatch-server check`.
269
+
270
+ Migrations do not run backwards automatically; to go back, restore the backup and the old image.
271
+
272
+ ## Sizing
273
+
274
+ Measured with Postgres on a laptop (`server/scale_test.py`, `results/server_scale.json`), per
275
+ million records: loads about 1 minute, a batch run about 2.5 minutes (2-3 GB of memory), the
276
+ real-time matcher starts in 6 seconds and holds about 0.5 GB, a real-time match takes 24 ms
277
+ (median) and a lookup 7 ms; the database grows by about 1.8 GB. The batch library has run 10
278
+ million records on one 16-core machine (docs/report/06-blocking-and-scale.md, "Larger files").
279
+
280
+ ## Troubleshooting
281
+
282
+ | Symptom | Look at |
283
+ | --- | --- |
284
+ | `401` from every call | The key: `custmatch-server key list` (revoked?); the header is `Authorization: Bearer <key>` |
285
+ | `409 another matcher holds the write lease` | Another API process is the writer; send writes to one process, or wait 60 s after stopping the old one |
286
+ | A file stays in the inbox | Its name: `<source>.<full|incremental>.<csv|parquet>`, with a source from the config |
287
+ | A file lands in `inbox/failed/` | The scheduler's log and the alert: usually a missing column or an unknown source |
288
+ | "customers" warns after a run | Customers' events in the dashboard (Customers, then a customer's history); a new source or a data problem can merge many customers at once |
289
+ | The review queue keeps growing | More labels help most: answering the queue trains the next run |