---
title: "Keep the index as fresh as its sources · Agent Wranglers"
url: https://agentwranglers.se/playbook/ai-features/retrieval/index-freshness
updated: 2026-10-20
licence: "All rights reserved"
---

# Keep the index as fresh as its sources

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Retrieval](https://agentwranglers.se/playbook/ai-features/retrieval)
- Rule: Update or remove a document's chunks within a set time after the source changes, such as 15 minutes. Show the source date with every answer.
- How: Index on change events from the source, not only in a nightly job. Delete chunks by document ID when a document is deleted or unpublished. Store the source's last-modified time with each chunk and show it with the citation. Run a full rebuild on a schedule to catch missed events. The general method is in [keep search indexes in step](https://agentwranglers.se/playbook/data/caches-and-copies/search-index-sync).
- Check: Delete a test document at the source. Within the set time, a search for its unique phrase returns nothing. A nightly job compares document IDs in the source and the index and alerts on any difference.

Example:

```sql
SELECT c.document_id FROM chunks c LEFT JOIN documents d ON d.id = c.document_id
WHERE d.id IS NULL OR (c.source_updated_at < d.updated_at AND d.updated_at < now() - interval '15 minutes');
-- PASS when no rows are returned
```

```ts
documents.on('deleted', async ({ id }) => vectorIndex.deleteWhere({ documentId: id }));
```

```python
@documents.on("deleted")
def remove_from_index(event: DocumentDeleted) -> None:
    vector_index.delete_where(document_id=event.id)
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers ai features playbook: https://agentwranglers.se/playbook/ai-features/retrieval/index-freshness`.

- Previous: [Say so when nothing relevant was found](https://agentwranglers.se/playbook/ai-features/retrieval/no-match-answer)
- Next: [Copy access rights into the index and check them again](https://agentwranglers.se/playbook/ai-features/retrieval/retrieval-permissions)
- [Retrieval](https://agentwranglers.se/playbook/ai-features/retrieval)
