Why this matters
Retrieval quality is capped by ingestion quality. A table split in half, a scanned page with garbled text, or a document that was deleted but still answers questions: these are ingestion bugs, and they look like "the AI is wrong".
The pipeline
- Connect: files, wikis, tickets, databases. Check type and size.
- Parse: layout-aware for PDFs and scans (tables, headers, columns); OCR where needed.
- Handle sensitive data: redact or classify personal data before anything is indexed.
- Normalise + metadata: title, section path, page, version, source ID, tenant, ACL labels, dates.
- Chunk (below).
- Embed in batches; record the embedding model.
- Index: vectors + lexical index + metadata, in one transaction where possible.
Q3. Chunk size and overlap?
No universal size. Structure-aware first (never split a lab table, dosage block or coverage criterion), baseline on a representative query set, then compare sizes and overlap on recall@k and answer quality. Small: precise, loses context. Large: context, diluted embeddings, more tokens.
Strategies
| Strategy | How | Good for |
|---|---|---|
| Fixed size + overlap | N tokens with M overlap | Uniform prose; quick baseline |
| Structure-aware | Split on headings, sections, list items, table boundaries | Manuals, policies, contracts |
| Parent-child | Retrieve small chunks, return their larger parent section | Precise matching with enough context |
| Semantic | Split where topic shifts | Long unstructured text |
Prepend context to each chunk ("Policy X › Section 4.2 › Exclusions") so it stands on its own.
Q9. Updates and deletions?
Version documents and chunks; idempotent ingestion keyed by source ID + checksum; supersede on update; on delete remove vectors, lexical entries and caches, then verify. Embedding model change = full re-embed with a dual-index cutover.
Common mistakes
- Naive PDF text extraction that scrambles tables and columns.
- No source ID or checksum, so re-ingestion creates duplicates.
- Deleting the document row but not its vectors and cached answers.
- Choosing chunk size by intuition rather than measurement.
Worked example: one policy document
source: handbook.pdf (v7, sha256 3f1…, tenant t_42, acl: [staff])
parse → 42 pages, 3 tables kept intact, headings detected
chunks → 118 structure-aware chunks; 12 parent sections
each prefixed: "Handbook › Leave › Parental leave (v7) — …"
embed → 118 vectors, embed_model = "embed-v3"
index → vectors + tsvector + metadata in one transaction
update → v8 arrives: new checksum → new version written, v7 chunks marked superseded
delete → vectors, lexical rows, caches removed; retrieval test confirms nothing returns
Interview follow-ups
- "How do you handle tables in PDFs?" Layout-aware parsing that keeps tables whole; store them as Markdown or row-wise text with headers repeated, plus a summary chunk.
- "How do you index scanned documents?" OCR with confidence scores; low-confidence pages flagged; keep page images for review.
Check yourself
How do you make ingestion idempotent?
Key every document by source ID and a content checksum. If the checksum is unchanged, skip; if changed, write a new version and mark old chunks superseded, in one transaction. Re-running the pipeline produces the same state.
What's the risk of an embedding model change, and how do you handle it?
Old and new vectors aren't comparable. Re-embed everything into a new index, run evals on both, switch reads atomically, then retire the old index.
Build it
Ingest a set of Markdown or PDF documents with structure-aware chunks, section-path prefixes, source IDs and checksums. Re-run it and prove no duplicates appear; delete one document and prove it can't be retrieved.