Skip to main content

Docling for Synthetic Data Generation (SDG) provides a set of tools to create artificial data from documents, leveraging generative AI and docling's parsing capabilities.

Project description

Docling SDG

Platforms uv Ruff Pydantic v2 pre-commit License MIT

Docling for Synthetic Data Generation (SDG) provides a set of tools to create artificial data from documents, leveraging generative AI and Docling's parsing capabilities.

Features

  • 🧬 Generation of question-answering pairs from passages of [multiple document formats][supported_formats] including PDF, HTML, or DOCX, leveraging Docling's parsing capabilities
  • ⚖️ LLM as a judge for high quality question-answering pairs
  • 💻 Simple and convenient CLI

Coming soon

  • 📝 Integrations with Llama Stack and vLLM
  • 📝 SDG on tabular data
  • 📝 Documentation

Installation

To use Docling SDG, simply install docling-sdg from your package manager, e.g., pip:

pip install docling-sdg

Alternatively, you can clone this repository and use uv for creating a virtual environment, installing the packages, and running the project commands.

git clone git@github.com:docling-project/docling-sdg.git
cd docling-sdg
uv sync

Getting started

You can create synthetically-generated questions and answers from relevant parts of one or several documents. These question-answer pairs may be used in AI applications, such as evaluating a RAG application or generating ground truth to train a language model.

Sample

Generating and judging data with LLMs may be computationally intense. Since document collections may be large, you may want to chunk the documents into passages, filter them based on length and content criteria, and sample a bunch of them to have a manageable dataset.

from docling_sdg.qa.sample import PassageSampler

source = "https://en.wikipedia.org/wiki/Duck"
passage_sampler = PassageSampler()
print(passage_sampler.sample(source))

By default, the results will be exported to the file docling_sdg_sample.jsonl. Every line represents a document passage.

Generate

For each passage created in the previous step, we can prompt an LLM and generate 3 different questions of the following types: simple fact, summary, and reasoning.

Note that Docling SDG uses watsonx.ai and you will need to provide a watsonx.ai instance ID and an API key.

import os
from docling_sdg.qa.base import GenerateOptions
from docling_sdg.qa.generate import Generator

options = GenerateOptions(
    project_id=os.environ.get("WATSONX_INSTANCE_ID"),
    api_key=os.environ.get("WATSONX_APIKEY"),
)

generator = Generator(generate_options=options)
print(generator.generate_from_sample("docling_sdg_sample.jsonl"))

By default, the results will be exported to the file docling_sdg_generated_qac.jsonl. Every line represents a generated question-answer-context item with additional information like the question type.

Critique

Certain applications may require certain quality in the generated data. The last step consists of using an LLM to judge the generated data and provide both qualitative and quantiative evaluations of the question-answer-context items. Using those evaluations, we can filter the generated dataset to the required quality levels.

import os
from docling_sdg.qa.base import CritiqueOptions
from docling_sdg.qa.critique import Judge

options = CritiqueOptions(
    project_id=os.environ.get("WATSONX_INSTANCE_ID"),
    api_key=os.environ.get("WATSONX_APIKEY"),
)

judge = Judge(critique_options=options)
print(judge.critique("docling_sdg_generated_qac.jsonl"))

By default, the results will be exported to the file docling_sdg_critiqued_qac.jsonl. The file content is similar to the one created in the Generate step, but it additionally contains the critique evaluation on several dimensions such as question to context groundness, question feasibility or context usefulness.

CLI

Docling SDG has a built-in CLI to run the 3 steps of the question-answering data generation.

docling-sdg qa sample https://en.wikipedia.org/wiki/Duck
docling-sdg qa generate docling_sdg_sample.jsonl
docling-sdg qa critique docling_sdg_generated.jsonl

Find out more about optional parameters with the help argument. For instance:

docling-sdg qa generate --help

Get help and support

Please feel free to connect with us using the discussion section.

Technical report

For more details on Docling SDG's inner workings, check out the paper Know Your RAG: Dataset Taxonomy and Generation Strategies for Evaluating RAG System, as well as Docling Technical Report.

Contributing

Please read Contributing to Docling SDG for details.

References

If you use Docling SDG in your projects, please consider citing the following:

@inproceedings{teixeira-de-lima-etal-2025-know,
    title={Know Your RAG: Dataset Taxonomy and Generation Strategies for Evaluating RAG Systems}, 
    author={Rafael Teixeira de Lima and Shubham Gupta and Cesar Berrospi and Lokesh Mishra and Michele Dolfi and Peter Staar and Panagiotis Vagenas},
    year={2025},
    month={jan},
    booktitle={Proceedings of the 31st International Conference on Computational Linguistics: Industry Track},
    publisher={Association for Computational Linguistics},
    url={https://aclanthology.org/2025.coling-industry.4/}
}

License

The Docling SDG codebase is under MIT license. For individual model usage, please refer to the model licenses found in the original packages.

LF AI & Data

Docling is hosted as a project in the LF AI & Data Foundation.

IBM ❤️ Open Source AI

The project was started by the AI for knowledge team at IBM Research Zurich.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docling_sdg-0.1.3.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docling_sdg-0.1.3-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file docling_sdg-0.1.3.tar.gz.

File metadata

  • Download URL: docling_sdg-0.1.3.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for docling_sdg-0.1.3.tar.gz
Algorithm Hash digest
SHA256 729b334b097875322f19edf18e295a31733bc9ba8daf5f76bfa42bf53fee794f
MD5 8b369deb46dae75c7a27d562212d32ed
BLAKE2b-256 bab3de62fd8974ebf3efd05b9d65cfa0b70517fce197b86a47871fff6c25082f

See more details on using hashes here.

Provenance

The following attestation bundles were made for docling_sdg-0.1.3.tar.gz:

Publisher: pypi.yml on docling-project/docling-sdg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docling_sdg-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: docling_sdg-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for docling_sdg-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2e03f34b81d414996b3065c1ab9ea7f6a4e0b59bafcc7337103b3cc538c05c19
MD5 441eaf3b3e142f77bf91c155d8fbc0af
BLAKE2b-256 cb779136fef35af18a9ceb2fc6d497a4a5940e2fa821803387aa4b386af1c55e

See more details on using hashes here.

Provenance

The following attestation bundles were made for docling_sdg-0.1.3-py3-none-any.whl:

Publisher: pypi.yml on docling-project/docling-sdg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page