Skip to content

ocr: POST /ocr in docTR's contract (#2440 step 5) - #2574

Merged
ashhart merged 3 commits into
ashhart:mainfrom
laudney:ocr-5-doctr
Nov 24, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
laudney:ocr-5-doctr

Conversation

@laudney

@laudney laudney commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor
Before (#2573) After
docTR API clients (files parts, options in the query) 400 POST /ocr: one OCROut a page or image, relative geometry
A body with both files and file parts 400 (files not read) 400 on every path, ?format= included: neither contract drops the other's parts

Step 5 of the stack #2440 set out. It follows #2573, now on main.

#2440 gate Proof in this pull request
Its client's request round-trips, with its own refusals tested doctr_test.zig: the README call on /ocr and /ocr/, part order, a PDF part, every query option (accepted, refused, malformed), part types, and the mixed-parts refusal through each dialect's envelope

Provenance, following your ruling on #2530: docTR's fields come from its published docs and the reply its README shows, not its tests or source, and every message is ours. This changed three things from #2530: orientation is {"value": 0, "confidence": null} as the README reply shows (was all null); paragraph_break is accepted only at its documented default 0.035; and bin_thresh/box_thresh, which have no documented API default, are refused. The part-type refusal is now our own text.

Sources: R = api/README.md, UM = using_models, IO = io, FA = FastAPI handling errors.

Field, option or message Source
POST /ocr, multipart files parts; types image/jpeg, image/png, application/pdf R
det_arch, reco_arch (accepted, not read) R
assume_straight_pages (default true: boxes; false: polygons) UM
resolve_lines (default true), resolve_blocks (default false), paragraph_break (only its default 0.035) UM
detect_orientation, detect_language (accepted); straighten_pages, detect_layout, detect_tables (only false) UM
bin_thresh, box_thresh (refused) UM names them; the refusal is ours
reply: one OCROut a page, name, orientation {"value": 0, "confidence": null}, language {"value": null, "confidence": null}, dimensions, items [{"blocks": [...]}] R (its reply)
dimensions [height, width] R; IO
blocks, lines and words with geometry, objectness_score, confidence, value, crop_orientation R; IO
geometry relative to the page, not rounded R (its floats); IO
page layout and tables (always []) UM, IO (keys of a page's export); R's reply example does not show them
polygon geometry as 8 flat floats (assume_straight_pages=false) no published page shows the API's polygon JSON; IO describes a polygon as points. This is the shape the API sends, so a client reading it expects it: tell me if you want 4 [x, y] points instead
error body {"detail": "..."} FA (the template is a FastAPI server, R)
scores 1.0; statuses 400, 422, 503 with Retry-After, 500; every message ours

What this changes

POST /ocr gains docTR's API contract: one or more files parts (images or PDFs, by the part's type), options in the query, one OCROut a page in part order. Words come from a line's estimated word boxes, and every score is 1.0. With docTR and LiteParse served, a body with both kinds of parts is refused on every path, and a docTR option sent twice is 400.

Checks on this head

  • Head commit: fde877533, on main a0f809ea0. Rebuilt like ocr: PDF documents and pages on /v1/ocr, one page at a time (#2440 step 2) #2571 to ocr: POST /ocr in LiteParse's contract (#2440 step 4) #2573: the step-5 change, with the review fix (a docTR option sent twice is refused), applied to main in 2 commits with the original subjects. Each file's change equals the reviewed change; CHANGELOG.md is no longer touched.
  • Lean checker, python3 tools/zig/lean_check.py: 165 on main and 165 on this head, the same list, 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test-ocr-host test-api-boundaries test-server-cpu test-dots-mocr-host test-glm-ocr-host check-native-hip-host -Dhip=true: 24/24 steps, 2178 of 2196 pass, 18 skip, 0 fail
    • zig fmt --check zig/src build.zig zig/build and git diff --check: clean
  • CI: pending on this head. A test merge into main a0f809ea0 is clean.
  • Not run, and why: the dots.mocr oracle-run test and the PDF tests skip here (no TF_DOTS_OCR_DIR runs and no PDFium on this run); this step changes only test replies on the PDF path. CUDA, Metal and Windows: no OCR reader is offered there; the readers are wired into the HIP offers only.

Receipt

  • Client receipts on gfx1201 (dots.mocr), the docTR README call: /ocr and /ocr/ on a JPEG: 200, dimensions [260, 900], 1 block, 10 words, orientation {"value": 0, "confidence": null}; an application/pdf part: 2 OCROut named report.pdf; two files: 2 OCROut in part order; assume_straight_pages=False: 8-float geometry; a cut page: 422 {"detail": "page 0: ..."}.
  • Boxes it reaches: the HIP native server with an OCR reader and --vision (--vision-pdf for PDF parts).
  • New switch? No.
  • Environment: receipts on base 9c9bf542c, checks on main a0f809ea0; Zig 0.17.0; ROCm 10.1 (hipcc HIP 7.16); one Radeon AI PRO R9700 (gfx1201); Linux; dots.mocr dots-studio/dots.mocr e539fbb52280393adc081b289ec597430a0f9031, GLM-OCR zai-org/GLM-OCR 2e85a62840ccac27daa451df36c736c4636b8628; PDFium chromium/7725; libjpeg-turbo 3.1.4.1. The end-to-end client receipts ran on the whole stack's code (c517f4379, byte-equal to step 6's OCR files), which serves this step's requests through this step's code.
  • Paths and platforms the change reaches, which I ran and which I could not: HIP gfx1201 end to end; CUDA, Metal and Windows not run.
  • Exactness: n/a; no generation path changes.
  • Main against this branch: n/a; no chat path changes in this step.
  • Decode speed before and after: n/a.
  • Prompt speed before and after: n/a.
  • Licence of any new weights or drafter, or "n/a": n/a

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. An early read of step 5: the both-kinds refusal is in all three places with a test through each envelope, content options off their defaults are refused one by one, and the source table answers the provenance question from #2530. Nothing new to ask here. It uses step 4's query reader, so the repeated-parameter fix we asked for on #2573 covers it too. It follows #2573 in the order you set out.

  • Synthena (Ash's Agent)

@laudney

laudney commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart rebased onto main a0f809ea0 (with #2573), as you set out, and marked ready. New head: fde877533.

Before (d3b9d1862) After (fde877533)
Base 9c9bf542c, under the old #2573 main a0f809ea0
Commits 2 for step 5, then 9 review commits 2, with the original subjects
Review fix local only in: a docTR option sent twice is 400, through #2573's query reader
Change each file's change equals the old one; CHANGELOG.md is no longer touched
Merge with main conflicted clean
Check on fde877533 Result
zig build test-ocr-host test-api-boundaries test-server-cpu test-dots-mocr-host test-glm-ocr-host check-native-hip-host -Dhip=true 24/24 steps, 2178 of 2196 pass, 18 skip, 0 fail
Lean checker 165 on main, 165 on this head, the same list

#2575 follows when this lands.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @laudney. This head merges cleanly with main. Interpreted query options use the duplicate-rejecting reader, and the mixed file/files refusal remains in each dialect, including explicit format selection.

The page-origin change preserves the existing reader path while supplying each response's filename. No further changes are requested for this API step, subject to the normal CI checks.

  • Synthena

laudney and others added 3 commits November 24, 2026 18:11
docTR's API client posts one or more files parts with options in
the query and reads one OCROut a page, so POST /ocr now answers it:
parts typed by their exact Content-Type in part order, each PDF
page named by its file, blocks and lines from the shared estimates
in relative coordinates or 8-float polygons, pydantic booleans for
the options, a docTR option sent twice refused, and content options
off their documented defaults refused. A body with both files and
file parts is refused as ambiguous on every path, the format query
included, in the chosen envelope.
The API guide adds docTR to the /ocr contract choice, with the
refusal of a body holding both files and file parts, its failure
column, word estimates and scores, whole-page boxes for a reader
without boxes, and the docTR section with its part types and query
options, a repeated option refused; the changelog stays with the
maintainer.
@ashhart
ashhart merged commit 217055d into ashhart:main Nov 24, 2026
1 check failed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

ashhart added a commit to atakann/TensorFold that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants