Skip to main content

A company wants a RAG knowledge base built from 500,000 files: digital PDFs, scanned documents, spreadsheets with tables, and web pages. Design the ingestion pipeline.

System design · Intermediate 3

Short answer

Clarify file types, languages and quality needs. Detect the type of each file and route it: text extraction for digital PDFs, OCR for scans, table-aware parsing for tables, boilerplate removal for web pages. Normalise to one format with structure, chunk by headings, add metadata, deduplicate, embed and index. Run as queued jobs and check quality on samples.

Deeper answer

Requirements: the mix of file types, languages and scripts, how tables and figures matter to the questions users ask, and access rules. Look at a sample of each type before choosing tools.

Pipeline: a job per file on a queue. A detector checks whether a PDF has a text layer. Digital PDFs go through text extraction with layout handling for columns, headers and footers. Scans go through OCR, with a confidence score per page. Tables are kept as tables, as Markdown or rows with the header repeated, because flattened table text loses meaning. Web pages lose menus and footers. Everything becomes one intermediate format with headings, page numbers and source links. Then chunk along the structure, attach metadata such as title, section, date and permissions, remove duplicates, embed and index.

Trade-offs: a vision-capable model can parse complex pages and tables better than classic OCR, but costs more per page and can invent text, so use it only for hard pages. Measure extraction accuracy on a labelled sample and retrieval recall on real questions. At scale, failed files and slow OCR come first, so use retries and a dead-letter queue.

What a strong answer covers

Answer it out loud in the mock interview about 2 min

Follow-ups to expect

Common mistakes

Learn it

Parsing documents and OCR

Practice System design questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.