feat: introduce BaseExternalParser protocol for pluggable OCR/VLM backends#3207
Open
gavin913-lss wants to merge 7 commits into
Open
feat: introduce BaseExternalParser protocol for pluggable OCR/VLM backends#3207gavin913-lss wants to merge 7 commits into
gavin913-lss wants to merge 7 commits into
Conversation
Defines the abstract interface for external parser engines. See RFC HKUDS#3197.
Registry dict maps engine names to BaseExternalParser implementations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every new OCR/VLM parser engine copies the same four-file structure and adds another
if engine == …branch in the pipeline. No shared contract exists between engines.Fixes #3197
Solution
1.
BaseExternalParserprotocol (_base.py)Abstract base class with three methods:
is_bundle_valid(raw_dir, source_path)— cache-hit checkdownload_into(raw_dir, source_path)— fetch raw bundle from external servicebuild_ir(raw_dir, document_name)— convert raw bundle to IRDoc2. Engine registry (
_registry.py)Dict mapping engine names to parser classes:
register_parser("mineru", MinerUParser)register_parser("docling", DoclingParser)New engines register here instead of adding pipeline branches.
3. MinerU adapter (
mineru/adapter.py)Wraps existing
MinerURawClient+MinerUIRBuilder+is_bundle_validbehind the protocol.4. Docling adapter (
docling/adapter.py)Wraps existing
DoclingRawClient+DoclingIRBuilder+is_bundle_validbehind the protocol.What this does NOT change
pipeline.pydispatch logic (that's a follow-up)parse_mineru/parse_doclingmethods continue to workNext steps (follow-up PRs)
parse_externalmethod to the pipeline that uses the registryif engine == …chain from the pipeline