Skip to content

Docling GLM-OCR Plugin ​

A Docling OCR plugin that delegates text recognition to a remote GLM-OCR model served via vLLM.

GitHub Repository: DCC-BS/docling-glm-ocr

Features ​

  • Remote Delegation: Offloads OCR processing to a remote vLLM server hosting zai-org/GLM-OCR.
  • Markdown Output: The model returns Markdown-formatted text, preserving headings, tables, and formulas.
  • Concurrent Processing: Sends page crops as base64-encoded images via concurrent API requests with retry logic.
  • Skips Born-Digital Pages: Pages with PDF text are not sent to the model as a whole; only regions that need OCR are.
  • Clean Output: Discards repetition loops, caps tokens per crop by its size (GLMOCR_REMOTE_OCR_MAX_TOKENS_PER_MEGAPIXEL), strips code fences and echoed prompts, and turns HTML tables into plain text rows.
  • Engine Key: Registers under the "glm-ocr-remote" engine key.

Installation ​

  • Using uv (recommended): uv add docling-glm-ocr
  • Using pip: pip install docling-glm-ocr

Usage ​

Configure the DocumentConverter with GlmOcrRemoteOptions:

python
from docling_glm_ocr import GlmOcrRemoteOptions

pipeline_options.ocr_options = GlmOcrRemoteOptions(
    api_url="http://localhost:8001/v1/chat/completions",
    model_name="zai-org/GLM-OCR"
)

Environment Variables ​

VariableDescriptionDefault
GLMOCR_REMOTE_OCR_API_URLvLLM chat completion URLhttp://localhost:8001/v1/chat/completions
GLMOCR_REMOTE_OCR_API_KEYBearer token for the Authorization headerunset
GLMOCR_REMOTE_OCR_MODEL_NAMEModel name sent to vLLMzai-org/GLM-OCR
GLMOCR_REMOTE_OCR_PROMPTPrompt sent with each cropMarkdown OCR prompt
GLMOCR_REMOTE_OCR_LANGComma-separated language hintsen
GLMOCR_REMOTE_OCR_TIMEOUTHTTP timeout per crop (s)120
GLMOCR_REMOTE_OCR_MAX_TOKENSMax tokens per completion16384
GLMOCR_REMOTE_OCR_MAX_TOKENS_PER_MEGAPIXELToken budget per megapixel of a crop (0 disables)2500
GLMOCR_REMOTE_OCR_SCALECrop rendering scale3.0
GLMOCR_REMOTE_OCR_MAX_IMAGE_PIXELSPixel budget per crop4500000
GLMOCR_REMOTE_OCR_MAX_CONCURRENT_REQUESTSConcurrent API requests10
GLMOCR_REMOTE_OCR_MAX_RETRIESRetries on HTTP errors3
GLMOCR_REMOTE_OCR_RETRY_BACKOFF_FACTORExponential backoff factor2.0

Developed with ❤️ by the DCC. Documentation released under the MIT License.