Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

Documents in your RAG system are updated and deleted daily, and users get answers from outdated versions. How would you design incremental ingestion so the vector store stays in sync with the source?

Every chunk carries a stable document id and a version or content hash in its metadata. When the source tells us a document changed, we delete its old chunks with vectorStore.delete and a filter on the document id, then insert the new chunks; when it tells us a document was deleted, we delete its chunks too. Changes are detected from events, timestamps or hashes instead of nightly full re-ingestion, the job is idempotent and reports added, updated and deleted counts and lag, and answers show the source and its date so users can spot old information.

Why this question is asked

A RAG system is only as current as its index. If a pricing policy changed on Tuesday but the vector store still holds Monday's chunks, the assistant will confidently quote the old prices, and it will keep quoting a withdrawn document forever if nobody removes it. Interviewers ask this question because it is the step that demo projects skip and production systems cannot. In this answer, we will see why answers go stale, give chunks a stable identity, detect changes, handle updates and deletions, make the job idempotent and observable, and show dates to users.

1Why Answers Go Stale

A typical first version ingests everything once and then appends new documents. When a document is edited, the new version is added, but the old chunks are still there, so a search returns a mix of both. When a document is deleted in the source system, nothing happens in the vector store at all. The vector store has no idea which rows belong to which source document, so it cannot clean up.

So the fix starts with identity: we need to be able to say these 14 chunks are document HR-221, version 7.

2Give Every Chunk a Stable Identity

When we ingest, we put the source system's document id, the version or last modified time, and a hash of the content in each chunk's metadata. We can also derive the chunk ids from the document id and the chunk position, so ingesting the same version twice produces the same ids instead of duplicates.

Java
String docId = "HR-221";
String hash = sha256(sourceText); // "9f2c..."
List<Document> chunks = splitter.apply(List.of(new Document(sourceText))).stream()
.map(c -> new Document(
UUID.nameUUIDFromBytes((docId + ":" + hash + ":" + c.getText()).getBytes(UTF_8)).toString(),
c.getText(),
Map.of("doc_id", docId, "version", 7, "content_hash", hash,
"source", "hr-portal", "updated_at", "2026-11-03")))
.toList();
// 14 chunks, each with doc_id=HR-221, version=7

Notice that the id is a deterministic UUID. Many vector stores, PgVectorStore among them, expect ids in UUID form, so we derive one from our own key instead of inventing a format.

3Detect Changes Instead of Re-Ingesting Everything

Re-ingesting all documents every night is simple, but it is slow and expensive (every chunk is embedded again) and it still leaves answers up to a day old. It is better to ask the source what changed. The best option is change events: the document management system publishes document updated and document deleted events, for example to Kafka or a webhook, and we process them within seconds. If events are not available, we poll with a modification timestamp: every 10 minutes, fetch documents with updated_at after the last run. As a safety net, a weekly reconciliation compares the list of ids and hashes in the source with those in the store and fixes any drift.

4Applying an Update

For an updated document, we compare the new content hash with the stored one. If it is the same, there is nothing to do. If it differs, we delete all chunks with that document id and insert the new chunks. Deleting by filter means we do not need to know how many chunks the old version had, which matters because the new version may split into a different number of chunks.

Java
void upsert(SourceDoc doc) {
String hash = sha256(doc.text());
if (hash.equals(index.storedHash(doc.id()))) {
metrics.counter("ingest", "result", "unchanged").increment();
return; // same content, nothing to embed
}
vectorStore.delete("doc_id == '" + doc.id() + "'"); // removes the 14 old chunks
vectorStore.add(toChunks(doc, hash)); // inserts 16 new chunks
index.saveHash(doc.id(), hash);
metrics.counter("ingest", "result", "updated").increment();
}
Step throughOne document update
Source systemIngestion jobEmbedding modelVector store
event: HR-221 updated
fetch content
text of version 8
hash differs from stored
delete where doc_id == HR-221
embed 16 new chunks
16 vectors
add 16 chunks

