ZR-003 Benchmark Document segmentation

Page-boundary detection in multi-document accounting PDFs: an evaluation of windowed recurrent segmentation

Abstract

Documents submitted to accounting firms frequently arrive as a single PDF containing several invoices, receipts or delivery notes, often scanned without a text layer. Before extraction, such files must be segmented into their constituent documents. We compare a block-wise, text-only baseline with an adaptation of RICoT, which processes overlapping page windows, carries a summary of the open document between windows, and supplies page images where no text is available. On two evaluation sets built from real supplier documentation (100 synthetic bundles, 528 pages, 473 documents), the windowed method segments 98% and 100% of bundles exactly, against 48% and 68% for the baseline, and correctly segments 45 of 46 multi-page documents. Adding explicit invoice-level state tracking does not improve accuracy. The gain comes at three to six times the model cost of the baseline and about three times its latency, at roughly four seconds per bundle.

0.98–1.00
Bundle-level exact accuracy (baseline 0.48–0.68)
0.997–1.000
Boundary F1 (baseline 0.615–0.874)
45 / 46
Multi-page documents segmented correctly
≈ 4 s
Latency per bundle of 2–15 pages

1. Introduction

Documents submitted to an accounting firm do not arrive one per file. A common pattern is a single PDF produced by scanning a stack of supplier invoices in one pass. Downstream tasks, including classification, field extraction and posting to a ledger, assume one document per input, so the file must first be segmented: each page must be assigned to a document, and each document must begin and end on the correct page.

Segmentation errors propagate. A missed boundary merges two invoices, so one is never extracted. A spurious boundary divides a multi-page invoice, leaving a continuation page without a supplier or invoice number. We therefore evaluate segmentation as a task in its own right, separately from extraction.

The task is difficult for three reasons. First, a substantial share of pages are scans or photographs with no text layer, so methods that read only embedded text receive no signal. Second, continuation pages often repeat the issuer’s header, which resembles the first page of a new document. Third, long files exceed what can be processed in a single model call, so a document may begin in one segment of the file and end in the next.

This report compares the method previously used in Ziffa with an adaptation of RICoT [1], and with a variant that adds invoice-specific state. It describes the evaluation data, the metrics, the results, and an analysis of the remaining errors.

2. Methods

All methods take a PDF and return the first page of each document. Three methods are compared, together with a trivial reference.

Reference: one document per page. Every page is treated as the start of a new document. No model is used. Because most documents in the evaluation sets are one page long, this reference indicates how much of any score is attributable to that distribution alone.

Baseline: block-wise text classification. Text is extracted from each page with a PDF parser. Pages are grouped into non-overlapping blocks of ten, and each block is classified independently, with no information carried between blocks. Pages without a text layer are represented by a placeholder string.

Windowed recurrent segmentation (RICoT). Following [1], the file is processed in windows of up to six pages or approximately 3,600 tokens, each overlapping the previous window by one page. For each page, the model produces a short rationale and then commits a label: the page either begins a new document or continues the current one, with a document class, the supporting evidence and a confidence score. Labels are fixed before the next window is processed. The most recent decisions and a summary of the open document are passed into the next window. Pages without a text layer are supplied as images. The model is also told the expected document type of the upload, in this evaluation “invoice”. A final step promotes documents nested inside a larger document, such as an invoice attached to a statement, to documents in their own right.

RICoT with invoice-state tracking. As above, but the supplier, invoice number, “page x of y” marker and whether a total has been observed are also carried between windows for the open invoice, and a change of invoice number forces a boundary. This variant tests whether domain-specific state improves on the general method.

3. Experimental setup

3.1 Data

Two evaluation sets were built from real documents received by businesses in the course of ordinary bookkeeping. No customer is identified in this report.

Dataset 1: scanned supplier documentation. 27 PDFs (173 pages) of supplier invoices, credit notes and delivery notes from a single business. Every page is a scan without a text layer. The files were annotated by hand into 152 documents, 11 of which span more than one page.

Dataset 2: mixed invoice folder. 342 PDFs and 15 photographs of invoices, receipts, order confirmations, customs documents and statements from two businesses. Photographs were converted to single-page PDFs and 27 exact duplicates were removed, leaving 330 source files. Of the multi-page files, five contained more than one document (for example a duty invoice, a waybill and a commercial invoice scanned together) and were annotated by hand. One file, containing two photographs of the same invoice, was excluded. The set contains 335 documents.

3.2 Bundle construction

Evaluation bundles were constructed by concatenating 2 to 8 documents in random order with a fixed seed, preserving the page order within each document. Dataset 1 yields 40 bundles (210 pages, 185 documents, 20 of them multi-page). Dataset 2 yields 60 bundles (318 pages, 288 documents, 26 of them multi-page). In Dataset 2, 20 bundles were rasterised at 170 DPI to remove their text layer, and one further bundle had no text on any page, giving 21 scanned and 39 digital bundles. The digital bundles still contain 75 image-only pages among their 224 pages, as real submissions do.

3.3 Metrics

  • Boundary precision, recall and F1. A boundary is a page on which a document begins. The first page of a bundle is always a boundary and is excluded.
  • Document F1. A predicted document is correct only if both its first and last pages match the annotation.
  • Bundle-level exact accuracy. The proportion of bundles in which every document is segmented correctly. A single misplaced boundary counts the bundle as incorrect.
  • Over-segmentation and under-segmentation. False boundaries divide a document; missed boundaries merge two documents.
  • Computational overhead. Model cost is computed from the input and output tokens recorded for each response and reported relative to the baseline. Latency is wall-clock time per bundle, measured with four bundles processed concurrently.

Scores are micro-averaged over all boundaries or documents.

3.4 Model configuration

All methods were run on the same model, Gemini 3.1 Flash-Lite, with thinking at its lowest setting, so that differences between methods are attributable to the method rather than the model. Section 7 reports a second model.

4. Results

Bundle-level exact accuracy by method. Dataset 1: one document per page 62%, block-wise baseline 48%, RICoT 98%. Dataset 2: one document per page 62%, block-wise baseline 68%, RICoT 100%.
Figure 1. Bundle-level exact accuracy by method on both datasets.

Table 1. Dataset 1: scanned supplier documentation (40 bundles, 210 pages).

MethodBoundary PBoundary RBoundary F1Document F1Exact bundlesFalse boundariesMissed boundaries
One document per page0.8531.0000.9210.8350.62250
Block-wise baseline0.8950.4690.6150.5650.48877
RICoT0.9931.0000.9970.9920.9810
RICoT + invoice state0.9931.0000.9970.9920.9810

Table 2. Dataset 2: mixed invoice folder (60 bundles, 318 pages).

MethodBoundary F1F1, digitalF1, scannedDocument F1Exact bundlesFalse boundariesMissed boundaries
One document per page0.9380.9280.9650.8650.62300
Block-wise baseline0.8740.9310.7210.8160.68547
RICoT1.0001.0001.0001.0001.0000
RICoT + invoice state0.9960.9970.9930.9900.9720

No method produced malformed output or required retries on either dataset.

The baseline performs reasonably on digital bundles (boundary F1 0.931 on Dataset 2) but degrades sharply where pages lack text: 0.721 on the scanned bundles of Dataset 2 and 0.615 on Dataset 1. Its errors are predominantly missed boundaries (77 and 47), so documents are merged rather than divided. It segmented none of the 20 multi-page documents in Dataset 1 correctly.

The one-document-per-page reference scores higher than the baseline on Dataset 1. This reflects the distribution of the data, in which most documents are one page, rather than any competence: it divides every multi-page document, producing one false boundary for each.

RICoT achieves a boundary recall of 1.000 on both datasets, with a single false boundary across all 100 bundles, and segments 45 of the 46 multi-page documents correctly.

5. Error analysis

RICoT. The single error on Dataset 1, made by both RICoT variants, is a two-page invoice whose pages were scanned in reverse order. The page carrying the totals is followed by a page marked “Page 1 of 2” with a full header, which the model interpreted as the start of a new document. Correcting this would require the model to reorder pages, which none of the methods attempts.

RICoT with invoice state. Invoice-state tracking did not prevent the error above, since the invoice number does not change between the two pages. On Dataset 2 it introduced two false boundaries that the general method avoided: a monthly bill with a blank second page, and an invoice whose second page repeats the issuer’s header. The additional state appears to give the model more grounds to begin a new document without supplying information that the general method lacked. It also increases model cost by approximately 16% over the general method. We therefore do not use it.

Baseline. Given a placeholder in place of an unreadable page, the model has no evidence and its label is effectively a guess. On a set dominated by one-page documents this guess is often “new document”, which accounts for its reasonable precision, while its recall on scanned material is poor.

6. Computational overhead

Table 3. Overhead of RICoT relative to the block-wise baseline.

DatasetModel cost vs baselineLatency per bundle (RICoT)Latency per bundle (baseline)Model calls per bundle (RICoT)
Dataset 1 (all scanned)5.7×4.1 s1.1 s2.4
Dataset 2 (two thirds digital)2.7×3.9 s1.4 s1.7

The accuracy gain is not free. RICoT makes more model calls per file, because windows overlap and context is carried forward, and it supplies scanned pages as images of approximately 1,600 tokens rather than a short placeholder. Its model cost is therefore three to six times that of the baseline, with the largest increase on fully scanned material. Calls for a single file are sequential, at roughly 1.5 to 2 seconds each, so latency grows linearly with length: a 300-page file requires about 60 calls, or approximately two minutes.

In context, segmentation remains a small part of document processing: the added overhead amounts to approximately 2% of the model cost of extracting the resulting documents.

7. Model comparison

RICoT was re-run on the same bundles with Claude Haiku 5.5, using adaptive thinking at low effort as the closest equivalent to minimal thinking.

Table 4. RICoT on two models.

DatasetModelBoundary F1Exact bundlesRelative model costLatency per bundleRetries
1Gemini 3.1 Flash-Lite0.9970.981.004.1 s0
1Claude Haiku 5.51.0001.000.8412.3 s29
2Gemini 3.1 Flash-Lite1.0001.001.003.9 s0
2Claude Haiku 5.51.0001.000.789.3 s18

Claude Haiku 5.5 segmented every bundle correctly, including the reversed invoice, at 16–22% lower model cost. It was 2.5 to 3 times slower, partly because 18–30% of windows required a second request. A difference of one bundle is within the run-to-run variation we observe, so we do not regard the accuracy difference as significant. We retain Gemini 3.1 Flash-Lite for its lower latency.

8. Limitations

  • Distribution of document length. Most documents in both sets are one page. Only 46 multi-page documents appear in the bundles, and these are where segmentation is hardest. The estimate for multi-page documents is correspondingly imprecise.
  • Synthetic bundles. Bundles are constructed from separately annotated documents. Real submissions may contain material absent here, such as separator sheets, two documents on one page, or pages out of order within a document.
  • Limited sources. The data come from three businesses and are dominated by invoices. Results may differ for other document types and other jurisdictions.
  • Single runs. Each configuration was run once. Results vary slightly between runs.
  • No OCR comparison. Supplying OCR text for scanned pages, rather than page images, was not evaluated.

9. Conclusion

On real supplier documentation, windowed recurrent segmentation substantially outperforms block-wise text classification, with the largest gains on scanned material, where the baseline has no usable signal. It achieves near-perfect segmentation on both evaluation sets, at the price of a higher model cost and roughly three times the latency of the baseline. Domain-specific invoice state does not improve on the general method. The method is now used for all multi-document uploads in Ziffa. Future work will extend the evaluation to longer documents, other document types and OCR-based inputs.

References

  1. RICoT. arXiv:2611.22382, 2026. https://arxiv.org/abs/2611.22382
← All research