Page reader
Add a reader, OCR engine, or vision model that joins the generic routing ladder through its descriptor kind.
A generic reader implements the PageReader protocol and advertises the kind that determines its place in the routing ladder. This example is a CPU OCR lane; read_with_engine() stands for your code, and everything facing indx uses the real public contracts. Package and install it as the overview describes.
from typing import Any
from indx_interfaces import ( BlockStatus, CapabilityDescriptor, CapabilityId, CapabilityKind, Device, PageOutput,)
CAPABILITY_ID = CapabilityId("acme-ocr")
class Reader: def read( self, content: bytes, media_type: str, pages: tuple[int, ...] ) -> tuple[PageOutput, ...]: outputs = [] for page in pages: try: text, metadata = read_with_engine(content, media_type, page) outputs.append(PageOutput(page=page, text=text, metadata=metadata)) except Exception as error: outputs.append( PageOutput( page=page, status=BlockStatus.FAILED, reason=str(error), ) ) return tuple(outputs)
class Provider: def descriptors(self) -> tuple[CapabilityDescriptor, ...]: return ( CapabilityDescriptor( id=CAPABILITY_ID, version="1", kind=CapabilityKind.OCR, devices=(Device.CPU,), media_types=("application/pdf",), available=True, ), )
def create(self, capability_id: CapabilityId) -> Any: if capability_id != CAPABILITY_ID: raise ValueError(f"unknown capability: {capability_id}") return Reader()Import heavy runtimes inside create(), read(), or a lazily imported implementation module. Discovery calls descriptors() while building every snapshot and must not load weights, initialize a GPU, or contact a service.