Docling

repository·main·Indexed 13 days ago

https://github.com/ds4sd/docling

A high-performance document parsing and conversion tool that transforms complex formats like PDF, DOCX, and HTML into structured, machine-readable representations such as Markdown or JSON. Optimized for LLM and generative AI workflows, it offers a full-featured package, a minimal-dependency version called docling-slim, and a service client for remote processing via Docling Serve.

Tokens
74.7K
Snippets
214
Records
300
Agent score
96%

What's inside Docling

  1. Overview of Docling features and capabilities

    main

    Docling is a document processing library designed to parse diverse formats and provide seamless integration with the generative AI ecosystem. It excels at advanced PDF understanding, including page layout, reading order, table structure, code, and formulas.

    Key Capabilities:

    • Multi-format Parsing: Supports PDF, DOCX, PPTX, XLSX, HTML, EPUB, WAV, MP3, WebVTT, Box Notes, email formats (EML, MSG), images (PNG, TIFF, JPEG, etc.), LaTeX, DocLang, and plain text.
    • Unified Representation: Uses a unified, expressive DoclingDocument format.
    • Rich Export Options: Export to Markdown, HTML, WebVTT, DocLang, DocTags, and lossless JSON.
    • Specialized Schema Support: Supports XML schemas like DocLang, USPTO (patents), JATS (articles), and XBRL (financial reports).
    • AI & Agentic Integrations: Plug-and-play support for LangChain, LlamaIndex, Crew AI, and Haystack.
    • Advanced Modalities: Includes OCR for scanned documents, Visual Language Model support (e.g., GraniteDocling), Audio support with ASR, and video parsing (MP4, AVI, etc.) with transcripts and keyframes.
    • Deployment Options: Can be run locally for sensitive data, as an MCP server, or as a service via the docling-serve API server.
  2. Integrate Docling with Data Prep Kit

    main

    Docling is integrated into the Data Prep Kit open-source toolkit to facilitate the preparation of unstructured data for LLM applications. It is used for large-scale data processing, ranging from local laptop environments to datacenter scales.

    Key integration workflows include:

    • PDF ingestion to Parquet: Converting PDF documents into Parquet format for efficient storage and processing.
    • Document chunking: Breaking down documents into smaller, manageable chunks suitable for LLM contexts.
  3. Available OCR engines in Docling

    main

    Docling supports multiple Optical Character Recognition (OCR) engines. These are not included in the core package and must be installed as extra packages depending on your requirements:

    • RapidOCR
    • Nemotron-OCR
    • EasyOCR
    • ocrmac
    • tesseract-CLI
    • tesserocr
  4. Overview of Docling Enrichment Models

    main

    Docling allows you to enrich the conversion pipeline with additional steps that process specific document components like code blocks, formulas, or pictures. These enrichments are disabled by default because they require additional model executions which increase processing time.

    FeatureParameterProcessed itemDescription
    Code understandingdo_code_enrichmentCodeItemAdvanced parsing for code blocks and setting code_language.
    Formula understandingdo_formula_enrichmentTextItem with label FORMULAExtracts LaTeX representation of equations.
    Picture classificationdo_picture_classificationPictureItemClassifies pictures (e.g., charts, logos, signatures).
    Picture descriptiondo_picture_descriptionPictureItemAnnotates pictures using a vision model (captioning).
  5. Overview of the Docling usage skill references

    main

    The Docling usage skill is structured to allow AI agents to load only the specific documentation required for a task. The entry point is SKILL.md, which routes the agent to specialized reference files:

    | Task | Reference File | |---|---|---| | Read/convert a file from the shell | cli.md | | Convert in code and tune the pipeline (PipelineOptions) | python-sdk.md | | Extract specific typed fields from a document | extraction.md | | Chunk documents for RAG | rag.md | | Offload conversion to a remote service | service-client.md | | Install only the dependencies you need | slim-packaging.md |

    These files are located within the installed package at docling/.agents/skills/docling/references/.

  6. What is a DoclingDocument?

    main

    Introduced in Docling v2, DoclingDocument is a unified document representation format defined as a Pydantic datatype. It provides a structured way to express document features including:

    • Content Types: Text, Tables, Pictures, and more.
    • Hierarchy: Document structure using sections and groups.
    • Disambiguation: Separation between the main document body and furniture (headers, footers, etc.).
    • Layout: Bounding box information for items (if available).
    • Provenance: Information regarding the origin of the content.

    The Pydantic type definitions are located in the docling_core.types.doc module.

  7. Choose between SimplePipeline and StandardPdfPipeline

    main

    Docling provides different pipeline implementations for document processing:

    • StandardPdfPipeline: A comprehensive pipeline designed for high-fidelity PDF parsing and structural analysis.
    • SimplePipeline: A lighter-weight pipeline option for faster or less complex conversion tasks.
  8. Configure Picture Description (Image Captioning)

    main

    When using picture-description enrichment, you can select models using picture_description_preset (for named presets) or picture_description_custom_config (for full control).

    Note: The parameters picture_description_local and picture_description_api are deprecated as of docling-serve v1.21.0.

    To use remote OpenAI-compatible API endpoints for description, the server must be launched with DOCLING_SERVE_ENABLE_REMOTE_SERVICES=true.

  9. Understand TikZ rendering fallback behavior

    main

    When using the Tectonic engine for TikZ rendering, Docling handles failures gracefully:

    1. Success: If Tectonic compilation succeeds, the TikZ diagram is rasterized and stored as an image.
    2. Failure: If compilation fails, times out, produces no PDF, or rasterization fails, Docling does not drop the figure. Instead, it preserves the original TikZ source as fallback code metadata.
  10. Choose an ASR backend for audio and video processing

    main

    Docling provides three interchangeable Automatic Speech Recognition (ASR) backends. You can choose between them based on your hardware and performance requirements:

    1. Native Whisper (openai-whisper): The default backend. Works on CPU and CUDA. Offers the broadest compatibility.
    2. MLX Whisper (mlx-whisper): Optimized specifically for Apple Silicon (M-series Macs) using MPS.
    3. WhisperS2T (whisper-s2t-reborn): An experimental, high-throughput backend using CTranslate2. It uses batched, VAD-segmented decoding and is typically the fastest on CPU and CUDA, using less VRAM for large models. Note: Not available on Apple Silicon.

    To use these, ensure you have installed the asr extra during installation.

  11. How Docling chunkers work

    main

    A chunker is a Docling abstraction that operates directly on a DoclingDocument. It returns a stream of chunks, where each chunk contains a string representation of a document segment and its associated metadata.

    There are two conceptual ways to chunk documents in a Docling workflow:

    1. Post-processing: Exporting a DoclingDocument to Markdown and then using external tools to chunk the text.
    2. Native Chunking: Using Docling's built-in chunker classes to operate directly on the document structure. This is the approach covered by the native chunker API.

    Docling's chunkers follow a common interface (BaseChunker), making them compatible with GenAI frameworks like LlamaIndex. You can use built-in chunkers, your own custom implementations, or third-party ones as long as they implement the BaseChunker interface.

  12. Configure format-specific options with FormatOption

    main

    Docling uses a hierarchy of format options to customize how different file types are processed. You can provide specific configuration objects to the DocumentConverter to tune the extraction behavior for PDF, Word, PowerPoint, Markdown, AsciiDoc, or HTML files.

    from docling.document_converter import DocumentConverter, PdfFormatOption
    
    # Example: Customizing PDF conversion options
    converter = DocumentConverter(
        format_options={
            "pdf": PdfFormatOption(
                # configuration parameters here
            )
        }
    )