Skip to content

Add Baidu Unlimited-OCR engine adapter - #11

Merged
Mihailorama merged 2 commits into
mainfrom
claude/evaluate-and-add-07lqbk
Jun 27, 2026
Merged

Add Baidu Unlimited-OCR engine adapter#11
Mihailorama merged 2 commits into
mainfrom
claude/evaluate-and-add-07lqbk

Conversation

@Mihailorama

Copy link
Copy Markdown
Owner

Summary

Evaluates and adds Baidu Unlimited-OCR (the project from the uploaded screenshot) as a new docfold engine.

Unlimited-OCR is an open-weight (MIT) document-parsing Vision-Language Model released June 2026. It builds on DeepSeek-OCR and replaces the decoder attention with Reference Sliding Window Attention (R-SWA), giving a constant KV cache so it can transcribe dozens of pages in a single 32K-context forward pass — its "one-shot long-horizon parsing" headline. It's free, locally runnable, and a good fit alongside docfold's existing local VLM engines (Chandra, Surya).

The new UnlimitedOCREngine wraps the upstream HuggingFace model (baidu/Unlimited-OCR, loaded via trust_remote_code), mirroring the existing ChandraEngine/SuryaEngine adapters:

  • Lazy model load (never at import / construction / is_available() / registration time); blocking inference runs in run_in_executor.
  • gundam (default) and base modes mapped to upstream base_size/image_size/crop_mode.
  • Accepts images directly; renders PDF pages to images via PyMuPDF.
  • Emits Markdown / HTML / JSON / text via the unified EngineResult.

Built per the project's mandatory TDD workflow: proposal → failing tests → implementation → verification.

Changes

  • New: src/docfold/engines/unlimited_ocr_engine.py
  • Router: added unlimited_ocr to PDF + image priority lists and default fallback (src/docfold/engines/router.py)
  • CLI: registered in _build_router() (src/docfold/cli.py)
  • Packaging: new unlimited-ocr optional-dependency group, added to [all] (pyproject.toml)
  • Tests: TestUnlimitedOCREngine (10 cases) + interface parametrize entry (tests/engines/test_adapters.py)
  • Docs: proposal (docs/tasks/UNLIMITED_OCR_ENGINE.md), README engine tables, benchmarks profile, CHANGELOG

Testing

  • pytest tests/329 passed, 3 skipped
  • ruff check and mypy on new/changed files → clean
  • Smoke-tested router registration: engine registers, advertises pdf+image extensions and table/heading/reading-order capabilities (is_available() is False until torch/transformers are installed)

Notes

  • The model requires a CUDA GPU and heavy deps (torch, transformers, einops); these only load when the engine actually runs, so the adapter imports cleanly without them.
  • First cut processes PDFs page-by-page for determinism/testability. Native single-pass infer_multi long-horizon batching is noted as a future enhancement in the proposal.
  • Repo convention (docs/conventions/golden-rules.md) says "never push"; this session's operator instructions explicitly require pushing the feature branch and opening a draft PR for review, which preserves that intent (no direct-to-main, no release).

🤖 Generated with Claude Code

https://claude.ai/code/session_01P23UQav6r1QsPGKzogma26


Generated by Claude Code

claude added 2 commits June 27, 2026 09:14
Add UnlimitedOCREngine, wrapping Baidu's open-weight one-shot
long-horizon document-parsing VLM (loaded from HuggingFace via
trust_remote_code). Supports gundam/base modes, images, and PDFs
(rendered to images via PyMuPDF), emitting Markdown/HTML/JSON.

- New engine: src/docfold/engines/unlimited_ocr_engine.py
- Register in router priority (PDF + image) and default fallback
- Register in CLI _build_router()
- Add unlimited-ocr optional-dependency group (+ to [all])
- Tests: TestUnlimitedOCREngine + interface parametrize entry
- Docs: proposal, README tables, benchmarks profile, CHANGELOG

Follows the TDD workflow (proposal -> failing tests -> implementation).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P23UQav6r1QsPGKzogma26
Add UnlimitedOCREngine to the local-engine candidate list so it is
benchmarked on GPU machines. It auto-skips (is_available() == False)
where torch/transformers are not installed, so CPU runs are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P23UQav6r1QsPGKzogma26
@Mihailorama
Mihailorama marked this pull request as ready for review June 27, 2026 19:40
@Mihailorama
Mihailorama merged commit a7a71ad into main Jun 27, 2026
10 checks passed
@Mihailorama
Mihailorama deleted the claude/evaluate-and-add-07lqbk branch June 27, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants