BM
Bashar ModallalSOFTWARE · AI · SYSTEMS
← All field notes

AI

Keeping a RAG Knowledge Index Fresh

Design RAG freshness around durable changes, versioned idempotent updates, deletion tracking, permission changes, and reconciliation.

A versioned document passes through change detection, chunking and embeddings into a searchable RAG index, with a deletion and reconciliation loop.

Keeping a RAG Knowledge Index Fresh

Estimated reading time: 9 minutes

Read the Arabic edition: الحفاظ على حداثة فهرس المعرفة في RAG

A retrieval-augmented generation system is only as useful as the evidence it can retrieve. When a policy changes in the source repository but its old passage remains searchable, a fluent answer can still be stale. When a deleted document survives as a vector, the system may quote material that the organization intended to withdraw. Keeping a RAG index fresh is therefore a data consistency problem: the indexed representation must eventually reflect creates, edits, moves, deletes, access-control changes, and sometimes a new embedding model.

“Fresh” needs a measurable meaning. A team might define it as: every committed source update is searchable within an agreed delay, a deletion is no longer retrievable within its deletion window, and every indexed chunk carries a source version and permission snapshot that can be audited. The exact target depends on the use case. A live support catalog may need low delay; a nightly research archive may accept batch updates. Neither schedule alone proves correctness. The system must also detect missed events and repair drift.

Treat the index as a derived view

The source database or document store should remain authoritative. The vector index is a derived view optimized for retrieval. A useful indexed record includes a stable document ID, source version, chunk identity, content hash, embedding-model version, source URI, timestamps, and any permission metadata needed at query time. The index should be reproducible from the source plus a recorded transformation pipeline.

A freshness pipeline can be represented as follows:

flowchart TB
  A["Authoritative source"] --> B["Change event or batch scan"]
  B --> C["Versioned work queue"]
  C --> D["Normalize, authorize, chunk, embed"]
  D --> E["Idempotent upsert or delete"]
  E --> F["Searchable index"]
  G["Reconciliation scan"] --> H["Compare source and index"]
  H --> C

Choose an update path that can recover

Three strategies are common, and a production system can combine them.

Event-driven updates consume change data capture, database triggers, or messages. They reduce delay, but delivery is often at least once rather than exactly once. Consumers must tolerate duplicates, reordering, and retries. Qdrant’s synchronization guidance describes event-driven upsert/delete work, timestamp- or version-based batch synchronization, and dual writes as alternatives with different latency and consistency trade-offs.

Batch synchronization periodically finds records whose version or modification timestamp is newer than a checkpoint. It is simple to reason about and useful as a fallback, but a timestamp is only a safe cursor when it is reliably updated, has adequate precision, and is combined with a stable tie-breaker. If two rows share the same timestamp, a cursor on time alone can skip one. A safer cursor is often the pair (updated_at, document_id), with an overlap window and idempotent writes. The overlap deliberately revisits a small range, trading repeated work for protection against precision and late-commit edge cases.

A transactional outbox closes the gap between changing the source and recording work. In one source-database transaction, write the business row and an outbox event. A worker later sends the event to the vector store and marks it processed. Qdrant’s Postgres integration guide illustrates this architecture: the event exists if and only if the source write commits, and the event contains a snapshot so a later update does not silently change what the worker meant to process. This does not make the source and vector database one transaction; it makes the intended synchronization work durable.

Make updates idempotent and version-aware

Give each source document a stable ID and each change a monotonic version or immutable event ID. A worker should process the same event twice without creating duplicate chunks. In Qdrant, points with the same ID are overwritten by an upsert, making a stable point ID useful for idempotent loading. A chunk ID can be derived from the document ID and a deterministic chunk key, such as section path plus chunk ordinal. If chunk boundaries change, delete the document’s previous chunk set before or atomically with writing the new set, depending on the store’s guarantees.

The worker should compare versions before applying a change. Suppose version 12 is already indexed and a delayed event for version 10 arrives. Reapplying version 10 would roll the index backward. Store the indexed version and reject events older than it, or serialize work per document. If events are not ordered, a version check is essential. A version is meaningful only if it is monotonic for that document; wall-clock timestamps can be equal, skewed, or updated in a different order than commits.

Worked example 1: editing a handbook page

Assume document handbook/returns is at source version 41 and has three indexed chunks. An editor changes one section, creating version 42.

Input: an outbox event with document ID, version 42, operation upsert, and the committed content snapshot.

Decision: the worker reads the indexed version, 41, and sees that 42 is newer. It normalizes the snapshot, creates deterministic chunk IDs for the document, and records version 42 on each point. If the new text produces four chunks, it upserts those four IDs and deletes any old ID no longer present. If the same event is delivered again, the same IDs and content hash make the replay harmless. If an event for version 41 arrives afterward, it is rejected as stale.

