Remote Inference Services#
Docling supports offloading model inference to remote servers via two distinct protocols and backend types:
- KServe v2-compatible servers — for OCR, layout detection (object detection), and image classification tasks. Communicates via HTTP REST or gRPC using the KServe Predict Protocol v2. Typical backend: NVIDIA Triton Inference Server.
- OpenAI-compatible VLM endpoints — for vision-language model tasks (code/formula extraction, VLM-based document understanding). Communicates over HTTP using the OpenAI Chat Completions API. Compatible with Ollama, LM Studio, vLLM, and OpenAI.
All remote engines are opt-in: you must set pipeline_options.enable_remote_services = True or the engine constructor raises OperationNotAllowed .
KServe v2 Engines (OCR, Object Detection, Image Classification)#
Transports#
Both the HTTP and gRPC transports implement the same KserveV2Client interface — infer() accepts numpy arrays and returns numpy arrays — so engine code is transport-agnostic.
| Transport | Client class | Source |
|---|---|---|
| HTTP | KserveV2HttpClient | docling/models/inference_engines/common/kserve_v2_http.py |
| gRPC | KserveV2GrpcClient | docling/models/inference_engines/common/kserve_v2_grpc.py |
gRPC is the default transport . The gRPC client requires the remote-serving extras (pip install 'docling[remote-serving]'); the HTTP client only requires requests .
Both transports support binary tensor payloads (use_binary_data=True by default), which is more efficient than JSON encoding for large pixel arrays . Set use_binary_data=False for servers that do not support this extension.
The grpc_max_message_bytes default is 64 MB . For dns:///host:port URLs, the gRPC client auto-injects round_robin load-balancing unless a policy is already specified .
Engine classes#
| Task | Engine class | Options class |
|---|---|---|
| OCR | KserveV2OcrModel | KserveV2OcrOptions (kind: "kserve_v2_ocr") |
| Object detection (layout) | ApiKserveV2ObjectDetectionEngine | ApiKserveV2ObjectDetectionEngineOptions |
| Image classification | ApiKserveV2ImageClassificationEngine | ApiKserveV2ImageClassificationEngineOptions |
On initialize(), each engine:
- Downloads the HuggingFace preprocessor and label config locally (no model weights needed).
- Opens the transport client.
- Calls
get_model_metadata()to discover input/output tensor names from the server .
Factory pattern#
The object-detection and image-classification engines are constructed via factory functions:
create_object_detection_engine()— selectsApiKserveV2ObjectDetectionEnginewhen the engine type isAPI_KSERVE_V2.create_image_classification_engine()— selectsApiKserveV2ImageClassificationEnginewhen the engine type isAPI_KSERVE_V2.
Both factories receive and forward enable_remote_services to the engine constructors. The resolve_kserve_transport_base_url() utility in kserve_transport_utils.py normalizes the URL before the client is opened (prepending http:// for HTTP URLs lacking a scheme).
Configuration options (shared across all KServe v2 engines)#
| Option | Default | Notes |
|---|---|---|
url | required | host:port or dns:///host:port for gRPC; http(s)://host:port for HTTP |
transport | "grpc" | "grpc" or "http" |
model_name | — | Registered model name on the server |
use_binary_data | True | Binary tensor payloads for both transports |
timeout | 60.0 s | Per-request timeout |
grpc_use_tls | False | TLS for gRPC channel |
grpc_metadata | {} | gRPC auth/routing metadata (not reused by HTTP) |
headers | {} | HTTP auth/routing headers (not reused by gRPC) |
grpc_max_message_bytes | 67108864 (64 MB) | Max send/receive message size |
grpc_channel_args | [] | Extra gRPC channel args (e.g., LB policy) |
OCR-specific options#
KserveV2OcrOptions (set via pipeline_options.ocr_options) adds:
lang(default["english", "chinese"]) — passed to the serverscale(default2.0) — image scale multiplier (e.g., 72 DPI → 144 DPI)model_name(default"ocr")
Example:
from docling.datamodel.pipeline_options import PdfPipelineOptions, KserveV2OcrOptions
pipeline_options = PdfPipelineOptions()
pipeline_options.enable_remote_services = True
pipeline_options.do_ocr = True
pipeline_options.ocr_options = KserveV2OcrOptions(
url="localhost:8001", # gRPC endpoint
model_name="ocr",
transport="grpc",
lang=["english"],
scale=2.0,
)
OpenAI-Compatible VLM Endpoints#
For VLM tasks (SmolDocling-style pipeline, code/formula enrichment), use ApiVlmEngineOptions:
from docling.datamodel.vlm_engine_options import ApiVlmEngineOptions
from docling.datamodel.pipeline_options import VlmPipelineOptions, VlmConvertOptions
options = VlmPipelineOptions(
vlm_options=VlmConvertOptions.from_preset(
"smoldocling",
engine_options=ApiVlmEngineOptions(url="http://localhost:11434"),
)
)
Key ApiVlmEngineOptions fields :
| Field | Default | Notes |
|---|---|---|
engine_type | API | Use API_OLLAMA, API_LMSTUDIO, or API_OPENAI for pre-set URLs |
url | http://localhost:11434/v1/chat/completions | Chat Completions endpoint |
headers | {} | HTTP auth headers |
timeout | 60.0 s | Per-request timeout |
concurrency | 1 | Max concurrent requests |
The API VLM engine is constructed via create_vlm_engine() in docling/models/inference_engines/vlm/factory.py. It is one of several VlmEngineType variants; see VLM Inference Engine for the full local/remote backend matrix.
Key Source Files#
| File | Purpose |
|---|---|
docling/models/inference_engines/common/kserve_v2_http.py | KserveV2HttpClient — synchronous HTTP transport |
docling/models/inference_engines/common/kserve_v2_grpc.py | KserveV2GrpcClient — gRPC transport via tritonclient |
docling/models/inference_engines/object_detection/api_kserve_v2_engine.py | ApiKserveV2ObjectDetectionEngine |
docling/models/inference_engines/image_classification/api_kserve_v2_engine.py | ApiKserveV2ImageClassificationEngine |
docling/models/stages/ocr/kserve_v2_ocr_model.py | KserveV2OcrModel |
docling/datamodel/pipeline_options.py | enable_remote_services, KserveV2OcrOptions |
docling/datamodel/vlm_engine_options.py | ApiVlmEngineOptions |
docling/datamodel/kserve_transport_utils.py | resolve_kserve_transport_base_url() — URL normalization |