- 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 o imagen -> detectar si hay texto seleccionable -> OCR si hace falta -> reconstruir orden de lectura -> extraer tablas como HTML/Markdown/JSON -> añadir metadatos: documento, página, sección -> revisión de muestra -> chunking e indexación
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 factura.pdf --to md --output salida_docling/ # Revisa antes de indexar: ls salida_docling cat salida_docling/factura.md
Output format for invoices
{
"document_id": "factura-2026-001",
"page": 1,
"type": "invoice",
"supplier": "Proveedor S.L.",
"invoice_number": "F-2026-001",
"date": "2026-07-02",
"total": 242.00,
"currency": "EUR",
"table_rows": [
{"concept": "Servicio mensual", "base": 200.00, "vat": 42.00}
],
"source_text": "fragmento verificable..."
}