When a page is removed from a documentation site and the crawl lists only pages that exist, how does a RAG index find and remove its chunks?
answer
- absence is the only signal
- what you indexed minus what you saw
- only diff a complete listing
- a mass-delete brake
- registry row goes last
basics
~20 sKeep a per-source registry of indexed documents; after a complete listing, documents in the registry but not the listing were removed, so delete each one's whole chunk set. Never diff a partial listing, and hold any run deleting an unusual share.
solid answer
~50 sA job that processes only what the listing returns never mentions the removed page, so nothing deletes it. The pipeline needs its own memory: a registry of document IDs per source, with the chunk IDs each one owns. After the listing finishes, `gone = registry_ids - listed_ids`, and for each gone document you delete its chunk set by ID (or by a `doc_id` filter where the store supports one), then remove its registry row. The dangerous case is a listing that silently came back short: an expired credential, a throttled page, a pagination bug. Diffing that deletes half the index. So diff only a listing that paged to the end without errors, scope the diff to one source, and stop and alert when the deletions exceed a set share of the source. Direct delete events from a source are faster where they exist; the diff is the backstop that catches what they miss.
go deeper
Recall that a job driven by a listing never sees a removed page, so something must remember what was indexed before.
Explain the registry, the set difference per source, deleting each document's whole chunk set by ID, and removing the registry row last.
Show the guards: complete listings only, per-source scope, a mass-delete brake, error versus not-found, and immediate hiding for urgent removals.
Set the deletion policy for every source: brake thresholds, grace periods, and how fast a removal must stop appearing in answers.
## Why deletes are invisible to a listing-driven job A retrieval-augmented generation (RAG) index fed by a nightly job usually works from a **listing**: the source, here a product-documentation site, reports the pages that exist, and the job processes each one. When a page is removed, it is simply absent from tonight's listing. A job that loops over the listing never encounters it, so it never issues a delete, and every chunk of the removed page stays retrievable. The assistant keeps quoting a page that no longer exists, with a citation link that now returns "not found". Absence is the only signal, and absence can only be noticed by something that remembers what was there before. ## The deletion diff The pipeline keeps a **document registry**: a table keyed by document ID, recording for each document its source, the chunk IDs it owns and the last run that saw it. The diff is a set difference: 1. List the source completely. 2. `seen` = document IDs in tonight's listing for this source. 3. `known` = document IDs the registry holds for this source. 4. `gone = known - seen`. 5. For each gone document, delete its chunk set, then delete its registry row. The registry row goes last for the same reason as everywhere else in re-indexing: it is the only record of what the document owned. If the row is removed before the chunk delete succeeds, a failed delete leaves chunks no future run can find. A variant that suits incremental processing is **mark and sweep**: every listed document gets `last_seen_run = tonight`, and after a complete listing every document whose `last_seen_run` is older is swept. ```pseudocode listing = source.list_all(source_id) # pages to the end if not listing.complete: skip deletes for source_id this run; alert # adds and updates may proceed stop gone = registry.doc_ids(source_id) - set(listing.doc_ids) if size(gone) > max(20, 0.05 * registry.count(source_id)): # illustrative brake hold gone for review; alert stop for each doc_id in gone: store.delete(registry.chunk_ids(doc_id)) # by ID: works on every store registry.remove(doc_id) # only after the delete succeeded ``` ## The failure that makes this dangerous The diff turns "missing from the listing" into "delete". A listing can be missing pages for reasons that have nothing to do with deletion: - an **expired or revoked credential** that makes the source return an empty or partial result without an error; - **throttling** partway through paging, with the client treating the last page it got as the end; - a **pagination bug**, or a listing that silently caps its results; - a **permission change on the crawler's account** that hides a whole section; - a source that is **down** and returns a valid-looking empty list. Each of these, diffed naively, deletes a large part of the index in one night, and the next run has to re-embed it all. The guards: | Guard | What it prevents | |---|---| | Diff only a listing that paged to the end with no errors | Deleting from a truncated listing | | Scope the diff per source (and per tenant) | One failing source deleting another's documents | | Mass-delete brake (count or share of the source) | A silent empty listing wiping the source | | Treat "forbidden" or "error" differently from "not found" | Deleting pages the crawler simply could not read | | Optional grace: soft-delete first, hard-delete on a second complete miss | Brief removals and one-off glitches | The grace period has a cost. A **soft delete** should hide the document immediately (a `deleted` flag in the registry, checked on the read path) even if the chunks are only removed later, because a page taken down for being wrong or confidential should stop appearing in answers at once. ## Where the diff sits next to direct delete signals Many sources can also report deletions directly, through a change feed or a webhook, and those are faster. They are also lossy: an event can be dropped, and a feed that falls too far behind can force a full re-crawl. The diff over a complete listing is the **backstop** that catches whatever the direct signals missed, which is why it usually runs even when a feed exists. Reading those feeds and recovering a connector after missed events is connector work; how quickly deletes overtake other queued writes is a freshness concern; and how long a vector store keeps returning a chunk after acknowledging its delete is the store's write-visibility subject. The diff's job is to issue the right deletes, for the right documents, and only when it can trust its input.
- The removed page was confidential. Is waiting for the nightly diff acceptable?No. Use a direct delete signal from the source where one exists, and give deletes priority over queued edits. Hide the document at once with a registry flag checked at read time, then remove its chunks. The diff remains the backstop for deletes the direct path missed.
- How do you choose the mass-delete threshold?From the source's normal churn: measure how many documents a source loses on a typical night and set the brake well above that, with a floor for small sources. A run over the brake is held for a human, not dropped, so a real large removal is still applied after a check.
- A crawl that re-indexes every listed page removes deleted ones too.
- An empty listing means the source was emptied; delete everything.
- Without a registry, the diff can be computed from the listing alone.
- Remove the registry row first, then delete the chunks.
- Once deletes arrive by webhook, the listing diff can be retired.