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 1.0.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 1.0.0
File Size Uploaded Provenance Actions
minicpm_ocr_haystack-1.0.0.tar.gz 16.8 kB With provenance Details for minicpm_ocr_haystack-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 29.5 kB

Release files / minicpm_ocr_haystack-1.0.0.tar.gz

Download URL minicpm_ocr_haystack-1.0.0.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3e25f2dc29acacb5123331c263f39d6f2249e6d845466d23b4c68a823ee7b605
BLAKE2b-256 checksum
How to use checksums
bc71e7b73ec477d8f99d2481a0d49ff160879f19b4283b0e4bf8f66f68eb7b46
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 25, 2026.

Transparency log

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

Download URL minicpm_ocr_haystack-1.0.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1120a736995ca191763037afefb5131d13df05d383158116062c72cac5a4135a
BLAKE2b-256 checksum
How to use checksums
8b80e8278e1f8e584f45bc528b0fcb28ab219a7cf49c430410d79d235150e6ac
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 25, 2026.

Transparency log

Security for minicpm-ocr-haystack 1.0.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-1.0.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 25, 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

1.0.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