# How Do You Keep the Index Fresh?

> How to keep an AI search index of your documents up to date: re-index only what changed, remove what was deleted and rebuild safely, for your AI interview.

**In short:** You re-index only what changed: new and edited documents are embedded again, and deleted ones are removed. Sync on a schedule or when files change, and when the embedding model changes, rebuild the whole index beside the old one.

AI and LLM interview question Q139, Retrieval-augmented generation (RAG). Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-keep-the-index-fresh

## Say it in 30 seconds

An index goes stale when the files behind it change and the index doesn't. So I don't rebuild everything each time. A sync job compares each file with the last run, re-embeds the new and edited ones, and removes the deleted ones. It runs on a timer, or straight away when a file changes. When the embedding model changes, I build a second index beside the old one, test it on fixed questions, and switch only when it passes. That way customers never get half-updated answers.

## Say it in 2 minutes

A RAG bot answers from a copy of your documents, so the copy has to keep up with the originals. Think of a new hire who copies the leave policy into a cheat sheet on day one. When HR changes the rules, the sheet is wrong until someone updates it, and the hire keeps quoting the old rule with confidence.

The fix is incremental sync. The job keeps a record of each file's last version, usually a timestamp or a fingerprint of its text. Each run compares today's files with that record, re-embeds only the new and edited ones, and removes the deleted ones. Take a mid-size insurer with 18,000 documents and about 150 edits a week. A full rebuild takes most of a night, and the incremental run takes minutes.

Removing deleted files is easy to skip. If a withdrawn policy stays in the index, the bot quotes it with confidence. I also test the job, not only the answers: after each sync, a changed rule must return its new figure, and a deleted one must return nothing. When the embedding model changes, old and new vectors don't mix, so I build a second index, compare answers on a fixed test set, and switch only when it passes.

I'd be honest about the limit. A timer-based sync can lag behind the source by its whole interval, so for rules that change often I'd trigger the sync on each change and show the document date next to each answer.

## What does keeping the index fresh mean, in plain words?

RAG, short for retrieval-augmented generation, means the bot looks up passages from your documents before it answers. Those passages come from an index: a searchable store where each piece of text is kept as an embedding, a list of numbers that stands for its meaning.

Think of a new hire who copies the leave policy into a cheat sheet on day one. When HR changes the rules, the sheet is wrong until someone updates it, and the hire keeps quoting the old rule with confidence. An index behaves the same way. A made-up case: a mid-size insurer's claims assistant quoted last year's deductible (the amount the customer pays first) because the new rule sat in a PDF nobody re-indexed. Keeping the index fresh means keeping that copy in step with the source, without rebuilding everything each time.

- **Index:** The searchable store the bot looks in, built from your documents.
- **Embedding:** A list of numbers, also called a vector, that stands for the meaning of a piece of text.
- **Chunk:** A short piece of a document, the unit that gets embedded and stored.
- **Sync:** A job that brings the index in line with the source files.
- **Stale:** Out of date: the index no longer matches the files it came from.

## How do you find what changed?

Each stored file gets a record of its last version. That is usually a last-modified timestamp from the file store, or a fingerprint, a short code made from the text, so any edit changes it. Each sync run compares today's files with those records and sorts them into four groups: new, edited, deleted and unchanged.

> "Syncing is incremental, so Amazon Bedrock only processes added, modified, or deleted documents since the last sync." (Amazon Bedrock docs)
>
> "It detects new and updated files and metadata through built-in change detection." (Microsoft Learn, blob indexing)

*Diagram, One sync run: One sync run: the job reads today's files, works out what changed, re-embeds only the new and edited ones, and drops the deleted ones. Unchanged files are left alone, so the run stays quick.*
1. The job reads the file list as it is today.
2. New, edited and deleted files go on to the work step. Unchanged files are skipped.
3. Fresh vectors are written, and deleted files are removed from the index.
4. The bot searches the updated index and quotes the new rule.

Worked example, with made-up numbers: the insurer keeps 18,000 documents, and about 150 change in a week. A full rebuild re-embeds all 18,000 and takes most of a night. The incremental run touches only the 150 and finishes in minutes, and the bot is current by the morning. Here is the decision in a small Python sample, with made-up file names from a bank.

```python
# A simplified sync job. Each file has a version tag that changes when its text changes.
# Compare today's tags with the last run, and touch only what differs.
last_run = {"card-fees-2026.md": "rev3", "leave-policy.md": "rev7", "dispute-process.md": "rev2", "branch-hours-old.md": "rev1"}
today = {"card-fees-2026.md": "rev4", "leave-policy.md": "rev7", "dispute-process.md": "rev2", "chargeback-faq.md": "rev1"}

new = [f for f in today if f not in last_run]
changed = [f for f in today if f in last_run and today[f] != last_run[f]]
removed = [f for f in last_run if f not in today]
skipped = [f for f in today if f in last_run and today[f] == last_run[f]]

print("Re-index (new):", ", ".join(new) or "none")
print("Re-index (changed):", ", ".join(changed) or "none")
print("Remove from index:", ", ".join(removed) or "none")
print("Skip, no change:", ", ".join(skipped) or "none")
```

Output:

```text
Re-index (new): chargeback-faq.md
Re-index (changed): card-fees-2026.md
Remove from index: branch-hours-old.md
Skip, no change: leave-policy.md, dispute-process.md
```

## How often should the index refresh?

