Loading and versioning source documents
medium 6 minIngestion has two outputs: searchable content and the information needed to maintain it.
Video lesson · Chapter 1 of 4
A deleted handbook returns
Theory
Read or listen first. About 2 min.
What it is
Ingestion has two outputs: searchable content and the information needed to maintain it. Document identity, revision, access scope, structure and deletion events matter just as much as extracted text. A connector’s cursor controls delivery, not the meaning of the records it delivers.
Why it exists
A corpus that is accurate on day one can drift after access changes or source deletions. Exercise update, retry and removal paths and check the resulting visible evidence under the same permissions as a real user.
A deleted handbook survives a connector retry
Inside this chapter
Chapter sources- Document Loader Fundamentals
- A loader converts source-specific objects into text plus metadata. Give each record a stable source ID, revision, access rules and extraction timestamp. Retaining only plain text makes later deletions, access changes and citations difficult to propagate through the index.
Treat the loader's output as a record, not a string. The
source_idplusrevisionpair is the key that makes writes idempotent: loading the same pair twice should be a no-op, and loading a higher revision should replace every chunk of the lower one. The access list and the deleted flag travel with the record so that downstream stages never have to go back to the source to ask who may read it.Example. Load a handbook twice with the same ID and revision. The second delivery should leave the searchable corpus unchanged.
Another example. A finance team's expense-policy loader runs nightly. If the policy has not changed, the run should write nothing; a run that adds a second copy of every chunk each night will slowly push the real answer out of the top results.
JSON{ "source_id": "handbook-12", "revision": 9, "title": "Staff handbook", "text": "Section 3. Leave requests ...", "acl": [ "group:staff" ], "sections": [ { "heading": "Leave", "page": 4, "offset": 1820 } ], "extracted_at": "2026-03-02T09:00:00Z", "deleted": false}One normalised record. Text alone would make deletions, access changes and citations impossible to follow later. - Web & URL Loaders
- A web loader should identify the canonical page and remove repeated navigation while retaining useful headings, links and timestamps. Honor access and fetch policies. Detect changes from source metadata or content hashes. Two URLs can represent one document, and one URL can produce different content over time.
Web pages carry a lot of repeated furniture: menus, footers, related-article lists. If that text is indexed, every page shares it and searches for words like "returns" match the menu on every page. Resolve the canonical address first (a canonical link tag or your own rules), strip the template, and hash what remains so you only re-index real changes. Respect robots rules and site terms for anything you do not own.
Example. Compare a page with its printer-friendly URL. Separate duplicated navigation content from article content before indexing either copy.
Turning two URLs into one document - 1Fetch two URLs
/help/returnsand its print view - 2Resolve canonicalboth map to
/help/returns - 3Strip furniturenav, footer, cookie bar removed
- 4Hash article textcompare with last revision
- 5Index only if changedone document, new revision
Duplicated navigation text would otherwise match the same words on every page.
- File Format Loaders
- Choose extraction by format. A plain-text reader preserves lines while a PDF extractor may return columns in reading order incorrectly. Store page or section positions for reconstruction. Compare a sample of extracted tables and captions with the originals before indexing thousands of documents.
Each format hides structure differently. Plain text and Markdown keep line order; Word files keep styles that mark headings; PDFs only store glyphs at positions, so the extractor has to guess reading order, and multi-column layouts or tables are where it guesses wrong. Keep the page number and position for every extracted span so a reviewer can jump straight to the original when something looks off.
Example. A two-column PDF extracts the right-hand price next to a left-hand product name. Verify the association visually before accepting the parser output.
A two-column price sheet, extracted two ways
Reading Line 1 Line 2 Correct? Naive text order Basic plan Pro plan 9.00 19.00 Ambiguous pairing Column-aware Basic plan · 9.00 Pro plan · 19.00 Yes Shifted columns Basic plan · 19.00 Pro plan · 9.00 Wrong price attached Illustrative. Check a sample visually against the original before trusting any parser on thousands of files. - Cloud & API Loaders
- A cloud connector reads authorized pages or objects, follows pagination and records a resumable cursor. Account for throttling and deletions. Replaying the last page after a timeout should update the same document versions instead of duplicating them in the index.
Cloud connectors page through results and remember where they stopped with a cursor. The dangerous gap is between writing records and saving the cursor: a crash there means the same page arrives again. If writes are inserts, you get duplicates; if they are upserts keyed on source ID and revision, the replay changes nothing. Also handle rate-limit responses with backoff and make sure the API's delete events (or a periodic full listing) reach the index.
Example. Fail a connector after it stores page three but before it saves the cursor. A replay of page three must not create duplicate document revisions.
Another example. A shared-drive connector is throttled halfway through 10,000 files. After backoff it resumes from the last saved cursor and re-sends 200 files it had already written. The index still holds one revision of each.
A timeout between write and checkpoint
Upserts keyed on ID and revision make the replay harmless. - Integration Loaders
- An integration loader often needs to reconstruct context across linked records, such as a parent ticket and its replies. Preserve relationships and authorization metadata when flattening them for search. A reply accessible in one workspace must not become searchable by everyone merely because it shares a connector.
Tickets, chat threads and CRM records are graphs: a parent with children, each with its own visibility. Flattening a thread into one chunk is convenient for search but merges permissions, so the most restrictive child decides who may see the whole chunk, or you split children into separate chunks that link to the parent. Always test search as at least two users with different scopes.
Example. A ticket is public to one team but its internal reply is restricted. Test search as both an authorized reader and a reader outside that scope.
Who can find the internal reply?
How it works
Step through the idea, or press Play.
Document event. handbook-12 · revision 9
Understand it
Worked example
A deleted handbook survives a connector retry
- 1
handbook-12 · revision 9
The connector reads versioned records with access metadata and a checkpoint. A later delete is a real update that downstream systems must receive.
- 2
Stable ID plus revision
Normalize text without losing page references, access rules or deletion state. Replay the cursor using idempotent writes after a timeout.
- 3
Revision 9 retired
Remove or tombstone all entries for the deleted revision. Verify absence under ordinary user permissions instead of assuming the connector’s success proves cleanup.
Follow the handoffs
The life of handbook-12 in the index
Checking the retry outcome
| Check | Correct result | Bug signal |
|---|---|---|
| Revisions of handbook-12 | 1 effective | 2 identical revisions |
| Chunks after delete | 0 searchable | Old chunks still returned |
| Search as ordinary user | No hit | Hit on deleted text |
Summary
The whole topic in one minute.
A replay is a delivery event. Stable identities should prevent duplicate content and allow the delete to retire every corresponding chunk.
A corpus that is accurate on day one can drift after access changes or source deletions. Exercise update, retry and removal paths and check the resulting visible evidence under the same permissions as a real user.