An ETL pipeline for unstructured data ingests raw documents (PDF, HTML, DOCX, images, tables) and outputs clean, deduplicated, chunked text with metadata, work that takes much of the effort in a RAG or training project and gets little attention.
Four stages: parse, clean, deduplicate, chunk
Parsing extracts text from PDFs, HTML and DOCX files. Tools such as Unstructured.io or LlamaParse use layout-aware techniques to keep structure, and vision models can read text from scanned pages and tables. Weak parsing loses context and structure for the later stages.
Cleaning removes boilerplate, navigation menus and footers, and fixes encoding issues. Leftover noise confuses downstream models.
Deduplication removes exact duplicates with hashing, and near-duplicates with methods such as MinHash or SimHash. Run it before embedding, so redundant passages do not crowd out other results.
Chunking splits the cleaned text semantically or structurally, with overlapping segments and headings kept as metadata. Missing deduplication floods retrieval with redundant text, and bad chunking cuts apart the context a query needs.
- Ingest the raw documents.
- Parse with layout-aware tools.
- Clean out unwanted content.
- Deduplicate with hashing, MinHash or SimHash.
- Chunk semantically or structurally.
Order matters. Parsing keeps the layout that cleaning and chunking depend on, cleaning removes the noise that would otherwise be embedded, and deduplication keeps copies out of the index. Skipping a stage pushes its errors into the stages after it, and the final retrieval system is where they surface.
"Clean" has no schema to check against
Classic ETL validates data against a schema, and a badly structured table trips a CHECK constraint. With unstructured data no such safety net exists. Clean here means the data supports retrieval and generation downstream. If a table is split wrongly or context is lost, nothing fails at load time. The damage shows up as wrong answers later.
Why fixed-size chunks shatter tables
A newcomer extracts all the text and cuts it every 1000 characters. That shatters tables, breaks context, leaves orphaned fragments and creates near-identical passages that dominate retrieval results. The root cause is ignoring layout and semantics, so the dataset no longer represents the source.
For uniform prose, cheap fixed-size chunking can be enough, since structure is simple and little context is at risk. Documents with tables, forms, code or nested structure need layout-aware parsing and semantic chunking.
Example scenario: 30% of PDFs fail to parse
Suppose the pipeline fails on 30% of PDFs (an illustrative figure). Unhandled formats or corrupted files are likely causes. A PDF with non-standard fonts or embedded images can be skipped, so ingestion is incomplete.
- Read the ETL logs for parsing errors.
- Measure processed documents against total ingested.
- Inspect failed documents manually for shared traits.