Design a PDF Ingestion and Retrieval-Augmented Generation Pipeline
Company: Nike
Role: Software Engineer
Category: ML System Design
Difficulty: medium
Interview Round: Technical Screen
## Scenario
Design a pipeline that ingests PDF documents and supports retrieval-augmented answers with page-level citations. PDFs may contain selectable text, scanned pages, tables, repeated headers, and malformed files. Updates and deletions must be reflected in search without leaving stale chunks.
### Constraints & Assumptions
- Files arrive through an object store and are processed asynchronously.
- A document can have several versions, but only one approved version should be queryable at a time.
- Some pages require OCR, and OCR can be slow or low confidence.
- Users may retrieve only documents permitted by their current identity.
- The query path must return evidence that can be mapped back to a document version and page region.
### Clarifying Questions to Ask
- Which languages, layouts, maximum sizes, and table or image semantics must be supported?
- What ingestion freshness and query latency targets apply?
- Are citations page-level, paragraph-level, or bounding-box-level?
- How should low-confidence OCR and password-protected PDFs be handled?
- What permission and retention systems are authoritative?
```hint Preserve layout provenance through every stage
A chunk should retain document version, page, source offsets or bounding boxes, parser version, and OCR confidence.
```
### What a Strong Answer Covers
- Secure upload, type validation, malware isolation, immutable versioning, and durable ingestion work.
- A parser cascade for embedded text, OCR, layout, tables, and explicit quarantine of unsupported files.
- Header and footer cleanup, chunking that respects sections and token limits, and reproducible chunk identities.
- Batched embeddings plus keyword indexing, metadata filters, atomic publication of a complete version, and tombstoned deletion.
- Permission filtering before prompt construction and citation links bound to the exact page region.
- Retry, idempotency, reconciliation, backpressure, cost controls, and observability by processing stage.
- Evaluation of extraction quality, retrieval recall, citation precision, groundedness, and permission leakage.
### Follow-up Questions
1. How do you avoid serving half of a newly indexed document version?
2. What happens when the OCR model or chunking logic changes?
3. How would tables be represented so answers can cite the correct cells?
4. How do you prove a deleted document is absent from indexes and caches?
Quick Answer: Design PDF ingestion and retrieval-augmented generation with page-level citations across selectable text, scans, tables, repeated headers, malformed files, updates, and deletions.