Document ingestion & cleaning
Turn messy PDFs, pages and tickets into clean, attributable text before anything else can work.
Garbage in, garbage retrieved. Parsing is the least glamorous stage and often the biggest quality lever. PDFs lose reading order across columns, tables flatten into nonsense, scanned pages need OCR, and web pages carry navigation and cookie banners that pollute every chunk.
Extract structure, not just text: headings, lists, tables and page numbers. Convert tables to a form the model can read, such as Markdown or row-wise sentences. Strip boilerplate. Detect and remove duplicates and near-duplicates so the same paragraph does not crowd out other results.
Attach metadata at ingestion, because you cannot add it later: source id, title, URL, section path, author, created and updated dates, language, and access control. Store a content hash so re-ingestion can skip unchanged documents and update only what changed.
Key points
- Parsing quality caps everything downstream. Inspect real parsed output.
- Preserve structure: headings, tables, page numbers.
- Deduplicate and strip boilerplate before chunking.
- Capture metadata and a content hash at ingestion for filters, citations and incremental updates.
Answer these out loud
- 1A two-column PDF is parsed with sentences from both columns interleaved. How would you detect it and what do you change?
- 2Which metadata fields would you need to answer 'only use documents the asking user may see, updated in the last year'?
Build it
Write an ingester for a folder of PDFs and Markdown files that outputs one JSON record per section with source, heading path, page and content hash, and skips unchanged files on re-run.
Use this from an agent
Any MCP client, including Grok, can read this lesson. See how to connect.
curl https://engineeros-delta.vercel.app/api/v1/topics/rag-document-ingestion