Designing a Document Ingestion Pipeline
Engineering

Designing a Document Ingestion Pipeline

Uploading a file is only the first step toward a searchable, permission-correct document. Here is what each stage should check, and when a document is really ready.

Short answer

A document ingestion pipeline is a staged process that fetches files from source systems, validates them, extracts their text and structure, chunks and embeds them, and writes them to a search index with their permissions. In a good design each stage's status is tracked separately, every passage is tied to its original file, page, version and permissions, permanent failures go to a separate queue, and a document counts as ready only after its own test queries pass.

What is a document ingestion pipeline, and what stages does it have?

A document ingestion pipeline is a staged process that takes files from source systems, validates them, extracts their text and structure, splits them into chunks, turns those chunks into embeddings and writes them to a search index together with their permissions. Much of a RAG assistant's answer quality is decided here: no later step can fix a document that entered the index wrongly or incompletely. Each stage has its own output and its own typical failure:

StageOutputTypical failure
FetchRaw file, owner, version and permission dataPartial download, missing permission data
ValidationAccept, or reject with a reasonSpoofed extension, encrypted file, oversized archive
Parsing and OCRText, pages, headings and table structureEmpty text from scanned pages, flattened tables
EnrichmentLanguage, effective date, sensitivity labelWrong language detected, missing date
ChunkingPassages with their heading pathPassages cut off from their heading, split tables
EmbeddingPassage vectorsDifferent model versions mixed in one index
Index writeSearchable recordsFields silently lost on a schema mismatch
Verification queries"Ready" statusErrors nobody notices because this step was skipped

The last row is the step most often skipped. A file that uploaded, or a job that shows green, does not mean the assistant can find the right passage in that document and cite it.

What should the pipeline contract define?

It should define in writing, for each source, what the pipeline accepts, how it identifies a document and when it considers that document "ready". For each source record at least the supported formats, the owner, where the stable document ID comes from, version information, tenant, access rules, update frequency, deletion behaviour, size limits, expected languages and sensitivity level. Name the document states separately too: fetched, validated, parsed, chunked, embedded, indexed, passed query test, quarantined and deleted.

The contract makes visible the checks that tools do not do for you. Microsoft's documentation on creating indexers for Azure AI Search states two points plainly: indexers don't fix data quality issues, and during indexing only field names and types are checked; there is no validation step that ensures incoming content is correct for its field. The same page reminds you that a successful run can still include warnings. When you write the contract, Microsoft's guide to the RAG preparation phase also helps: it recommends analysing content classifications, formats, security constraints and structural features (multi-column pages, headers and footers, tables, languages) in advance, and gathering at least two test documents for each content variant and format.

How do you validate files before they enter the pipeline?

Put every file through a security and suitability gate before it reaches the parser. OWASP's file upload cheat sheet is a good checklist for that gate: define allowed extensions as a list; do not trust the Content-Type value, which is supplied by the user and trivial to spoof; validate the file signature; set size limits for upload and decompression to guard against compression bombs; and run files through antivirus scanning or, for document types such as PDF and DOCX, content disarm and reconstruction (CDR). Add three rules specific to document ingestion. Route encrypted or password-protected files to a separate path and notify the owner. Use a content hash to catch the same file arriving from two folders, and decide by the permission rules whether to keep one record or two. Finally, always record a rejection with its reason; "could not be processed" does not tell the owner what to fix.

How do you preserve structure during parsing and OCR?

Extract structure, not just text: page numbers, headings, paragraphs, tables, figures and the position of each element on the page. Microsoft's Document Intelligence layout model is a good example: it assigns paragraphs roles such as title, section heading, page header, page footer, page number and footnote, returns tables with their row and column structure, and reports whether a page is rotated. Using these roles to remove headers and footers stops lines such as "Confidential – Internal" that repeat on every page from polluting passages. The same page is clear about its limits as well: password-locked PDFs must be unlocked before submission; in Word, Excel, PowerPoint and HTML files embedded text is extracted as is but embedded images aren't supported; and table analysis isn't supported for Excel files. If information in embedded images matters, plan a separate processing step.

Scanned documents need particular care. Azure's indexer troubleshooting guide notes that PDFs containing only scanned images don't produce results in a standard blob indexing pipeline, and that OCR or image analysis is needed to get the text. A simple rule catches this: if the number of characters extracted per page falls below a threshold, route the page to OCR. Record the name and version of the parser and OCR engine with every output; a version change can alter chunk boundaries and therefore the evidence that gets retrieved. Always keep the original file, and link every passage to the page and region it came from.

How do permissions and personal data travel through the pipeline?

Connectors read files with a service identity that has broad read access, so the permission data saying who may read a document has to be fetched from the source separately at fetch time and copied unchanged onto every passage derived from the document. If the chunking step forgets to carry the permission fields, a permission that is correct at document level is lost at passage level. Decide on personal data at the start of the pipeline too: write into the contract which document types may contain personal data, whether masking is required before embedding and how long data is retained. Embeddings and passage copies are derived data; when the original document is deleted or its retention period ends, they must be deleted as well.

