Document Ingestion and Parsing
Real-world data is PDFs, HTML, slides and spreadsheets; clean extraction and a repeatable, incremental pipeline decide RAG quality.
Intermediate · about 5 hours · difficulty 3/5
Learn first: RAG Fundamentals
Garbage in, garbage retrieved. Ingestion is unglamorous but it is where many RAG projects are won or lost.
Extracting text
- PDFs are layouts, not documents. Text extractors can scramble columns, headers and tables. Try a few parsers; for complex layouts use layout-aware tools or send page images to a vision-capable model.
- HTML: strip navigation, footers and scripts; keep headings for structure.
- Office files, Markdown, code, email, chat exports: each needs its own loader.
- Tables: keep them intact, convert to Markdown, or also store a natural-language summary.
- Scanned documents need OCR.
The pipeline around it
- Normalize: fix whitespace, encoding and boilerplate; remove duplicates.
- Capture metadata: source URL, title, author, dates, permissions.
- Incremental updates: hash content so unchanged documents are skipped and edited ones are re-chunked and re-embedded. Handle deletions so stale chunks disappear.
- Idempotence and logs: rerunning ingestion must not create duplicates; log failures per file.
Pitfalls
Never trust extraction blindly. Spot-check a sample of parsed documents by eye, especially tables and multi-column pages. Also remember that ingested documents may contain hidden instructions (prompt injection) or sensitive data (PII).
Good enough to move on
You have an ingestion job that handles at least three file types, skips unchanged files, removes deleted ones, and logs failures.
Key concepts
- PDF text extraction
- HTML cleaning
- Tables and structured content
- OCR and vision-based parsing
- Content hashing and incremental updates
- Handling deletions
- Parsing libraries (Unstructured, Docling)
Mini project
Write an ingestion job that watches a folder of PDFs, HTML and Markdown files, parses and chunks them, and on rerun only processes changed files and removes chunks for deleted files.
Check yourself
A policy PDF was updated but users still get answers from the old version. What part of your ingestion pipeline failed?
Free resources
- Docling documentation (Docling)
- Unstructured open source docs (Unstructured)