Docling Document Processing Library

repository·main·Indexed 13 days ago

https://github.com/docling-project/docling

A document processing library that parses diverse file formats—including complex PDFs, DOCX, HTML, videos, and audio—into structured, machine-readable formats like Markdown and JSON. Optimized for generative AI and LLM workflows, it provides a Python SDK, a CLI, and a service client for remote processing via Docling Serve. Features include advanced PDF parsing, OCR, table extraction, and document chunking for RAG.

Tokens
76.6K
Snippets
231
Records
306
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 integrations with the generative AI ecosystem. It specializes in 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, plain text, and video files (MP4, AVI, etc.) with ASR transcripts.
    • Unified Representation: Uses a unified DoclingDocument format.
    • Export Options: Supports Markdown, HTML, WebVTT, DocLang, DocTags, and lossless JSON.
    • Specialized Schema Support: Includes support for DocLang, USPTO patents, JATS articles, and XBRL financial reports.
    • AI Ecosystem Integration: Plug-and-play support for LangChain, LlamaIndex, Crew AI, and Haystack.
    • Deployment Options: Can be run locally for sensitive data, as an MCP server, or as a service via the docling-serve API server.
  2. Overview of Docling Service Client SDK capabilities

    main

    The docling.service_client SDK provides several ways to interact with a remote docling-serve instance:

    • High-level API: convert() and convert_all() for direct document conversion.
    • Job Lifecycle API: submit* methods for managing asynchronous jobs, defining result targets, and per-item fan-out via tasks.py.
    • Batch Processing: submit_batch() for handling built-in or plugin sources and artifact targets via batch.py.
    • Document Chunking: chunk() to split documents into pieces optimized for retrieval-augmented generation (RAG) via chunk.py.
  3. Explore Docling integrations

    main

    Docling integrates with several leading AI and LLM orchestration frameworks. You can use Docling to power document parsing and ingestion within the following ecosystems:

    • LangChain: For building LLM applications via chains.
    • Langflow: For visual orchestration of AI workflows.
    • LlamaIndex: For advanced RAG (Retrieval-Augmented Generation) and data indexing.
    • Metaxy: For AI agent orchestration.
    • Semantica: For semantic search and data processing.
    • Haystack: For building NLP pipelines.
    • Crew AI: For multi-agent collaborative workflows.
  4. Overview of the Docling usage skill references

    main

    The Docling usage skill is organized into a router (SKILL.md) and several specialized reference files. This structure allows an AI agent to load only the specific documentation required for a given task, minimizing context window usage.

    Available Skill References

    TaskReference File
    Read/convert a file from the shellcli.md
    Convert in code and tune the pipeline (PipelineOptions)python-sdk.md
    Extract specific typed fields from a documentextraction.md
    Chunk documents for RAGrag.md
    Offload conversion to a remote serviceservice-client.md
    Install only the dependencies you needslim-packaging.md

    Skill Directory Structure

    When located, the skill directory follows this structure:

    docling/.agents/skills/docling/
    ├── SKILL.md                     # Entry point/router
    └── references/
        ├── cli.md
        ├── python-sdk.md
        ├── extraction.md
        ├── rag.md
        ├── service-client.md
        └── slim-packaging.md
  5. 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 typically require extra model executions and are disabled by default to save processing time.

    FeatureParameterProcessed itemDescription
    Code understandingdo_code_enrichmentCodeItemAdvanced parsing and language detection for code blocks.
    Formula understandingdo_formula_enrichmentTextItem (label FORMULA)Extracts LaTeX representation of equations.
    Picture classificationdo_picture_classificationPictureItemClassifies figures (e.g., charts, logos, signatures).
    Picture descriptiondo_picture_descriptionPictureItemAnnotates pictures using Vision Language Models (VLM).
  6. How Docling's architecture works

    main

    Docling's architecture is built around a modular conversion process. For any given document format, a document converter selects a specific backend for parsing and a pipeline to orchestrate the execution using specific options.

    Key components include:

    • Document Converter: Orchestrates the conversion process. While it has default mappings for formats, these are parametrizable (e.g., you can specify different backends or pipeline options for PDFs).
    • Docling Document: The fundamental internal representation of a document after conversion.
    • Conversion Result: The output of the converter, which contains the Docling document.
    • Post-processing Tools: Once you have a Docling document, you can use export methods (e.g., to Markdown or a dictionary), a serializer for storage, or a chunker for breaking the document into smaller pieces.

    Developers can extend the system by subclassing the base classes (indicated by dashed outlines in the architecture diagram) to create specialized implementations.

  7. Navigate DoclingDocument content items and structure

    main

    A DoclingDocument organizes information into two main categories: Content Items (the actual data) and Content Structure (the hierarchy). Items reference parents and children using JSON pointers.

    Content Items

    These are stored as lists in the following top-level fields:

    • texts: Items with text representation (e.g., paragraphs, headings, equations). Base class: TextItem.
    • tables: Table data. Type: TableItem.
    • pictures: Image data. Type: PictureItem.
    • key_value_items: Key-value pairs.

    Note: All items above inherit from the DocItem type.

    Content Structure

    These fields store NodeItem instances that define the document's organization:

    • body: The root node of the tree structure for the main document content. The reading order is determined by the body tree and the order of children within each item.
    • furniture: The root node for items outside the main body, such as headers and footers.
    • groups: A set of container items (e.g., lists, chapters) that do not represent content themselves but hold other content items.
  8. How compute engines work in docling-serve

    main

    The DOCLING_SERVE_ENG_KIND setting determines how conversion jobs are dispatched.

    1. Local Engine (local): The default. Jobs run in an in-process thread pool inside the server. No external services are required. Best for single-machine setups.

      • Tune with DOCLING_SERVE_ENG_LOC_NUM_WORKERS (default 2).
      • Tune with DOCLING_SERVE_ENG_LOC_SHARE_MODELS (default false).
    2. RQ Engine (rq): A distributed model using Redis. The API tier enqueues jobs to Redis, and separate docling-serve rq-worker processes execute them. This allows the API and workers to scale independently. Best for high throughput and horizontal scaling.

    3. Cluster Engines: Support for KFP (Kubeflow Pipelines) and Ray is available via the docling-serve repository for cluster orchestration.

  9. Understand the API response format

    main

    A successful single-file conversion returns a JSON object containing the requested content fields (e.g., md_content, json_content), the conversion status, processing_time, and any errors. If you requested a zip target or the job produces multiple files, the response will be a zip archive instead of JSON.

    {
      "document": {
        "md_content": "",
        "json_content": {},
        "html_content": "",
        "text_content": "",
        "doctags_content": ""
      },
      "status": "success",   // success | partial_success | skipped | failure
      "processing_time": 0.0,
      "timings": {},
      "errors": []
    }
  10. Understand the DoclingDocument data model

    main

    The DoclingDocument is the central data structure representing a processed document in Docling. It follows a hierarchical model composed of various item types that describe the document's structure, content, and layout.

    Key components of the document model include:

    • Structural Items: DocItem, GroupItem, NodeItem, SectionHeaderItem, and PageItem define the document's hierarchy and layout.
    • Content Items: TextItem, TableItem (including TableCell, TableData, and TableCellLabel), PictureItem (including ImageRef and PictureClassificationData), and KeyValueItem represent the actual data extracted.
    • Spatial Information: BoundingBox, Size, and CoordOrigin provide geometric context for items on a page.
    • Metadata and Provenance: DocumentOrigin and ProvenanceItem track the source and origin of document elements.
    • References: RefItem handles links and references within the document.