8 messages in order. Play them, or step through them one at a time.

There is a short moment between the delete and the add when the document has no chunks. For most systems that is fine. If it is not, we write the new chunks first with the new version, then delete chunks whose doc_id matches and whose version is older, so there is always one complete version present. Also check that your vector store supports deletion by filter expression, since support differs between stores.

5Handling Deletions Explicitly

Deletions are the case that most often goes wrong, because a deleted document simply stops appearing in the source and nothing tells us. Orphaned chunks then keep being retrieved for months. So the source must give us a tombstone, a record that says this id was deleted, either as a delete event or as a deleted flag we can query. The job reacts by deleting all chunks with that doc_id. The weekly reconciliation catches any tombstone we missed by listing ids that exist in the store but not in the source.

Java
void delete(String docId) {
vectorStore.delete("doc_id == '" + docId + "'"); // removes every chunk of the document
index.removeHash(docId);
metrics.counter("ingest", "result", "deleted").increment();
}

6Idempotent, Observable and Visible to Users

Events can arrive twice or out of order, and jobs can crash halfway. Because updates compare hashes and use deterministic ids, processing the same event twice gives the same result, which is what idempotent means. Out-of-order events are handled by ignoring an event whose version is older than the one stored. Failures go to a retry queue with backoff, and after a few attempts to a dead-letter list someone looks at.

We publish counts of added, updated, unchanged and deleted documents per run, the number of failures, and the lag: how far the newest change in the store is behind the newest change in the source. An alert on lag above, say, 30 minutes tells us the pipeline is stuck before users notice.

Finally, we help users judge freshness. Each answer lists its sources with the document title and last updated date from metadata, such as HR travel policy, updated 3 November 2026. A user who sees a date from 2023 knows to double-check.

7Follow-up questions

How would you re-embed everything when the embedding model changes?

Treat it as a migration, not an update. Vectors from different models cannot be mixed, so we build a new index or table, run a full ingestion of all documents into it with the new model as a rate-limited batch, keep the incremental pipeline writing to both indexes during the migration, evaluate retrieval quality on a labelled query set, then switch reads to the new index and keep the old one for a while for rollback.

Why not just store the version and filter searches to the latest?

It works, but old chunks still take space, cost index memory and can leak back if the filter is forgotten. Deleting old versions keeps the store small and the query simple.

What if the source system has no change events?

Poll by modification timestamp, and run a periodic reconciliation by id and hash to catch deletions and missed changes.

8Conclusion

In this answer, we saw that stale answers come from chunks without identity. We gave every chunk a stable document id, version and content hash, detected changes through events or timestamps, replaced a changed document by deleting its chunks with a filter and inserting the new ones, and removed deleted documents through explicit tombstones. An idempotent job with counts, lag and retries keeps the pipeline trustworthy, and showing sources with dates lets users spot outdated information.

What to say in the interviewAbout 80 seconds aloud

Open with

The root cause is usually that chunks have no link back to their source document, so updates add new chunks next to old ones and deletions do nothing.

Then, if they want more

I would give every chunk a stable doc_id, a version and a content hash in metadata, with deterministic chunk ids. Then I detect changes from the source, ideally through change events, otherwise by polling a modification timestamp, instead of re-ingesting everything nightly.

For an update, if the hash differs, I call vectorStore.delete with a filter on doc_id and add the new chunks, or write the new version first and delete older versions if there must be no gap.

Deletions need explicit tombstones from the source, a delete event or a deleted flag, and then I delete all chunks for that id; a weekly reconciliation by id and hash catches anything missed. The job must be idempotent, so duplicate or out-of-order events are safe, with retries and a dead-letter list.

I publish counts of added, updated and deleted documents, failures and lag behind the source, with an alert on lag. And I show the source and its last updated date in every answer so users can judge freshness.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring AI reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Documents in your RAG system are updated and deleted daily, and users get answers from...": https://scrivio-interview-library.netlify.app/spring-boot/spring-ai/6eb0181e50/