- Decide when you need OCR and when plain text extraction is enough.
- Preserve tables, pages, and metadata before indexing.
- Create a reviewable intermediate output before embeddings.
Recommended pipeline
PDF or image -> detect if selectable text exists -> OCR if needed -> reconstruct reading order -> extract tables as HTML/Markdown/JSON -> add metadata: document, page, section -> sample review -> chunking and indexing
Example with Docling
Docling is designed to convert complex documents into structure useful for AI: text, tables, layout, and exportable formats.
pip install docling docling invoice.pdf --to md --output docling_output/ # Review before indexing: ls docling_output cat docling_output/invoice.md
Output format for invoices
{
"document_id": "invoice-2026-001",
"page": 1,
"type": "invoice",
"supplier": "Supplier S.L.",
"invoice_number": "F-2026-001",
"date": "2026-07-02",
"total": 242.00,
"currency": "EUR",
"table_rows": [
{"concept": "Monthly service", "base": 200.00, "vat": 42.00}
],
"source_text": "verifiable fragment..."
}