cadrumo.application.local_reader module¶
The local document reader as one provisioned unit: runtime, role models, readiness.
Invoice extraction reads a text-layer document with the TEXT_EXTRACTION model
and a scanned one with the VISION_TRANSCRIPTION model; column mapping and the
supply-nature proposal use their own roles. Each role reads the model its
setting names, so provisioning, status and the reader itself must resolve the
same identifier – configured_role_model() is that single resolution.
Starting, installing and pulling live in provisioning_host and
provisioning_runtime; this module turns their measurements into the
projections a status surface renders and the per-role probe an ingestion lane
consults before spending a document. Its one write is the fitness verdict
verify_role_target() records in provisioning_fitness; status
reads that record and never probes unless asked.
- EXTRACTION_READER_ROLES: tuple[ModelRole, ...]¶
The roles invoice evidence extraction reads with, text layer first.
- FITNESS_PROBED_ROLES: tuple[ModelRole, ...]¶
Roles whose readiness includes a fitness probe. Presence answers “is the model there”; only the text reader has shown that a model can be present, loaded and answering, and still never produce a parseable extraction – a vision model configured in the text role spends its whole answer budget and returns nothing the parser can read.
- class RoleFitnessOutcome(**data)[source]¶
Bases:
ProvisioningOutcomeWhether a model produced a usable answer to its role’s real request shape.
fitis the decision.answer_parseableandgroundedsay which half failed: a reply the parser could not read at all, or a readable reply whose values did not match the probe document.timed_outmarks a model that did not finish its answer within the probe’s bound – a verdict about the model on this host, recorded like any other.transport_failedmarks a probe that never got an answer for any other reason, which says nothing about the model and is therefore never recorded.- Parameters:
data (Any)
- role: ModelRole¶
- model: str¶
- fit: bool¶
- answer_parseable: bool¶
- grounded: bool¶
- timed_out: bool¶
- transport_failed: bool¶
- output_tokens: int | None¶
- answer_budget_tokens: int¶
- elapsed_ms: int¶
- property settled: bool¶
Return whether this outcome is a verdict about the model rather than about the transport.
- property verdict: RoleFitnessVerdict¶
Return the recorded verdict kind for a settled outcome.
- class RoleFitnessState(*values)[source]¶
Bases:
StrEnumWhat a status surface knows about a probed role’s fitness.
NOT_VERIFIEDis its own state: no verdict is recorded for the model’s current weights, which is not evidence that the model is unfit.- FIT¶
- UNFIT¶
- TIMED_OUT¶
- NOT_VERIFIED¶
- class LocalReaderDocumentReadiness(*values)[source]¶
Bases:
StrEnumWhich invoice documents this machine can turn into drafts.
Text-layer documents are read by label rules that need no runtime and no model, so they are always readable; the model only fills fields the labels do not print. Every document is readable only when
LocalReaderStatus.extraction_ready.- ALL_DOCUMENTS¶
- TEXT_LAYER_ONLY¶
- probe_role_fitness(role, model, settings, *, text_probe)[source]¶
Run
role’s fitness probe againstmodelnow, or returnNonewhen the role is not probed.Records nothing;
verify_role_target()is the only writer of the recorded verdict.- Return type:
- Parameters:
- recorded_role_fitness(role, model, digest, settings)[source]¶
Return the recorded fitness of
model’s current weights, orNonewhen the role is not probed.
- verify_role_target(target, *, settings=None, text_probe=None)[source]¶
Verify a provisioning target is loaded, answering and fit for every role it serves.
Readiness first, through
verify_model_ready(), then – for a role inFITNESS_PROBED_ROLESand when a probe is supplied – the role’s real request shape. An unfit or too-slow model is reported not ready with its own condition, soverifycannot pass a model the reader will never get an answer from. Every settled probe is recorded against the model’s current digest; status reads that record instead of probing.- Raises:
ValueError – When
targetcarries no model (a refused selection).- Return type:
- Parameters:
target (RoleModelTarget)
settings (Settings | None)
text_probe (TextExtractionFitnessProbe | None)
- local_reader_service(role)[source]¶
Return the stable diagnostic row id for one role’s local reader.
- configured_role_model(role, settings=None)[source]¶
Return the runtime model id the on-host reader for
roleactually loads.The three document and table roles read their own settings; the supply-nature proposer resolves through catalogue selection, so it returns whatever that selection names, or
Nonewhen nothing is selectable.
- class RoleModelTarget(**data)[source]¶
Bases:
BaseModelOne distinct model to provision with every role it serves, or one role’s refusal.
modelisNoneexactly when catalogue selection refused the role; the selection’s facts and verdict are then carried so the caller reports why nothing will be fetched for it.- Parameters:
data (Any)
- model: str | None¶
- roles: tuple[ModelRole, ...]¶
- requirement_bytes: int | None¶
- selection_facts: Mapping[str, ProvisioningFactValue]¶
- selection_verdict: PreconditionVerdict | None¶
- select_role_model(role, settings, *, explicit=None)[source]¶
Resolve
rolethrough catalogue selection, honouring an operator-set model.The configured setting is passed as an override only when it differs from the catalogue default, so a default configuration keeps every selection bar – context window, licence, headroom – and an operator’s choice is honoured with its advisories.
explicitoutranks both.- Return type:
- Parameters:
- role_model_targets(roles=None, settings=None, *, explicit_model=None)[source]¶
Return the distinct models to provision for
roles(every role by default).Roles sharing one model yield one target, so provisioning every role pulls each model once. A role whose selection refuses yields its own target with no model and the refusal attached.
- probe_local_reader(role, settings=None, *, installed=None)[source]¶
Report whether the on-host reader for
rolecan run right now.Unavailable when the runtime does not answer, or when it answers without the model this role’s reader loads. An ingestion lane consults this per role, so a missing vision model never stops text-layer reads and a missing text model is not hidden behind an installed vision model.
- Parameters:
- Return type:
- Returns:
A
DependencyStatuson thelocal-reader:<role>row. Never raises.
- class LocalReaderRoleStatus(**data)[source]¶
Bases:
BaseModelOne role’s reader: which model it loads, and what the runtime says about it.
installed,residentandload_admittedareNonewhen the answer could not be measured – an unreachable runtime has no inventory, andNonemust not render as “not installed”.- Parameters:
data (Any)
- role: ModelRole¶
- model: str | None¶
- installed: bool | None¶
- resident: bool | None¶
- load_admitted: bool | None¶
- contention_causes: tuple[ContentionCause, ...]¶
- fitness: RoleFitnessState | None¶
- fit_for_role: bool | None¶
- ready: bool¶
- failed_condition_id: str | None¶
- class LocalReaderStatus(**data)[source]¶
Bases:
BaseModelThe whole local reader at one moment, for a status area or doctor row.
extraction_readyis true only when the runtime answers, both invoice-extraction roles have their models installed and the text model’s current weights carry a recorded fit verdict; it is the single claim a surface may use to say every document can be read on this machine.document_readinesssays which documents can be read either way, andtext_layer_model_fill_availablewhether text-layer fields the labels do not print can be filled by the text model.- Parameters:
data (Any)
- host: RuntimeHostStatus¶
- roles: tuple[LocalReaderRoleStatus, ...]¶
- last_pull: RuntimePullRecord | None¶
- extraction_ready: bool¶
- document_readiness: LocalReaderDocumentReadiness¶
- text_layer_model_fill_available: bool¶
- read_local_reader_status(settings=None, *, roles=None, assess_load=True, which=None, pull_record=<function last_runtime_pull>, text_probe=None)[source]¶
Measure the runtime host and every role’s model into one projection.
Reads only: nothing is started, pulled or loaded.
assess_loadadds the admission check for installed models that are not yet resident, which reads hardware counters and can be skipped by a surface that refreshes often. Withouttext_probethe text model’s fitness is the verdictverifyrecorded for its current digest, and a model with no recorded verdict is not verified rather than unfit. Withtext_probethe check runs now and its answer is reported without being recorded.- Return type:
- Parameters: