From PDFs in S3 to searchable data: an ingestion pipeline that reruns safely
Retrieval quality is capped by ingestion quality. If entities come out of your documents wrong, no amount of prompt tuning fixes the answers downstream.
The shape of the pipeline
- Land raw files in S3, partitioned by date. Never overwrite them.
- Extract text, tables and forms with Amazon Textract.
- Enrich with LLM entity extraction — few-shot examples plus a ReAct or chain-of-thought prompt per entity type.
- Index into OpenSearch for hybrid (keyword + vector) retrieval.
Each step is its own Airflow task, so a failure retries one step, not the whole run.
Three rules that keep it safe to rerun
- Raw is immutable. Every later step can be rebuilt from the landed files.
- Writes are idempotent. Key every record by document id + version, and upsert. Rerunning a day must never duplicate rows.
- Fail closed. If validation fails — empty extraction, schema drift, a sudden drop in entity counts — do not publish the new index.
Measuring it
Track context precision and recall on a small labelled set every run. Ours stayed above 80%; when it dipped, the cause was almost always an upstream document format change, not the model.
Treat extraction quality as a data contract, not a model detail.