How uktrade/matchbox works
Purpose and Entry Points
Matchbox is a Python record-matching pipeline orchestrator. It composes source data, deduplication/linking models, and resolution steps while indexing warehouse data rather than storing raw records. Primary user entry points are the client API/CLI (src/matchbox/client/cli/main.py, src/matchbox/client/_handler/main.py) and the optional HTTP server (src/matchbox/server/api/main.py).
Client Pipeline Definition
The client provides the domain-facing API for declaring sources, locations, models, queries, DAGs, and result access. Pipeline structure and execution-oriented steps are represented across src/matchbox/client/dags.py, src/matchbox/client/steps.py, and src/matchbox/client/sources.py. Client handlers form the boundary to server-backed operations: src/matchbox/client/_handler/query.py and src/matchbox/client/_handler/eval.py.
Matching Methodologies
Pluggable matching implementations separate deduplication from cross-source linking. Base contracts and built-in strategies are in src/matchbox/client/models/dedupers/base.py, src/matchbox/client/models/linkers/base.py, and src/matchbox/client/models/linkers/splinklinker.py; deterministic and weighted/probabilistic variants coexist. Comparisons and model configuration are centralized in src/matchbox/client/models/comparison.py and src/matchbox/client/models/models.py.
Resolution and Query Flow
A declared DAG combines source configurations and matching steps into reusable resolutions. Resolvers consume matching outputs to form queryable entity/group results, with component logic in src/matchbox/client/resolvers/components.py and orchestration in src/matchbox/client/resolvers/resolvers.py. Consumers retrieve resolved records through src/matchbox/client/queries.py and src/matchbox/client/results.py, preserving the separation between matching metadata and underlying warehouse data.
Evaluation and Human Feedback
Match quality is measurable and iteratively improved through evaluation samples, judgments, and a terminal UI. Core evaluation support is in src/matchbox/client/eval/samples.py and src/matchbox/common/eval.py; the interactive evaluator is rooted at src/matchbox/client/cli/eval/app.py. Server evaluation routes and persistence adapters expose this workflow to shared users: src/matchbox/server/api/routers/eval.py, src/matchbox/server/postgresql/adapter/eval.py.
Server, Authorization, and Persistence
The server exposes API routers for authentication, collections, groups, evaluation, and main/query operations via src/matchbox/server/api/routers/auth.py, src/matchbox/server/api/routers/collections.py, and src/matchbox/server/api/routers/groups.py. PostgreSQL is the durable metadata/index backend, implemented through ORM, adapter, and migration layers in src/matchbox/server/postgresql/orm.py, src/matchbox/server/postgresql/adapter/main.py, and src/matchbox/server/postgresql/alembic/. Upload handling is isolated in src/matchbox/server/uploads.py.
Shared Contracts and Runtime Infrastructure
Shared DTOs, data types, Arrow/database integration, transformations, hashing, and exception conventions live under src/matchbox/common/dtos.py, src/matchbox/common/arrow.py, and src/matchbox/common/db.py. The project runs as a Python package; server deployment is containerized through src/matchbox/server/Dockerfile and docker-compose.yml, with PostgreSQL as the material external service.
Main entry points: api/main.py HTTP API · adapter/main.py PostgreSQL adapters · dags.py Pipeline DAGs · steps.py Execution steps
Components 20
Client SDK & CLI
Pipeline declaration, execution, results, and local evaluation.
- Client CLI
src/matchbox/client/cli/main.py - Client handler
src/matchbox/client/_handler/main.py - Pipeline DAGs · Composes sources and matching steps into reusable resolutions.
src/matchbox/client/dags.py - Execution steps
src/matchbox/client/steps.py - Sources & locations
src/matchbox/client/sources.py - Models & comparisons
src/matchbox/client/models/models.py - Deduplication strategies
src/matchbox/client/models/dedupers/base.py - Linking strategies · Includes cross-source strategies such as Splink.
src/matchbox/client/models/linkers/splinklinker.py - Resolvers · Turns matching outputs into entity and group results.
src/matchbox/client/resolvers/resolvers.py - Queries & results · Retrieves resolved records without copying warehouse data.
src/matchbox/client/results.py - Evaluation samples
src/matchbox/client/eval/samples.py - Evaluator TUI
src/matchbox/client/cli/eval/app.py
Server
Optional shared HTTP API and metadata services.
- HTTP API
src/matchbox/server/api/main.py - Auth, collection & group routes
src/matchbox/server/api/routers/auth.py - Evaluation routes
src/matchbox/server/api/routers/eval.py - PostgreSQL adapters
src/matchbox/server/postgresql/adapter/main.py - Upload handling
src/matchbox/server/uploads.py - Container deployment · Runs the server alongside PostgreSQL.
docker-compose.yml
Shared Core
Contracts and warehouse integration used across runtimes.
- Shared DTOs & warehouse integration · Provides DTOs, Arrow/database access, transforms, hashes, and exceptions.
src/matchbox/common/dtos.py
Other components
- PostgreSQL · Durable metadata and indexes; raw records remain in warehouse sources.
Connections 23
- Client CLI → Pipeline DAGs: declares pipelines
- Client CLI → Evaluator TUI: runs
- Pipeline DAGs → Sources & locations: uses
- Pipeline DAGs → Execution steps: orders
- Execution steps → Models & comparisons: configures
- Models & comparisons → Deduplication strategies: selects
- Models & comparisons → Linking strategies: selects
- Execution steps → Resolvers: produces matching outputs
- Resolvers → Queries & results: forms resolved results
- Queries & results → Client handler: queries through
- Client handler → HTTP API: calls
- HTTP API → Auth, collection & group routes: serves
- HTTP API → Evaluation routes: serves
- HTTP API → Upload handling: accepts uploads
- Auth, collection & group routes → PostgreSQL adapters: persists metadata
- Evaluation routes → PostgreSQL adapters: persists judgments
- PostgreSQL adapters → PostgreSQL: reads and writes
- Evaluator TUI → Evaluation samples: collects judgments
- Evaluation samples → Client handler: submits samples
- Sources & locations → Shared DTOs & warehouse integration: accesses warehouse data
- PostgreSQL adapters → Shared DTOs & warehouse integration: uses contracts
- Container deployment → HTTP API: deploys
- Container deployment → PostgreSQL: provisions