Skip to content

fix(ingest): extract equations during ingest, derive schema evolution - #580

Merged
chris-dare-dev merged 2 commits into
mainfrom
fix/batch-n-equations-schema
Nov 21, 2026
Merged

chris-dare-dev merged 2 commits into
mainfrom
fix/batch-n-equations-schema

Conversation

@chris-dare-dev

Copy link
Copy Markdown
Owner

Two equation findings: ingest never extracted equations, and schema evolution only knew the columns it listed by hand.

#550: extract equations during ingest

  • Before, no ingest driver called the equation extractor. A corpus built the normal way had no equations table, so find_equation always fell back to dense_only_fallback.
  • ingest_one_paper now extracts a paper's equations from the HTML it chunked, right after writing the chunks.
  • Bulk ingest and the OAI delta build the equation trees once at the end of a run, under the run's dataset write lock. Notebook ingest goes through bulk ingest, so it gets the same.
  • Each equation is linked to the chunk whose body holds every cell of it as the chunker writes it, preferring a statement chunk. Without that link the chunks-proxy dense step finds no candidate, and the trees alone would not reach ted_fused.
  • The tree indexer is a no-op on a dataset with no equations table, and its CLI refuses a missing dataset path.

#315: derive schema evolution from the schema

  • Before, schema evolution was a hand-kept SQL-default map in ingest.store:
    • it failed on any column it did not list;
    • it reached only the chunks table;
    • equation trees carried no normalizer version, so a tree from an older MathML normalizer could never be re-indexed by a plain run.
  • ingest.schema.add_missing_columns now derives every addition from the table's Arrow schema:
    • a nullable column gets NULL;
    • a column whose existing rows hold a known value (source_kind and license on chunks) takes it from PRE_COLUMN_VALUES;
    • a required column with no such value is refused with SchemaEvolutionError before the table changes.
  • The chunks, equations and definitions tables all evolve through it when a writer opens them.
  • The equations schema gains normalizer_version. The tree indexer stamps it and rebuilds any tree whose version differs from the running normalizer's, including trees from before the column existed. After a normalizer change, the next ingest run or a plain index_equations brings the table in line.

Closes #550
Closes #315

Verification

  • ruff check . is clean.
  • Full suite on this branch: 5600 passed, 182 skipped, 1 xfailed (Python 3.12, Ubuntu).
  • This branch merged with the retrieval-routing and package-layering batches on 7cc5620: 5610 passed, 182 skipped, 1 xfailed. make wheel-check passes on that merge.
  • The package-layering PR moves modules this PR imports, so it lands after this one with the imports repointed.

The wiki's ingest pages should say that equations are now extracted during ingest and rebuilt after a normalizer change.

No ingest driver called the equation extractor, so a corpus built the
normal way had no equations table and find_equation always fell back
to dense_only_fallback.

ingest_one_paper now extracts a paper's equations from the HTML it
chunked, right after writing the chunks, and bulk ingest and the OAI
delta build the equation trees once at the end of a run, under the
run's dataset write lock. Notebook ingest runs through bulk ingest.

Each equation is linked to the chunk whose body holds every cell of it
as the chunker writes it ($alttext$), preferring a statement chunk.
Without that link the chunks-proxy dense step finds no candidate, so
the trees alone would not have reached ted_fused.

The tree indexer is a no-op on a dataset with no equations table, and
its CLI refuses a missing dataset path.

Closes #550
Schema evolution was a hand-kept SQL-default map in ingest.store that
failed on any column it did not list, reached only the chunks table,
and left equation trees unmarked, so a tree from an older MathML
normalizer could never be re-indexed by a plain run.

ingest.schema.add_missing_columns now derives every addition from the
table's Arrow schema: a nullable column gets NULL, and a column whose
pre-existing rows hold a known value (source_kind and license on
chunks) takes it from PRE_COLUMN_VALUES. A required column with no such
value is refused before the table changes, with SchemaEvolutionError.
The chunks writer, the equations table and the definitions table all
evolve through it when a writer opens them.

The equations schema gains normalizer_version. The tree indexer stamps
it and rebuilds any tree whose version differs from the running
normalizer's, including trees from before the column existed, so after
a normalizer change the next ingest run (or a plain index_equations)
brings the table in line.

Closes #315
@chris-dare-dev
chris-dare-dev merged commit f6689b8 into main Nov 21, 2026
4 checks passed
@chris-dare-dev
chris-dare-dev deleted the fix/batch-n-equations-schema branch November 21, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant