Field provenance
For every extracted field, GET /documents/{id}/provenance tells you which OCR words hold its value. Use it to highlight a value on the page, or to check it against the source.
Response
result maps each field path to its geometry:
- Field path — the field’s position in
data, with dots between segments and plain numbers for list items:supplier.name,lines.0.quantity. There is nodata.prefix and no.valuesuffix. Only the fields of the document’s type are listed, and a field can be missing: treat it like an emptygeometry. An address located as a whole is given on itsrawfield (supplier.address.raw). geometry— the OCR words that hold the value, in reading order. Each word is{ page, region, line, word }; see Matching the geometry with the OCR. The list is empty when the value was not found on the document, when it was computed (for example, a total derived from other fields), or when a later processing step or a correction changed it without locating the new value.
Matching the geometry with the OCR
All four numbers are 0-based. Read them against GET /documents/{id}/ocr, which returns one item per page, { index, data }:
pageis theindexof the OCR page (notdata.page, which counts from 1).regionis the position in that page’sdata.regions.lineis the position in that region’slines.wordis the position in that line’swords.
The word carries its text and its bbox, the four corners [x1, y1, x2, y2, x3, y3, x4, y4] as fractions of the page width and height, so you can draw it over the page image. Ignore the page’s data.lines, which repeats all its lines in a single list.
Correcting the geometry
When you correct a document with PUT /documents/{id} (see Feedback loop), send the right words of a field in provenance, keyed by the same field paths, with the same numbering:
- You send words for a field: the field takes them, whether or not its value changes.
"geometry": []leaves it without words. Sending words for a value that was already right points it at the right place. - You change a value and send no words for it: the field is left with an empty
geometry, since the old words no longer hold the value. - Any other field keeps its words.
Sending the same value the field already has is not a change. Any other value is, even if it only differs in format: sending "1210.00" when the stored value is 1210 leaves the field without words unless you send them. "provenance": null is the same as leaving provenance out.
The request fails with 400, and nothing is saved, when provenance is malformed, a path is not a field of the document, or a word does not exist in its OCR. The error’s param is provenance when the body is malformed, and names the field (provenance.totalAmount) when a path or a word is rejected.
Besides this request, only changing the document type changes the words: the fields the new type keeps keep theirs, and a value the change alters is left without words.
Lists. Deleting an item moves the next items up, so their values change position: send the words of every item after the deleted one, or they are left without words. Depending on how the document was extracted, the words of a list may be kept per column rather than per item: correcting one item can then shift the words the next items of that column show, so always check the list with GET /documents/{id}/provenance after correcting it.