- **Scheduled: A timer, hourly or nightly.** Simple and cheap to run. Answers can lag behind the source by up to one full interval.
- **Event-driven: A change starts the sync.** A file save triggers the job, so answers catch up soon after the change. More moving parts to run and watch.
- **On demand: A person or job asks for it.** Good for a one-off large load or a source that rarely changes. Easy to forget, so pair it with a timer.

> "To maintain current information for retrieval, asynchronously update the documents and update embedding representation of the documents." (AWS, what is RAG)
>
> "You can do this through automated real-time processes or periodic batch processing." (AWS, what is RAG)

Microsoft's indexer for blob storage (cloud file storage) offers two refresh options: on a schedule or on demand. Match the speed to the harm of a wrong answer. A fee rule can wait an hour. A fraud rule or a safety instruction may need a change-triggered sync.

> **Tip:** Asked how often? Don't say real time by default. Ask how long a wrong answer can stay live, then set the sync speed to match.

## What about deleted files and a new embedding model?

Deletions are the step people forget. If a withdrawn policy stays in the index, the bot quotes it with confidence. Amazon Bedrock removes a deleted document from its vector store (the database that holds the embeddings) on the next sync. Azure's indexer can spot deletions through native soft delete (the file is marked deleted rather than erased) or a custom metadata field (an extra label on each file), so check which one your tool uses. A new embedding model is the big change. Old and new vectors don't mix, so the whole index has to be rebuilt with the new model. Build it beside the live one, test it, then switch. Keep the old index for a few days so you can roll back.

*Diagram, Swapping to a new embedding model: Changing the embedding model without downtime: the live index keeps serving while the new one is built and tested. The switch happens only after the checks pass, and the old index stays ready to roll back.*
1. Every chunk is copied and embedded again with the new model.
2. The new index is tested on the same questions before anyone uses it.
3. Once it passes, the app points at the new index, and the old one stays ready for a rollback.

### How would you stop an old policy answer reaching customers?

A customer asks about the deductible on a policy that changed on Monday. The sync ran on Tuesday, but the bot still quotes the old figure. Here is how I would stop that.

1. **Stamp each chunk with its date:** Store the source file's version and date with every chunk, so each answer can show which rule it came from.
2. **Alert on lag:** If a source changed but the index did not sync within its window, the owner gets a message. A sync that fails quietly is the one to watch for.
3. **Test the changed rules:** Keep test questions for each policy. After every sync, the new figure must appear and the old one must not.
4. **Show the date to the customer:** Put the source date in the reply, so a stale answer is visible to the customer and to the team.

Customers ask in plain words, so the test set does too. A typical question is "What is my excess on the new policy?" and the answer must carry the new figure.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] The index is a copy of the source, so it goes stale.
- [ ] Sync only what changed: detect it, re-embed it, and remove deletions.
- [ ] Pick the refresh timing by how harmful a wrong answer is.
- [ ] Deletions need their own handling, or withdrawn text keeps answering.
- [ ] A new embedding model means a full rebuild beside the old index, then a switch.
- [ ] Test with fixed questions after every sync.

**Common traps**

- Trap: "Just rebuild the whole index every night." Better: Fine when the document set is small. At scale it's slow and costly, so re-embed only what changed, and rebuild in full only for a new model.
- Trap: "Real time is always the best choice." Better: Real-time sync adds moving parts and cost. Match the speed to how fast a wrong answer causes harm.
- Trap: "Adding new documents is enough." Better: Edited and deleted files need handling too, or old and withdrawn text keeps being quoted.

## Can you spot the stale index?

**Spot the gap:** Your bot runs a nightly sync. Which setup can still serve a withdrawn policy the next morning?

A. The sync re-embeds new and edited files, but has no step for deleted ones.
B. The sync removes files that no longer exist in the source.
C. Each chunk stores its source date and version.
D. Fixed test questions run after every sync.

**Answer:** A. A deleted file stays in the index unless the job removes it, so the bot keeps quoting it. Add a deletion step, and a test that asks about the withdrawn text.

**Quick check:** An insurer changes its embedding model. What is the safest way to switch?

A. Re-embed only the new documents and keep the old vectors.
B. Build a second index with the new model, test it on fixed questions, then switch.
C. Change the model name in the config and let the next sync fix the old vectors.
D. Stop syncing until the next release.

**Answer:** B. Old and new vectors don't mix, so the whole index has to be built with the new model. Building beside the old one lets you test it and roll back if needed.

## Can you answer these from memory?

**Flash cards**

- **What is a stale index?** One that no longer matches its source files, so answers use old text.
- **Cheapest refresh that works?** Incremental sync: re-embed only the added, changed or deleted files.
- **Why sync deletions?** Otherwise withdrawn text keeps being quoted by the bot.
- **New embedding model?** Build a second index beside the old one, test it, then switch.
- **Scheduled or event-driven?** A timer for slow sources; a change trigger for fast-moving rules.
- **What to check after a sync?** Fixed test questions: changed answers show new text, deleted ones nothing.

## Likely follow-up questions

- Q133 What are common RAG failure modes? https://designervenkat.online/interview/ai/common-rag-failure-modes
- Q140 How do you enforce access control in RAG? https://designervenkat.online/interview/ai/how-do-you-enforce-access-control-in-rag
- Q145 How do you cache RAG results? (full answer coming)
- Q150 How would you design RAG for 10 million documents? https://designervenkat.online/interview/ai/how-would-you-design-rag-for-10-million-documents
- Q155 Build a minimal RAG pipeline. https://designervenkat.online/interview/ai/build-a-minimal-rag-pipeline
- Q281 Fine-tune vs RAG vs prompting: when to use which? https://designervenkat.online/interview/ai/fine-tuning-vs-rag-vs-prompting
