Keeping a retrieval-augmented generation (RAG) application accurate requires more than adding new documents. This maintenance runbook explains how to detect changed and deleted source content, update vector records without creating stale chunks, recover from failed ingestion jobs, and rebuild an index safely when incremental synchronization is no longer enough.
Overview
A RAG index is a derived copy of a source collection. Documents are fetched, split into chunks, converted into embeddings, and stored with metadata that allows the application to retrieve relevant context. Because the index is derived, it can become incorrect even when the vector database itself is healthy.
Typical freshness problems include a policy document being revised while its old chunks remain searchable, a deleted page continuing to appear in answers, or a failed ingestion run updating only half of a document set. The language model may then produce a fluent answer from information that the source system no longer considers valid.
The safest maintenance design treats every indexed document as a versioned unit. Keep a manifest outside the vector store, or in a metadata collection, with at least these fields:
- source_id: A stable identifier from the source system, not a title or URL that may change.
- content_hash: A hash of the normalized document content used to decide whether reprocessing is necessary.
- modified_at: The source modification timestamp, when one is available.
- index_version: The ingestion, chunking, embedding, and metadata configuration used for the indexed version.
- deletion_status: A state such as active, missing, pending_delete, or deleted.
- sync_run_id: The job that last created, updated, or removed the document's records.
Use a deterministic chunk identifier such as source_id + content_hash + chunk_number, or another scheme that remains unique and traceable. Every vector record should also carry the source ID, document version, chunk number, and index version. This makes it possible to remove all chunks belonging to one document without relying on an approximate text search.
Maintenance cycle
1. Create a source snapshot
Start each synchronization with a defined source snapshot. The snapshot may come from an API response, a database query, a file listing, or a crawl manifest. Record the time the snapshot began and the source IDs it contains. Do not compare the current index only with documents that happened to download successfully; a temporary source error can otherwise look like a deletion.
For each source item, normalize the content consistently before hashing. Decide how to treat whitespace, line endings, generated timestamps, navigation text, and other fields that do not affect meaning. If normalization changes between runs, the system may re-embed every document even when the visible content is unchanged.
2. Classify every document
Compare the source snapshot with the manifest and assign a state before writing to the vector database.
| State | Condition | Action |
|---|---|---|
| New | The source ID is absent from the manifest. | Chunk, embed, and insert the document. |
| Unchanged | The content hash and relevant configuration match. | Skip embedding and retain the existing records. |
| Changed | The hash, source version, or processing configuration differs. | Write the new version, then remove the old version. |
| Missing | The source ID is absent from a trusted complete snapshot. | Mark it pending deletion and verify before removing records. |
| Deleted | The source system confirms that the item no longer exists. | Delete all vector records for the source ID and update the manifest. |
The distinction between missing and deleted matters. A partial crawl, permission error, rate limit, or connector outage can make active documents appear absent. Require a complete snapshot or an explicit deletion event before propagating a deletion.
3. Upsert changed documents safely
For a changed document, generate the complete new chunk set rather than updating only chunks whose text appears different. Changes in heading structure, chunk boundaries, or tokenization can shift every subsequent chunk. A complete replacement is easier to reason about and prevents orphaned chunks.
A provider-neutral workflow looks like this:
- Read and normalize the source document.
- Calculate its content hash and assign a new document version.
- Split the complete document using the current chunking configuration.
- Generate embeddings for the new chunks.
- Write the new vectors with source ID, document version, and sync run ID.
- Verify the expected count and metadata for the new version.
- Delete the previous version using an exact metadata filter.
- Mark the manifest as active only after verification succeeds.
There are two common replacement strategies. In an in-place strategy, new vectors use the same logical IDs and overwrite old records. This is efficient but depends on deterministic IDs and reliable upsert behavior. In a versioned strategy, new records are written under a new version first, then the old version is deleted. Versioned replacement usually provides a clearer recovery path because the old records remain available until the new set passes checks.
4. Propagate deletions
Delete by stable source metadata, not by document title, URL formatting, or a similarity query. A deletion filter should target the exact source ID and, where relevant, a tenant or collection boundary. For example, the logical operation is:
delete where tenant_id = T and source_id = SAfter deletion, query the same filter and confirm that no records remain. Also update the manifest so the next synchronization does not recreate the content from stale local state. If the application uses cached retrieval results, invalidate or expire those results as part of the deletion workflow.
5. Record an auditable sync result
Each run should produce counts for discovered, unchanged, inserted, replaced, deleted, skipped, and failed documents. Store the run ID, source snapshot identifier, index version, start and end times, and error details. These records support incident review and make it possible to retry only failed documents instead of repeating the entire job.
Signals that require updates
RAG index maintenance should respond to both source changes and system changes. The following signals are useful triggers:
- Source events: A document is created, edited, moved, unpublished, or deleted.
- Scheduled freshness checks: A periodic comparison finds an unexpected hash or modification timestamp difference.
- Connector failures: Authentication errors, incomplete pagination, timeouts, or permission changes prevent a complete snapshot.
- Retrieval feedback: Users report outdated answers, missing sections, duplicate passages, or content that should no longer be visible.
- Pipeline changes: Chunk size, overlap, parsing rules, metadata fields, embedding model, or embedding dimensions change.
- Application changes: Tenant filters, access-control rules, namespaces, or retrieval ranking logic change.
- Quality monitoring: Retrieval evaluations show lower recall, more irrelevant context, or an increase in answers based on superseded versions.
Not every signal requires a full rebuild. A single edited document normally needs an incremental replacement. A changed parser may require reprocessing a document type or collection. A change to the embedding representation generally calls for a separate index and a staged migration.
Keep retrieval monitoring alongside ingestion monitoring. A dashboard that tracks only job success can report green while the application still retrieves stale content. Useful checks include the age of the newest successful sync, the number of records by index version, deletion verification failures, documents pending retry, and retrieval results containing inactive versions. The LLM observability metrics checklist provides a broader framework for connecting these signals to production review.
Common issues
Old chunks remain after an update
This usually occurs when a replacement inserts new chunk IDs but does not delete the prior set, or when the delete filter targets a mutable title instead of a stable source ID. Inspect the records for one affected source and compare their document versions. Fix the deletion query, remove the orphaned records, and add a post-update count check.
Deleted documents return in retrieval
First determine whether the deletion event reached the manifest, vector store, cache, and access-control layer. A document may be deleted from the source but remain in a local export that a later job treats as authoritative. Make the source-of-truth boundary explicit and test deletion propagation with a known document in a non-production environment.
A failed run leaves mixed versions
Do not mark a document current after only some chunks succeed. Use a pending state until the complete replacement has been written and verified. If the run fails, retry the document using the same run or a new run, then remove incomplete temporary records. Versioned writes and a cleanup job for abandoned temporary versions make this recovery safer.
Metadata filters behave unexpectedly
Filter syntax and value types differ between vector database products and client libraries. Confirm whether IDs, booleans, timestamps, and arrays are stored in the form the filter expects. Test filters directly against a small fixture containing active, deleted, and multiple-version records. A filter that silently matches nothing is especially dangerous because it can make deletion appear successful.
A rebuild is expensive or risky
Build a new index rather than overwriting the only production index. Copy the source manifest, process documents into the new index, and compare document counts, chunk counts, metadata coverage, and retrieval results against the existing index. Route a controlled test workload to the candidate, then switch the application through a configuration change. Keep the previous index available until rollback checks pass and the new index has completed a normal synchronization.
For prompt and retrieval evaluation, use a fixed question set that includes changed, deleted, access-controlled, and ambiguous documents. The prompt testing framework guide can help structure repeatable checks, while the AI governance checklist is useful when index maintenance affects sensitive or restricted content.
When to revisit
Run incremental synchronization according to the freshness requirements of the application, and schedule a maintenance review on a recurring cycle. The review should confirm that source snapshots are complete, hashes are stable, deletion events are verified, failed records are retried, and the active index contains only the intended versions.
Revisit the implementation immediately after changing any parser, chunking rule, embedding model, metadata schema, tenant boundary, retrieval filter, or vector database client. Also review it after a connector migration, an access-control change, a significant source-system restructure, or a user report that exposes stale or unauthorized context. These events can invalidate assumptions that ordinary document-level synchronization does not detect.
Use this practical checklist for each review:
- Confirm the current source-of-truth system and whether the latest snapshot is complete.
- Inspect the sync manifest for documents in pending, failed, missing, or temporary states.
- Compare active index versions with the deployed ingestion configuration.
- Sample changed documents and verify that old chunks no longer retrieve.
- Test at least one confirmed deletion and verify vector records, caches, and application results.
- Review retrieval quality with questions covering current, superseded, and unavailable content.
- Decide whether incremental repair is sufficient or a staged rebuild is safer.
- Record the review date, findings, corrective actions, and the next scheduled check.
RAG freshness is a process rather than a one-time migration. A stable manifest, deterministic identifiers, verified deletion filters, and staged rebuilds turn index maintenance into a controlled engineering routine. Revisit the runbook whenever the source or pipeline changes, and keep the synchronization evidence detailed enough that another engineer can diagnose a stale answer without guessing.