Centralized bean catalog (Step 1): schema, migration, export, audit#9
Merged
Conversation
Introduces a SQLite catalog (Postgres-portable via SQLModel) as the source of
truth for the data — replacing the flat JSONL manifest's single-label, no-
provenance model. Step 1 of the data-curation plan; the model stays unchanged
(training still reads an exported manifest).
Schema (`src/almendra/db/models.py`):
- source / lot (provenance: farm, variety, altitude, process, harvest/wash/
hulling dates, humidity) / bean / bean_view (multi-view + multi-spectral) /
defect_class + morphology_class (seeded from taxonomy) / bean_defect.
- bean_defect is a many-to-many junction → multi-label by construction, with
is_primary (SCA most-severe), label_source (dataset|human_verified|
model_weak) and a trust score. provenance_type separates public vs private.
Tooling:
- `almendra db {init,migrate,export-manifest,audit}` CLI.
- migrate.py imports the existing manifest idempotently (1507 beans);
export.py writes a training manifest, gated on is_good + provenance
(public-only by default, private opt-in via --all-provenance) + min trust.
- BeanRecord gains a multi-label `defects` list (back-compatible with legacy
manifests).
- audit.py reports composition + integrity (license-blocked sources, missing
views).
The catalog.db is git-ignored and regenerable via `almendra db migrate`. DVC
for image blobs is deferred until a remote is chosen (see ADR-0006). New
`catalog` extra (sqlmodel, imagehash). Tests in tests/test_db.py (seed counts,
idempotent migration, export round-trip, good/provenance gating, back-compat).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This was referenced May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Step 1 of the data-curation plan: a centralized catalog as the source of truth for the data, replacing the flat JSONL manifest's single-label / no-provenance model. The training pipeline is unchanged — it still reads a manifest, now exported from the catalog.
Backend: SQLite now, Postgres-portable via SQLModel. Images stay on disk; the catalog holds paths + labels + metadata, so it stays small as the data grows.
Schema (
src/almendra/db/models.py)source/lot/bean/bean_view/defect_class+morphology_class/bean_defect.bean_defectis a bean↔defect junction, so a bean can carry several defects — withis_primary(SCA most-severe),label_source(dataset|human_verified|model_weak) and atrustscore.lot: farm, producer, region, country, altitude, variety, species, process, harvest/wash/hulling dates, humidity (mostly null for public lots, full for private).lot.provenance_type(public_dataset|proprietary).Tooling
almendra db {init,migrate,export-manifest,audit}.migrate.pyimports the existing manifest idempotently (1507 beans → beans/views/defects).export.pywrites a training manifest, gated onis_good+ provenance (public-only by default; private opt-in with--all-provenance) +--min-trust. Each record carries the multi-labeldefectslist plus the back-compat primarydefect_class/defect_index.audit.pyreports composition (by provenance/source/split/class/label-source) + integrity (license-blocked sources holding beans, beans missing views).BeanRecordgains adefectslist (legacy manifests load fine — defaults to[]).Notes / deferred
data/catalog.dbis git-ignored and regenerable viaalmendra db migrate.dvc addrestructures storage); the catalog doesn't depend on it. Seedocs/adr/0006-centralized-bean-catalog.md.Verification
uv run pytest -m "not e2e"→ 73 passed, 1 skipped (e2e);ruff check .+ format clean.almendra db migrate→ 1507 beans, re-run skips all (idempotent);almendra db auditprints sane composition;db export-manifestround-trips the manifest.tests/test_db.py: seed counts, idempotent migration, export round-trip, good/provenance gating, BeanRecord back-compat.🤖 Generated with Claude Code