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:
| Stage | Output | Typical failure |
|---|---|---|
| Fetch | Raw file, owner, version and permission data | Partial download, missing permission data |
| Validation | Accept, or reject with a reason | Spoofed extension, encrypted file, oversized archive |
| Parsing and OCR | Text, pages, headings and table structure | Empty text from scanned pages, flattened tables |
| Enrichment | Language, effective date, sensitivity label | Wrong language detected, missing date |
| Chunking | Passages with their heading path | Passages cut off from their heading, split tables |
| Embedding | Passage vectors | Different model versions mixed in one index |
| Index write | Searchable records | Fields silently lost on a schema mismatch |
| Verification queries | "Ready" status | Errors 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.
| Stage | What happens | Check |
|---|---|---|
| Fetch | The file is fetched with its version number and "all employees" permission | Content hash is new, permission data complete |
| Validation | File signature is PDF, no password, scan clean | Accepted |
| Parsing | 58 pages come from the text layer; the signature page and an appendix table go through OCR | Pages sent to OCR and their confidence scores are recorded |
| Enrichment | Effective date is added and version 3 is marked "superseded" | Date field filled |
| Chunking and index | Passages are written with their heading paths, and the table row by row | Passages written equal passages expected |
| Verification queries | Exact 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.