Document Parsing Pipeline#
DeepDoc is RAGFlow's in-house document understanding subsystem located under deepdoc/. It splits into two cooperating layers:
deepdoc/parser/— format-specific parsers that extract structured content from raw filesdeepdoc/vision/— a vision pipeline (OCR, layout recognition, table structure recognition) used by the PDF parser and image handling paths
DeepDoc is distinct from the MinerU integration, which is a separate PDF-only backend that calls an external API server (see deepdoc/parser/mineru_parser.py).
Format-Specific Parsers#
All parsers are exported from deepdoc/parser/__init__.py:
| Class | File | Format |
|---|---|---|
RAGFlowPdfParser (PdfParser) | pdf_parser.py | PDF (vision pipeline) |
PlainParser | pdf_parser.py | PDF (text-only, no vision) |
RAGFlowDocxParser (DocxParser) | docx_parser.py | DOCX / DOC |
RAGFlowExcelParser (ExcelParser) | excel_parser.py | XLSX, XLS, CSV |
RAGFlowPptParser (PptParser) | ppt_parser.py | PPTX |
RAGFlowHtmlParser (HtmlParser) | html_parser.py | HTML |
RAGFlowJsonParser (JsonParser) | json_parser.py | JSON |
RAGFlowMarkdownParser (MarkdownParser) | markdown_parser.py | Markdown |
RAGFlowTxtParser (TxtParser) | txt_parser.py | Plain text |
RAGFlowEpubParser (EpubParser) | epub_parser.py | EPUB |
Key implementation notes per format:
-
PDF (
pdf_parser.py) —RAGFlowPdfParseris the heaviest parser: it initializesOCR,LayoutRecognizer,TableStructureRecognizer, and an XGBoost model (updown_concat_xgb.model) for text-block concatenation heuristics. Pages are rendered viapdfplumberat 216 DPI (72 ×zoomin=3) . The output includes text chunks with page/position metadata, tables converted to HTML/natural language, and figures with captions. -
DOCX (
docx_parser.py) — Uses thepython-docxlibrary. Extracts paragraphs, tables, and embedded images (via XPath into the XML part). Image blob extraction catchesInvalidImageStreamError,UnrecognizedImageError, etc. -
Excel/CSV (
excel_parser.py) — Reads.xlsx/.xlswithopenpyxland falls back topandason parse error. CSV files are detected by magic bytes and converted to a workbook representation before processing. -
PPT (
ppt_parser.py) — Usespython-pptx. Shapes are sorted by position (top then left) before text extraction; supports bulleted lists, tables, and text frames.
Vision Pipeline (PDF Path)#
The vision pipeline is invoked by RAGFlowPdfParser and handles image/scanned content. Its three stages run in sequence :
1. OCR — deepdoc/vision/ocr.py#
The OCR class wraps two ONNX models: a text detector (det.onnx) and a text recognizer (rec.onnx). Both are loaded via load_model() which selects CUDAExecutionProvider if torch.cuda.is_available(), otherwise CPUExecutionProvider. Multi-GPU parallelism is enabled via PARALLEL_DEVICES=N .
2. Layout Recognition — deepdoc/vision/layout_recognizer.py#
LayoutRecognizer4YOLOv10 (exported as LayoutRecognizer) classifies page regions into 10 label types :
- Text, Title, Figure, Figure caption, Table, Table caption, Header, Footer, Reference, Equation
Layout output drives downstream decisions: which blocks are contiguous text, which need TSR, and which are figures with captions. An AscendLayoutRecognizer variant is available for Huawei NPU deployments . The backend is selected at runtime via the LAYOUT_RECOGNIZER_TYPE env var (onnx or ascend) .
3. Table Structure Recognition (TSR) — deepdoc/vision/table_structure_recognizer.py#
TableStructureRecognizer (a subclass of Recognizer) classifies elements within a cropped table image into 6 labels :
table,table column,table row,table column header,table projected row header,table spanning cell
TSR output is combined with OCR text boxes (which live in page-cumulative Y coordinates) via construct_table(), producing an HTML table or natural-language sentences. The coordinate space mismatch between TSR (image-local) and OCR boxes (cumulative) is resolved in _table_transformer_job(). TSR also supports Ascend via TABLE_STRUCTURE_RECOGNIZER_TYPE=ascend .
Table Auto-Rotation#
For scanned PDFs with rotated tables, _ocr_rotated_tables() evaluates 4 rotation angles (0°, 90°, 180°, 270°) using OCR confidence scores to find the best orientation before running TSR. This is on by default and controlled via the TABLE_AUTO_ROTATE env var .
PDF Parser Backends#
When used from the RAGFlow pipeline system, the PDF parse method is controlled by parse_method in ParserParam.setups["pdf"] . Available backends:
parse_method | Backend |
|---|---|
deepdoc | RAGFlowPdfParser (full vision pipeline) |
plain_text | PlainParser (text extraction only) |
mineru | External MinerU API server |
docling | DoclingParser |
paddleocr | PaddleOCR via LLMBundle |
<model>@<provider> | VLM image-to-text via VisionParser |
Key Source Files#
| Path | Purpose |
|---|---|
deepdoc/README.md | Overview, test commands for OCR/layout/TSR |
deepdoc/parser/__init__.py | Parser registry / public exports |
deepdoc/parser/pdf_parser.py | RAGFlowPdfParser, PlainParser |
deepdoc/parser/docx_parser.py | RAGFlowDocxParser |
deepdoc/parser/excel_parser.py | RAGFlowExcelParser |
deepdoc/parser/ppt_parser.py | RAGFlowPptParser |
deepdoc/vision/__init__.py | Vision module exports |
deepdoc/vision/ocr.py | OCR, TextDetector, TextRecognizer |
deepdoc/vision/table_structure_recognizer.py | TableStructureRecognizer, construct_table() |
deepdoc/vision/recognizer.py | Base Recognizer, overlap utilities |
deepdoc/vision/layout_recognizer.py | LayoutRecognizer4YOLOv10, AscendLayoutRecognizer |