Topic 2 of 4 · 4 min read
Deleting documents and honouring erasure requests
Goal: Trace a deleted source document through the index and write the steps that remove all of its chunks and cached answers.
A deleted document is only gone when every chunk, vector, cached answer and backup copy derived from it is gone, and the job that removes them is as deliberate as the one that adds them.
Check yourself · 1 of 3
A source document is deleted but the assistant still quotes it. What is the most likely cause?
Why it matters
Sources lose documents all the time: a policy is withdrawn, a customer leaves, a contract is terminated. If the index still holds the chunks, the assistant keeps quoting them. For personal data the stakes are legal: under Article 17 of the GDPR a person can ask for erasure, and the controller must act without undue delay. A search index is not exempt just because it is a copy.
How to do it
- Detect the deletion. Compare the source listing with the manifest. An id that is in the manifest but missing from the source is a deletion. Also listen to delete webhooks, and treat a "trashed" or "archived" flag as a delete.
- Delete by document id, not by guess. Every chunk carries
doc_idin its metadata, so one filtered delete removes them all. Most vector stores support delete by id, by id prefix or by metadata filter, but some only on certain index types, so test it. - Cover every copy. The vector store, a keyword index, a chunk text cache, a reranker cache, stored answers, evaluation sets and logs that hold the text.
- Leave a tombstone. Record
doc_id, deleted time and reason in a small table. If the source later reappears or an old queue message replays, the tombstone stops the document being re-indexed. - Verify. Query for a distinctive phrase from the document and confirm zero hits. Run this check as part of the delete job, and log the result.
- Plan for backups. Index snapshots restore deleted data. Record when snapshots expire, and re-apply the tombstone list after any restore.
Before and after
# Before: soft delete in the source only; index never told
db.documents.update(doc_id, status="withdrawn")
# After: propagate to every derived copy
index.delete(filter={"doc_id": doc_id})
chunk_cache.delete_prefix(f"{doc_id}:")
answer_cache.delete_where(cites=doc_id)
tombstones.insert(doc_id=doc_id, at=now(), reason="erasure-request")
assert not index.search(probe_phrase, top_k=5)
What goes wrong
- Delete the vectors, forget the cache. The model keeps answering from a cached response that quotes the document.
- Eventual consistency. Some stores apply deletes after a delay, so a check run immediately can pass and then fail. Re-check later.
- No chunk-to-document link. If chunks were stored without
doc_id, you cannot find them, and you must rebuild. - Replay after delete. A retried message re-adds the document because nothing remembers it was deleted.
Examples
The cached answer that kept quoting a withdrawn policy
HR withdrew a leave policy and the vector chunks were deleted. Staff still got the old rules, because an answer cache keyed by question held the old response. The fix was to tag cached answers with the document ids they cite, and delete by that tag on every document delete.
An erasure request as a runbook
- Find all documents containing the person's data (search plus source lookup).
- Delete them in the source.
- Delete chunks by
doc_idin the index, caches and logs. - Add tombstones.
- Run the probe search and save the result.
- Note the backup expiry date in the request record.
Key points
- A deletion in the source must be detected and propagated: the index never finds out on its own.
- Store doc_id on every chunk so one filtered delete can remove them all.
- Remove every derived copy: vectors, keyword index, chunk and answer caches, evaluation sets and logs.
- A tombstone record stops a deleted document being re-indexed by a replayed message or a restored backup.
- Verify by searching for a distinctive phrase and expecting zero hits, then check again after any delay.
Common mistakes
- Deleting the source document and assuming the index follows.
- Removing vectors but leaving cached answers, logs or evaluation sets that quote the text.
- Storing chunks without a document id, so they cannot be found for deletion.
- Treating a successful delete call as proof, with no search to confirm.
Check yourself · 2 of 3
What makes it possible to remove all chunks of one document with a single delete call?
Check yourself · 3 of 3
Why keep a tombstone record after deleting a document?
Practice items, not counted towards your mastery.
Start here
- Ingestion pipeline (LlamaIndex docs) (opens in a new tab)DocsFree
Shows a document store that hashes documents so unchanged ones are skipped on re-runs.
- Delete records (Pinecone docs) (opens in a new tab)DocsFree
Delete by id, by id prefix or by metadata filter, and what a delete does and does not remove.
- Art. 17 GDPR: Right to erasure (opens in a new tab)StandardFree
The legal text behind erasure requests: when data must be erased and the stated exceptions.
More for this topic
- Change and deletion detection in blob indexing (Azure AI Search) (opens in a new tab)DocsFree
A managed indexer's approach to change tracking and soft-delete markers for removed source files.