Skip to content

Add PaddleOCR-VL external parser support - #3376

Draft
ouyangfeng2022 wants to merge 39 commits into
HKUDS:mainfrom
ouyangfeng2022:parser_external_paddle
Draft

Add PaddleOCR-VL external parser support#3376
ouyangfeng2022 wants to merge 39 commits into
HKUDS:mainfrom
ouyangfeng2022:parser_external_paddle

Conversation

@ouyangfeng2022

@ouyangfeng2022 ouyangfeng2022 commented Jul 8, 2026

Copy link
Copy Markdown

Description

This pull request adds PaddleOCR-VL as a first-class external parser engine for LightRAG. It wires the parser into the registry and pipeline configuration, implements the official API client/cache layer, converts PaddleOCR-VL layout results into the sidecar IR model, and documents configuration and debugging usage.

Related Issues

No linked issue.

Changes Made

  • Added the paddleocr_vl external parser package with cache option normalization, official API client support, parser adapter, and sidecar IR builder.
  • Registered PaddleOCR-VL in parser constants, registry resolution, parser parameter validation, and LightRAG concurrency defaults.
  • Added support for PaddleOCR-VL-specific request options, nested optionalPayload handling, environment configuration, and per-file hint validation.
  • Mapped PaddleOCR-VL layout labels into LightRAG sidecar IR blocks, including table/image caption handling across nearby layout blocks.
  • Updated English and Chinese docs for file processing, third-party parsers, parser debug CLI usage, and env.example configuration.
  • Added regression coverage for cache signatures, client payloads, registry behavior, parser hint validation, sidecar output, and IR conversion.

Checklist

  • Changes tested locally
  • Code reviewed
  • Documentation updated (if necessary)
  • Unit tests added (if applicable)

Additional Notes

Local verification completed:

  • uv run pytest tests/parser/external/paddleocr_vl tests/parser/test_registry.py tests/parser/test_engine_params.py tests/parser/external/test_engine_param_thread.py -q (85 passed, 1 skipped)
  • uv run ruff check . (All checks passed!)
  • git diff --check

tianleG added 15 commits July 8, 2026 10:45
- Add PaddleOCR-VL external parser implementation
- Update environment configuration with PaddleOCR related settings
- Add PaddleOCR-VL to parser registry
- Add tests for PaddleOCR-VL parser
- Update documentation for FileProcessingPipeline
…oise

- Add _nearest_neighbor helper to skip over page numbers/headers/footers
  when matching figure/table titles to their media elements
- Improve caption heuristic with Chinese prefix recognition (表, 图, etc.)
- Fix missing default values for show_formula_number, prettify_markdown, visualize
- Change USE_OCR_FOR_IMAGE_BLOCK default to False
- Refactor _coerce_text → _item_content and improve _item_label
- Use regex for bbox parsing from image paths
- Add docstrings and type improvements
- Add comprehensive tests for caption matching logic
…ions

- Split PaddleOCRVLParserOptions into nested DocParsingOptions for optionalPayload
- Add generic _build_payload helper using dataclass fields
- Add new options: merge_layout_blocks, format_block_content, vlm_extra_args
- Change DEFAULT_PADDLEOCR_VL_API_MODE from 'local' to 'official'
- Support PADDLEOCR_VL_ENDPOINT fallback for official endpoint
- Reorder fields in DocParsingOptions for logical grouping
- Update client to use nested optional_payload in request_payload
- Merge _coerce_* functions into a single generic _coerce_value
- Add _resolve_option and _override_env helpers for consistent override/env handling
- Simplify DocParsingOptions and PaddleOCRVLParserOptions construction
- Add tests for None rejection and type coercion behavior
- Remove 20+ DEFAULT_* constants that are only used internally within
  DocParsingOptions.from_env()
- Remove test-only helpers (current_endpoint_signature,
  current_options_signature, current_engine_version, snapshot_tunable_env)
- Only 8 items remain in __all__, all actually used by production code
- Update tests to access internal helpers via module object
…ntation in env.example and processing pipeline
- Added detailed instructions for using the PaddleOCR-VL file parsing engine in FileProcessingPipeline.md, including configuration for both official and local modes, deployment options, and troubleshooting tips.
- Updated ParserDebugCLI-zh.md and ParserDebugCLI.md to include PaddleOCR-VL as a supported engine, with relevant command-line options and output directory structure.
- Revised ThirdPartyParser-zh.md and ThirdPartyParser.md to reflect the inclusion of PaddleOCR-VL in the list of built-in engines and provided guidance for third-party parser development.
@danielaskdd

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f0dedc49e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lightrag/parser/param_schema.py
@danielaskdd

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2f11d3510

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lightrag/parser/external/paddleocr_vl/client.py
tianleG added 10 commits July 9, 2026 20:11
…ndling

- Relax BOS URL host validation from *.bj.bcebos.com to *.bcebos.com for broader region support
- Add bbox normalization to handle polygon coordinates and convert to enclosing rectangle
- Extract _bbox_key helper for consistent bbox tuple conversion
- Update documentation and env.example to reflect the relaxed URL validation
- Add tests for polygon bbox normalization, poly bbox image asset matching,
  and page range cache signature without manifest extras
…ard on undecodable markdown images

Replace the hardcoded `.bcebos.com` BOS host check with an env-driven
allowlist (`PADDLEOCR_VL_ALLOWED_ASSET_HOSTS`, default `.bcebos.com`)
so self-hosted asset domains can be admitted without code changes; the
SSRF guard is preserved since only HTTPS URLs on a listed suffix are
fetched.

Split image materialization into mandatory vs. soft paths:
- `markdown.images` are referenced from the parsed body/IR, so a
  missing or undecodable entry now raises instead of silently
  dropping the asset.
- `outputImages` are diagnostic, so failures stay soft-skipped with a
  warning.

Also refine the 6+ even-count bbox normalization in the IR builder to
document the polygon-vertex heuristic, export `snapshot_tunable_env`
from the cache module, and add an autouse conftest fixture that strips
all PaddleOCR-VL env vars (including the new host allowlist) so a
leaked `.env` can't silently flip option/signature defaults.
…odels

Add model recommendation notes across the user-facing docs, env.example,
and the cache module default to clarify that PaddleOCR-VL-1.6 is the
preferred model, with PaddleOCR-VL-1.5 as an alternative.
tianleG and others added 13 commits July 10, 2026 16:02
…image download, and _safe_name

- Make options_signature validation strict (MinerU-style: missing
  signature = hard miss, prevents silently reusing stale output)
- Refactor _detect_heading to return int level with ("", 0) sentinel,
  matching MinerU's call-site pattern; remove text_level logic
  (PaddleOCR-VL has no such field)
- Make _download_referenced_images concurrent via asyncio.gather,
  separating mandatory (markdown.images) and optional (outputImages)
  task groups
- Enhance _safe_name to match sanitize_filename pattern (strip .., /,
  \, \x00, \x7f, leading/trailing dots and whitespace)
- Document N--M relative-end page range semantics and
  relevel_titles=True heading-level behaviour
- Fill test gaps: strict signature, error paths (httpx RequestError,
  HTTP 503, poll failed state), concurrent error surfacing, HTTPS
  asset-url gate, _safe_name sanitization
# Conflicts:
#	lightrag/parser/param_schema.py
…r_external_paddle

# Conflicts:
#	lightrag/parser/param_schema.py
@danielaskdd
danielaskdd marked this pull request as draft August 16, 2026 04:28

@dianatofficial dianatofficial left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement. Refactoring this module enhances readability and code maintainability.

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.

3 participants