← All questions
LLMOps & ProductionMedium· Production & Optimization

How do you handle document updates in a production RAG...

When a source document changes, the index needs two things to happen together: the old chunks tied to that document need to come out, and freshly generated chunks need to go in. Skip either half and you either serve stale content indefinitely or accumulate duplicate, contradictory chunks for the same underlying document.

The clean way to wire this is event-driven rather than on a manual or purely scheduled basis: a file-change event in storage triggers a pipeline that re-parses the document, re-chunks it with the same strategy used during original indexing (so retrieval behavior stays consistent), re-embeds, and then deletes every chunk tagged with that document’s ID before inserting the new ones. A document registry tracking a content hash per document lets the pipeline skip re-indexing entirely when nothing actually changed, which matters at scale since re-embedding unchanged documents is pure waste.

Worth adding on top: freshness as its own piece of metadata, so time-sensitive queries can be biased toward newer documents, and an alert when a document that’s expected to update regularly (say, monthly pricing) hasn’t been touched in far longer than expected — that’s usually a pipeline failure, not a stable document.

Code playground (Python)