How do you handle retries, failures and ordering?

Make every stage idempotent: derive the IDs of the records a stage produces from the document ID, version and chunk position, so that running the same job twice produces the same records rather than duplicates. Do not reprocess a file whose content hash has not changed. Retry transient failures (network outages, rate limits) a limited number of times with increasing waits; quarantine permanent failures (corrupt files, unsupported formats) and notify the owner.

If you use queues, a dead-letter queue is the standard tool for that separation. Amazon SQS's dead-letter queue documentation makes three practical points: the number of times a message can be received before it moves to the dead-letter queue (maxReceiveCount) should be high enough to allow sufficient retries; the dead-letter queue's retention period should be longer than the source queue's; and once the problem is fixed, messages can be moved back to the source queue. The same page advises against using a dead-letter queue with a FIFO queue when the exact order of operations matters. Order matters in document ingestion too: if a document's update is quarantined and a later delete is applied first, reprocessing the update afterwards brings the deleted document back. So rather than replaying a failed message as it was, read the document's current state from the source when you reprocess it.

A single problem file should not stop the whole pipeline. In Azure indexers, parameters such as maxFailedItems set how many failures are tolerated before the whole job counts as failed; choose that value deliberately and still write tolerated failures to the failure list.

Hypothetical example: a 60-page staff handbook

The HR department publishes version 4 of its handbook: a 60-page PDF with a table of leave limits and a scanned signature page. The values are illustrative.

StageWhat happensCheck
FetchThe file is fetched with its version number and "all employees" permissionContent hash is new, permission data complete
ValidationFile signature is PDF, no password, scan cleanAccepted
Parsing58 pages come from the text layer; the signature page and an appendix table go through OCRPages sent to OCR and their confidence scores are recorded
EnrichmentEffective date is added and version 3 is marked "superseded"Date field filled
Chunking and indexPassages are written with their heading paths, and the table row by rowPassages written equal passages expected
Verification queriesExact title, one value from the leave table, "Does the old version still apply?", a search as an external identity"Ready" only if all four return the expected result

If OCR loses the table header, the document does not become "ready"; it goes to review. Whether version 3 keeps being served in the meantime must follow an explicit rule; if it does, the answer should say that this is the previous version and that a new one is being processed. A confident answer based on the wrong version does more harm than no answer at all.

How do you monitor the pipeline?

On the dashboard, track counts by document state, time per stage, rejection rate and reasons, the age of the oldest quarantined document, the share of pages sent to OCR, the number of orphan passages whose source has been deleted, and the lag from a source change to searchability. Compare the source inventory with the document IDs in the index regularly. Keep lineage end to end: from the citation in an answer to the passage, from the passage to the parser output, and from there to the original file and the versions of the parser and embedding model used. Only with that chain can you see which stage broke a bad answer and fix it.

Common mistakes

  • Treating a document as ready once the upload succeeds, with no document-specific query test.
  • Trusting the extension and Content-Type instead of checking the file signature.
  • Indexing scanned pages with empty text.
  • Leaving each page's header and footer inside the passages.
  • Replaying a failed message out of order and bringing a deleted document back.
  • Not recording parser and embedding model versions.

We go into how parsed structure should be split into passages in our article on chunking documents at scale. A document ingestion pipeline that keeps the index current as documents change is one of the components delivered on our enterprise RAG and semantic search service page.

Key takeaways

  • Write a pipeline contract for each source covering formats, ID, version, permissions, deletion behaviour and what "ready" means.
  • Before parsing, check files against an extension allowlist, their file signature, size limits and an antivirus scan.
  • Preserve structure: separate pages, headings, tables, headers and footers, and route pages with little text to OCR.
  • Make stages idempotent, quarantine permanent failures with a reason, and read the source's current state when reprocessing.
  • Count a document as ready only after its own test queries pass: title, a table value, a permission denial and a version question.

Frequently asked questions

What is a document ingestion pipeline for RAG?

It is the process that turns files in source systems into searchable, permission-correct passages: fetch, validation, parsing and OCR, enrichment, chunking, embedding and writing to the index. Each stage has its own status, failure reasons and checks.

How are scanned PDFs handled in an ingestion pipeline?

Detect pages that yield little or no text and route them to OCR. Record OCR confidence and engine version, send low-confidence pages to review, and never index a scanned page with empty text.

What should happen to files that fail during ingestion?

Retry transient failures a limited number of times with increasing waits. Move permanent failures to a quarantine or dead-letter queue with a reason and notify the owner. When you reprocess, read the document's current state from the source instead of replaying the old message.

How do I know a document is ready to be searched?

Run a few queries specific to that document after indexing: its exact title, a key clause, a table value, a search under an identity that should be denied, and a question about the previous version. The document is ready only when all of them return the expected result.

Which security checks belong in document ingestion?

An extension allowlist, file signature validation, size and decompression limits, antivirus scanning or content disarm and reconstruction, a separate path for encrypted files, and capturing permission data from the source at fetch time.

All articles