Skip to main content

minicpm-ocr-haystack

PyPI - Version PyPI - Python Version


Installation

pip install minicpm-ocr-haystack

Usage

MiniCPMOCRDocumentConverter turns PDF and image files into Haystack Documents using MiniCPM-OCR, a 1.3B open OCR model specialized in document parsing.

The converter runs the official minicpm-ocr SDK in-process: it detects each page's layout with PP-DocLayout, crops the detected blocks, and asks a MiniCPM-OCR inference server to recognize them. The server can be a local vLLM, SGLang, llama.cpp or Ollama deployment, or any OpenAI-compatible endpoint serving the same model.

from haystack_integrations.components.converters.minicpm_ocr import MiniCPMOCRDocumentConverter

converter = MiniCPMOCRDocumentConverter(
    server_url="http://localhost:8000",
    model="minicpm-ocr",
)
converter.warm_up()
result = converter.run(sources=["invoice.pdf", "scan.png"])
documents = result["documents"]

Each Document contains the Markdown of all pages, separated by form feed characters (\f) so DocumentSplitter(split_by="page") can split it, plus page_count and ocr_engine: "minicpm-ocr" metadata. The original source metadata is preserved; file_path keeps only the file name unless store_full_path=True.

Supported inputs are PDF, PNG, JPEG, BMP, TIFF and WebP.

Running the inference server

vllm serve openbmb/MiniCPM-OCR-1.0 --served-model-name minicpm-ocr --port 8000

Set backend to ollama, llamacpp, vllm, or openai (SGLang and LMDeploy expose the OpenAI-compatible API, so use openai). When the server requires a key, pass api_key=Secret.from_env_var("MINICPM_OCR_API_KEY").

Layout model

The layout detector runs locally. By default the SDK downloads PP-DocLayout into ~/.cache/minicpm-ocr/layout in warm_up(); set layout_model_dir to reuse a directory that already contains the model. Layout detection runs on CPU unless layout_device is set to a CUDA device.

Limitations

  • OCR quality depends on the inference server; tables and formulas require a model and prompt set that support them.
  • The first warm_up() downloads the layout model, which can take a minute on a slow connection.
  • Scanned pages are recognized block by block, so very large PDFs take time and memory; adjust page_workers and max_workers to the server capacity.

Contributing

Refer to the general Contribution Guidelines.

Integration tests need a running MiniCPM-OCR server and are skipped without one. Without a GPU, a CPU or Apple Silicon llama.cpp server works:

llama-server -hf openbmb/MiniCPM-OCR-1.0-gguf:Q4_K_M --host 127.0.0.1 --port 8080
MINICPM_OCR_SERVER_URL=http://127.0.0.1:8080 MINICPM_OCR_BACKEND=llamacpp hatch run test:integration

Set MINICPM_OCR_LAYOUT_MODEL_DIR to reuse a downloaded PP-DocLayoutV3 model.

License

minicpm-ocr-haystack is distributed under the terms of the Apache-2.0 license.

Metadata

Release files for minicpm-ocr-haystack 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for minicpm-ocr-haystack 0.1.0
File Size Uploaded Provenance Actions
minicpm_ocr_haystack-0.1.0.tar.gz 15.7 kB With provenance Details for minicpm_ocr_haystack-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for minicpm-ocr-haystack 0.1.0
File Interpreter ABI Platform Actions
minicpm_ocr_haystack-0.1.0-py3-none-any.whl Python 3 none any Details for minicpm_ocr_haystack-0.1.0-py3-none-any.whl

Total release size: 27.8 kB

Release files / minicpm_ocr_haystack-0.1.0.tar.gz

Download URL minicpm_ocr_haystack-0.1.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b8e33ba678c89d099ceb9a78c1e71a0257664d8e7a5d9b0544ea4fe3b2317aef
BLAKE2b-256 checksum
How to use checksums
4cd3608a0f47e6ae8f05080113ff8fcfa6554f8eb632e4c725da3a7597c0ee39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Release files / minicpm_ocr_haystack-0.1.0-py3-none-any.whl

Download URL minicpm_ocr_haystack-0.1.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40cc2ffbe00292838ea3fad74e8ab3dfc88b7358d0a59b2b530c8e03b7ad6fe2
BLAKE2b-256 checksum
How to use checksums
0d3289addcf5e1152b8918e0a2518f2c0fa5373fd5c3886f2d0f94617e64c6dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for minicpm-ocr-haystack 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for minicpm_ocr_haystack-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page