Skip to content

Latest commit

 

History

History
100 lines (75 loc) · 3.84 KB

File metadata and controls

100 lines (75 loc) · 3.84 KB

Docling LangChain integration

PyPI version PyPI - Python Version uv Code style: black Imports: isort Pydantic v2 pre-commit License MIT

A Docling integration for LangChain.

Installation

Simply install langchain-docling from your package manager, e.g. pip:

pip install langchain-docling

Development setup

To develop for Docling LangChain, you need Python 3.10 through 3.14 and uv. You can then install from your local clone's root directory:

uv sync

Usage

Basic usage

Basic usage of DoclingLoader looks as follows:

from langchain_docling import DoclingLoader

FILE_PATH = ["https://arxiv.org/pdf/2408.09869"]  # Docling Technical Report

loader = DoclingLoader(file_path=FILE_PATH)
docs = loader.load()

Docling Serve or Managed Docling

Pass Docling's existing DoclingServiceClient as the loader's converter to run conversion remotely. The same client works with Docling for IBM watsonx and a self-hosted Docling Serve endpoint:

import os

from docling.datamodel.service.options import ConvertDocumentsOptions
from docling.service_client import DoclingServiceClient

from langchain_docling import DoclingLoader

service_url = os.environ["DOCLING_SERVICE_URL"]
api_key = os.environ["DOCLING_API_KEY"]
options = ConvertDocumentsOptions(
    do_ocr=True,
    table_mode="accurate",
)

with DoclingServiceClient(url=service_url, api_key=api_key) as client:
    loader = DoclingLoader(
        file_path=["https://arxiv.org/pdf/2408.09869"],
        converter=client,
        convert_kwargs={"options": options},
    )
    docs = loader.load()

The loader does not take ownership of a supplied client. Keep the client open until load() completes or until a lazy_load() iterator has been fully consumed. For a self-hosted endpoint that does not require authentication, omit api_key.

Advanced usage

When initializing a DoclingLoader, you can use the following parameters:

  • file_path: source as single str (URL or local file) or iterable thereof
  • converter (optional): a local DocumentConverter, remote DoclingServiceClient, or compatible converter
  • convert_kwargs (optional): backend-specific kwargs for conversion execution, such as {"options": ConvertDocumentsOptions(...)} for the service client
  • export_type (optional): export mode to use: ExportType.DOC_CHUNKS (default) or ExportType.MARKDOWN
  • md_export_kwargs (optional): any specific Markdown export kwargs (for Markdown mode)
  • chunker (optional): any specific Docling chunker instance to use (for doc-chunk mode)
  • meta_extractor (optional): any specific metadata extractor to use

Docs and examples

For more details and usage examples, check out this page.