Output: the index reports source version 42 for the document, and a query for the changed policy can retrieve the new chunks. A version 41 event arriving later cannot roll the index backward. The example illustrates a design; it does not claim a measured indexing time.

Treat deletion as a first-class change

A deletion cannot be inferred safely from the absence of a document in one partial scan. Use a durable tombstone or explicit delete event containing the stable document ID and deletion version. The consumer deletes every point belonging to that document, then records a deletion receipt. Keep tombstones long enough for delayed consumers and reconciliation jobs to observe them. If a document is physically removed immediately, a worker that was offline may have no source row from which to discover the deletion.

Azure AI Search documents a related trap: its indexers can detect changes using source timestamps, but deletion detection needs an explicit strategy such as native blob soft delete or custom metadata. The policy needs to be in place from the initial indexing run; otherwise earlier deletions can remain orphaned. Resetting an indexer is not a universal cleanup operation. Microsoft’s reset guidance says reset/run operations can reprocess creates and updates but do not remove orphaned index documents by themselves.

Worked example 2: a revoked document

Suppose a team removes document case-88 after it is withdrawn. The vector index currently contains chunks case-88:0 through case-88:5.

Input: a tombstone for case-88, version 19, with a delete reason code and event ID.

Decision: the consumer checks that version 19 is newer than the stored version. It deletes by the document ID filter, not by guessing the old chunk count. It records the tombstone version even after the points are gone, so a delayed version 18 update cannot restore the document. A reconciliation job later confirms that no point has that document ID.

Output: normal retrieval no longer returns those chunks, and the deletion receipt proves which version was applied. If deletion is required for privacy or legal reasons, the workflow must also consider backups, caches, logs, and downstream replicas; removing vector points alone does not establish erasure everywhere.

Permissions and moves belong in the freshness model

Content freshness and authorization freshness are related. If a document becomes restricted, its chunks must not remain available under old permissions. Possible designs include filtering by current authorization at query time, synchronously updating permission metadata, or combining both. Query-time checks provide a final guard, while indexed ACL metadata can reduce candidate leakage and improve filtering. The system must fail closed when authorization data is missing or stale beyond its accepted window.

Re-embedding is a controlled migration

A new embedding model, tokenizer, or chunking rule changes the representation even when source text has not changed. Store the transformation version with every point. For a full migration, build a new collection or index, populate it from a consistent source snapshot, verify counts and representative queries, then switch retrieval traffic. A mixed index can be valid only if the query vector is compatible with every stored vector; do not silently write vectors from different dimensions or model spaces into one retrieval path.

Selective reprocessing can reduce work when only one transformation stage changed. Azure’s indexer APIs distinguish broad resets from targeted reset operations, and their documentation notes that a reset must be followed by an indexing run. A reset also does not replace a delete policy. Treat vendor-specific reset behavior as one implementation detail, not as a substitute for end-to-end consistency checks owned by your application.

Observe lag, drift, and deletion debt

Monitor more than “worker is running.” Useful signals include the oldest unprocessed event age, queue depth, retries by error class, source version versus indexed version, documents awaiting deletion, embedding failures, and reconciliation repairs. Measure freshness from source commit to query visibility, and report percentiles or threshold breaches rather than relying on an average. Track separate objectives for updates, deletions, and permission revocations because their risks differ.

Reconciliation should compare stable IDs and versions, not just total counts. Equal counts can hide one missing document and one duplicate. A periodic scan can sample recent changes or compute partitions by source ID, then enqueue corrective work through the same idempotent path. For large indexes, use bounded batches, rate limits, and checkpoints; record a checkpoint only after the batch’s effects are confirmed. Microsoft’s indexer guidance describes an internal high-water mark for incremental processing. An application-owned pipeline should make its own cursor visible and recoverable.

A practical release checklist

Before calling an index fresh, confirm that:

  • source changes have durable event or scan coverage;
  • duplicate and out-of-order events cannot regress document versions;
  • deletes and permission changes have explicit handling;
  • chunk IDs are stable and obsolete chunks are removed;
  • embedding and chunking versions are recorded;
  • failed events remain retryable without hiding partial work;
  • reconciliation can discover missed changes and orphaned points;
  • queries enforce current authorization and expose useful source metadata;
  • lag and deletion debt have owners and alerts.

A RAG index is not fresh because its last scheduled job says “success.” It is fresh when the system connects each searchable representation to a current source version, accounts for deletions and permissions, detects drift, and repairs it through a bounded, observable process. Event delivery gets changes moving; stable identities make retries safe; tombstones preserve deletion intent; reconciliation provides a second path to correctness.

References

YOUR TAKE

What did you think?

Choose one reaction for this article.

Was this useful?

A cookie helps limit repeat responses. Your feedback is private.

Share this noteLinkedIn ↗X ↗Email ↗

Keep exploring.