Skip to main content

Module runtime

Module runtime 

Source
Expand description

The ONE shared ONNX Runtime layer for the opt-in model tiers: resolution, checksums, one-time init, version check, session cache. Pin: ort =2.0.0-rc.13, api-23, ONNX Runtime 1.23.2, loaded dynamically.

Always compiled: the specs, the failure types and the path resolution are plain Rust, so a build without the tier still reports a missing model with the typed ModelError rather than a string. Only the session half (init, builder, session, SharedSession) needs the onnx-runtime feature and the ort crate. The ONE shared ONNX Runtime layer for the opt-in model tiers.

Two model tiers need ONNX Runtime: the layout model (balanced/best headings, lists, regions) and the table-structure model (tables), and the paddle OCR path already runs it. A process loads one onnxruntime and one ort version per dependency graph, so model-file resolution, checksum verification, one-time runtime initialisation, the version check, session caching and the two failure kinds live here, once. Model-specific pre/post-processing is NOT here: it lives in each model feature on top of SharedSession::run (behind the onnx-runtime feature).

§Pin

ort =2.0.0-rc.13 (a release candidate, pinned exactly), api-23, ONNX Runtime ORT_VERSION, loaded dynamically, never linked, never downloaded. Nothing in this module ever fetches over the network: a missing model file or library is ModelErrorKind::ModelNotAvailable, never a download.

§Resolution

The model file is <dir>/<spec.name>/<spec.file>, where <dir> is the first of: RuntimeConfig::model_dir, the PDFLUENT_MODEL_DIR environment variable (the ONE documented override), or the per-user default <data dir>/pdfluent/models/. The runtime library resolves the same way: RuntimeConfig::ort_dylib, then ORT_DYLIB_PATH (ort’s own variable), then <model dir>/onnxruntime-1.23.2/<platform library>, where the model dir is PDFLUENT_MODEL_DIR or the per-user default – the same root the install commands put the library under, so an install is found wherever the override points. The explicit model_dir is deliberately not read for the library (see resolve_ort_dylib). The data dir is $XDG_DATA_HOME or ~/.local/share on Linux, ~/Library/Application Support on macOS, %LOCALAPPDATA% on Windows, read with std::env only.

§Threads

intra_threads x sessions_per_model x the caller’s page parallelism should not exceed the cores; one caller-facing thread budget (later, the CLI’s --threads) drives both numbers. There is no automatic pool sizing here: the pool holds exactly RuntimeConfig::sessions_per_model sessions and SharedSession::run (behind the onnx-runtime feature) blocks until one is free.

§Errors

Failures surface as ModelError, which converts into std::io::Error via [std::io::Error::other] so pdf-engine can carry it as EngineError::Io without a new variant; callers match that variant and find the typed cause with model_error. Bindings and the CLI map ModelErrorKind::code onto their error codes.

Structs§

ModelError
A shared-layer failure.
ModelSpec
What a model package must provide.
RuntimeConfig
How the shared layer resolves files and sizes its pools.

Enums§

ModelErrorKind
What went wrong, in one of the two failure kinds the layer reports.

Constants§

ORT_VERSION
The exact ONNX Runtime version this layer runs against.

Functions§

default_model_root
The per-user model root: <data dir>/pdfluent/models/, where the install commands put packages.
model_error
Find the ModelError in an error chain, if there is one.
resolve_model_file
Resolve the model file: resolve_model_root plus <spec.name>/<spec.file>, reported even when it is not there.
resolve_model_root
Resolve the model root: explicit dir, then PDFLUENT_MODEL_DIR, then the per-user default. An empty env var counts as unset, matching ort’s own reading of ORT_DYLIB_PATH.
resolve_ort_dylib
Resolve the runtime library: explicit path, then ORT_DYLIB_PATH, then <model dir>/onnxruntime-<version>/<platform library>, where the model dir is PDFLUENT_MODEL_DIR or the per-user default.