The OCR API coordinates.
The smart-document-manager container validates every submission, converts and rasterizes pages, orchestrates recognition and returns structured JSON and Markdown.
A visual guide to the architecture
See where validation, recognition, agent access and optional storage live. Then choose the request path that fits the work.
Think of a scanning desk: one service coordinates the work, a GPU specialist reads the pages, and an optional archive keeps the results.
The smart-document-manager container validates every submission, converts and rasterizes pages, orchestrates recognition and returns structured JSON and Markdown.
vllm-paddleocr serves PaddleOCR-VL on an NVIDIA GPU through an OpenAI-compatible API. Only the OCR API calls it; the pinned model revision never moves silently.
An opt-in SeaweedFS S3 profile keeps parsed outputs under least-privilege roles. Without it, every result simply returns in the HTTP response.
COMPOSE_PROFILES=storage.An optional MCP server exposes the API as fourteen tools on :8021. Two optional skills teach an agent how to drive them. The core pipeline works without either.
Follow one document through the pipeline. Each stage shows who acts and what crosses the next boundary.
A document enters through the static console, a REST call or an agent's MCP tool. All three reach the same POST /parse endpoint on the smart-document-manager container.
“Parse this scanned invoice into JSON and Markdown.”
Illustrative entry points. When OCR_SERVER_API_TOKENS is set, only /, /health, /assets/* and the Swagger pages are public; /stats, /metrics and /parse/progress/{id} need the bearer too.
The API checks the bytes, page count and per-page pixel budget first. Office files become PDF through headless LibreOffice; PDF pages rasterize at the configured DPI inside a hard per-page pixel cap, in blocks of up to 24 pages and 100 M pixels, so layout of one 8-page batch overlaps recognition of the previous one.
smart-document-manager container · admission and preparationDefaults from .env.example. Numbers are configuration, not measurements.
PP-DocLayoutV3 scans each page image and returns labelled regions — text, titles, tables, figures, formulas, seals — each with a bounding box in raster pixels.
Illustrative labels. 25 block types exist; captions, headers and footers carry no order.
The API crops each labelled region and sends it to vllm-paddleocr. Slot and memory budgets bound how many elements recognize at once; lanes bound parse concurrency.
Labelled regions dispatched within lane and inflight budgets
Markdown text, HTML tables with rowspan/colspan, LaTeX formulas, chart and seal descriptions — per block, with 413 (size or pixel budget), 429 (rate limit) and 503 (shutting_down, or backend_unavailable while the vLLM circuit breaker is open) pressure signals instead of unbounded queues.
Admission defaults: 32 element slots, 512 MiB shared element memory.
Recognized content lands back on its blocks. block_id gives the reading order for every block; captions sit next to their tables and figures in that order; per-page Markdown renders the result with warnings attached.
Illustrative blocks. Page errors and warnings survive in the JSON.
The response carries pages, blocks, Markdown and warnings. With the storage profile enabled, outputs also land in SeaweedFS S3 under least-privilege roles. /chunk can later build RAG chunks on CPU — no second inference.
{"pages":[{"blocks":[{"block_id":1,
"type":"doc_title","order":1,
"bbox":[52,60,398,96]}]}],
"warnings":[]}POST /parse through the console, REST or an MCP tool — one endpoint, one contract.Host ports below are shipped defaults. Each card names the container and, where it differs, the Compose service name that launcher commands such as logs -Service expect.
FastAPI owns document validation, Office conversion, layout/recognition orchestration, request budgets, RAG creation and the static console.
The GPU model server serves PaddleOCR-VL through an OpenAI-compatible API. Compose uses port 8080 internally; the host port exposes its API and docs.
c5630aba.Fourteen task tools translate agent requests into API calls. Three prompts teach workflows. Eleven resources: ten docs:// documents including these six guides, plus the live ocr://metrics.
/mcp with distinct bearer tokens.SeaweedFS (document-storage-s3, service seaweedfs), its gateway (document-storage-gateway, service storage-gateway, published on :8333 and :23646 for the admin console) and a one-shot initializer (document-storage-init, service storage-init) archive outputs. The initializer provisions identities before API startup. Writer, reader, browser and administrator credentials have separate roles.
COMPOSE_PROFILES=storage.This diagram changes only its explanation; it never contacts the application.
Send a document through the console, REST or an MCP tool.
Validate the source, enforce budgets and prepare pages.
Use layout and PaddleOCR-VL to recognize page content.
Return page/block JSON and optional Markdown with warnings.
Illustration only. No request is sent and no model capacity is measured.
/parse converts Office files if needed, rasterizes pages, runs layout detection and recognizes blocks on the GPU. /parse/chunks combines one parse with immediate RAG chunking.
Recognizes a single cropped image element (text, table, formula, chart, seal or spotting) against vllm-paddleocr under dedicated slot and memory budgets.
Accepts an existing structured /parse JSON payload and builds token-bounded RAG chunks on the CPU using the local tokenizer—without calling vLLM again.
Converts one Office or OpenDocument file with headless LibreOffice and returns the PDF that /parse would read — no GPU. The MCP tool ocr_convert_office_to_pdf wraps it.
With the storage profile, /storage/* lists, downloads, deletes and refines archived jobs through the S3 gateway — no GPU, exact confirmation for deletes. GET /parse/progress/{id} reports a running parse; the MCP parse tool polls it. In archive-only mode (--archive-only / -ArchiveOnly) these routes, /chunk and /office/pdf are the data routes that keep working, while /health, /stats and /metrics answer as usual: vllm-paddleocr is not started, no GPU is reserved and /parse, /ocr and /parse/chunks answer 503 ocr_disabled_archive_only.
Explore which services run, which clients reach them, and whether an archive joins the picture. These choices are independent.
Three independent choices. Agent access and archiving do not change where the OCR work happens — only who can call it and whether outputs are kept.
An interactive explanation.
These controls do not change your stack.
No archive: every result returns in the HTTP response and nothing is persisted by the pipeline.
All published ports bind to 127.0.0.1. Keep MCP inbound tokens and any agent connections inside the same boundary.
A GPU is required. vllm-paddleocr and the layout step in the smart-document-manager container both need a compatible NVIDIA GPU with at least 8 GB and a GPU-capable container runtime; there is no CPU fallback. Both share one GPU: GPU 0 unless OCR_GPU_DEVICE or --gpu-device selects another. /chunk runs on CPU but reuses existing parse JSON.
First-run preparation needs downloads. Container images, dependencies and the pinned PaddleOCR-VL model weights must be available once; afterwards the stack runs without hosted inference.
Keep the services on trusted infrastructure, control who can connect, and use an agent whose model and integrations fit that boundary. Every published host port binds to loopback by default; the published vLLM port (8081) serves its OpenAI-compatible API and metrics without bearer auth, so keep it on loopback.
MCP inbound tokens (MCP_API_TOKENS) are distinct from the API tokens (OCR_SERVER_API_TOKENS, also token:label), and the MCP server calls the API with its own service credential (UPSTREAM_CLIENT_TOKEN), which the API accepts automatically. Publishing a port beyond loopback is a deliberate deployment decision — follow the MCP configuration reference and the launcher configuration reference before exposing anything.
You describe the extraction in ordinary language. The agent chooses an available tool, supplies structured arguments and interprets the response.
The optional MCP server exposes the OCR API as 14 tools over Streamable HTTP at http://127.0.0.1:8021/mcp, plus 3 workflow prompts and 11 resources — ten documents including these guides, and the live ocr://metrics. It authenticates with its own MCP_API_TOKENS, distinct from the API token.
The smart-document-manager skill teaches tool selection and careful workflows; smart-document-reader teaches how to read parse JSON or a stored archive — block_id order, null order, relations and provenance. They are Markdown loaded by the agent host, not running services.
“Extract this invoice into structured JSON.”
The agent knows a mounted input path such as /inputs/invoice.pdf, or receives the bytes as base64.
One tool call maps to one POST /parse on the OCR API. Illustrative request:
{"name":"ocr_parse_document",
"arguments":{"params":{
"file_path":"/inputs/invoice.pdf",
"output":"both","json_rag":true}}}Illustrative response, abbreviated:
{"structuredContent":{"pages":[{
"blocks":[{"block_id":1,"type":"doc_title",
"order":1}]}],"warnings":[]}}Agent → MCP :8021 → smart-document-manager :8020 → vllm-paddleocr :8080 → structured JSON
Skills guide; services enforce. A skill shapes agent behaviour, while authentication, input checks and confirmation gates live in the services. Destructive storage tools require an exact confirm value checked locally and again by the API.
You connect the agent host. Point a Streamable HTTP client at /mcp with a bearer token, then load the skills if the host supports them. Server file paths live inside the MCP container — mounts plus MCP_INPUT_ROOTS decide what file_path may reach.
Authentication belongs to the service receiving a request, not to a nearby UI or network label.
The console is static code served by the API—not a separate ocr-ui container. All published host ports bind to 127.0.0.1; Docker-private networks do not authenticate callers. Two Compose networks: smart-document-manager-private joins the API, vLLM, MCP and the storage gateway; smart-document-manager-storage is internal-only and holds SeaweedFS and the initializer, so the API reaches S3 only through the gateway.
MCP has its own inbound tokens (MCP_API_TOKENS), calls the API with its own service token (UPSTREAM_CLIENT_TOKEN, listed in neither token list), and never gives clients a direct model-server token. The published vLLM port (8081) has no bearer auth.
MCP local file paths refer to the MCP container, requiring both MCP_INPUT_ROOTS and read-only Docker mounts. Inference POSTs are not retried; destructive storage tools require exact confirmation.
Every non-public request passes the shutdown guard (503 shutting_down on POST), a per-IP rate limit (429 rate_limited; GET /stats, /metrics and /parse/progress/{id} are exempt) and bearer auth (401 unauthorized). CORS is opt-in through OCR_CORS_ORIGINS and answers preflights before authentication.
ocr-api, ocr-mcp and the storage services run as a non-root user on read-only filesystems with every capability dropped, no-new-privileges and memory/PID limits. vllm-paddleocr drops capabilities and is memory-limited but runs as root on a writable filesystem.
Runtime state and release evidence answer different questions.
Named volumes retain model weights (ocr-vllm-model-cache), Paddle caches, runtime hardware state, tuning profiles and optional OCR archives (ocr-output-storage). Normal down retains them; volume deletion is destructive.
Autotuning fingerprints include the runtime and model context. A vLLM version or hardware change invalidates the cached profile and triggers recalibration. Empty concurrency overrides preserve automatic selection. OCR_AUTOTUNE is quick by default; full runs the complete corpus, off skips calibration and keeps built-in defaults, and OCR_AUTOTUNE_FORCE=true discards the cached profile.
The Docker services have separate images and dependency inventories. Native startup changes dotenv and bind semantics; use its owning reference instead of copying container settings blindly.
CI tests contracts with fake inference and offline guides. Its green aggregate does not prove GPU OCR quality, live credentials or production readiness. See the release checklist ↗.
Terms this page uses, and the owning documents that define the exact behavior.
The Model Context Protocol is a standard for connecting AI applications to tools and context. This repository's optional MCP server exposes the OCR API over Streamable HTTP at http://127.0.0.1:8021/mcp. Using HTTP does not by itself mean using the public internet.
The vision-language model — PaddleOCR-VL, served by vllm-paddleocr through vLLM's OpenAI-compatible API at a pinned revision. It reads cropped page regions and returns text, tables, formulas and descriptions.
A labelled region of a page: a type (one of 25 tags like text, doc_title, table, seal), a bounding box in raster pixels, recognized content, and identifiers block_id / group_id.
block_id is the reading order for every block, tables and captions included. order is null by label for captions, headers, footers and page numbers — never "unplaced". Do not rebuild order from coordinates.
A token-bounded, section-aware unit built from parse JSON by the deterministic CPU chunker (/chunk, /parse/chunks). Same input plus same options gives byte-identical chunks with canonical hashes.
Pre-start calibration: vllm-paddleocr writes a hardware manifest, then ocr-api measures concurrency settings against quality and stability gates and persists a fingerprint-bound profile.
The capacity band the Stage-1 entrypoint detects from VRAM and compute capability. It selects vLLM startup flags such as max sequences — 16 below 16 GiB, 32 from 16 GiB, 64 from 24 GiB — unless you override them.
The optional storage Compose profile: SeaweedFS S3 behind an nginx gateway, provisioned by a one-shot init with four least-privilege roles — writer, browser, reader, and an admin key the API never sees.
A launcher mode (-ArchiveOnly / --archive-only, or OCR_ARCHIVE_ONLY=true) that starts ocr-api, MCP and, with COMPOSE_PROFILES=storage, the storage profile without vllm-paddleocr or any GPU reservation, through the compose.archive-only.yml overlay. Stored archives stay readable through the console, /storage/* and the MCP storage tools; inference routes refuse with 503 ocr_disabled_archive_only, autotune does not run and /health reports vllm=disabled, healthy once the archive bucket answers.
Checked against the repository's owning references. This page is an offline explanation; it does not inspect your machine, connect to your services, or change their configuration.
Match each observation to the layer it can actually prove.
API health can return HTTP 200 while degraded. Check its response and model reachability. mode=archive_only with vllm=disabled is a healthy archive-only stack, not an outage: OCR is off by design and ocr_enabled=false says so. MCP listener health only proves a listening process; authenticated discovery is a separate check.
No, when complete structured parse JSON already exists. Use the existing-JSON mode of ocr_create_rag_chunks or REST /chunk. The tokenizer and CPU budgets remain relevant.
Run from the repository root
pwsh .\stack.ps1 down
bash stack.sh down
Retained data does not guarantee an unchanged calibration is valid after an upgrade. Let the runtime fingerprint decide.
The API returns parsed JSON, Markdown and chunks directly in the HTTP/MCP response without writing to S3, and the three document-storage-* containers are not started.
These guides teach the workflow. The owning documents define its exact behavior.
Every command, flag, exit behavior and recovery boundary.
Read the CLI reference ↗Template defaults, token relationships and deployment details.
Read the environment reference ↗How a page becomes labelled blocks, and how blocks become bounded chunks.
Read the pipeline guide ↗