Index freshness & lifecycle

In one sentence

A RAG index is a replica of your sources: stream changes in, propagate every deletion, version each chunk, and migrate embedding models through a blue/green index and an alias swap, never in place.

Analogy: Like a store's shelf labels: if prices change in the back office and nobody updates the shelf, customers get confidently wrong answers, and recalled products must leave every shelf, not just the warehouse.

During a model migration, changes and deletions are dual-written to both indexes; readers only see the alias, which flips to green once it passes eval.

How it works

  • Ingest incrementally: CDC or webhooks for changes, plus a periodic reconciliation crawl for missed events.
  • Upsert by a stable doc_id and hash each chunk, so unchanged chunks skip re-embedding.
  • Deletes must reach every chunk, cache and copy; embeddings can be inverted, so treat them as personal data.
  • Re-embedding is cheap; the real work is the backfill, dual-writes and an eval gate before the alias swap.
  • Set a freshness SLA, e.g. p95 edit-to-searchable under 15 min, and alert on the measured lag.

Check yourself

Answer to mark it learned; your answers aren't scored.

Monday's deploy upgraded the query embedding model to a newer one. No errors anywhere, but retrieval turns near-random across every topic. Nobody touched the index. Most likely cause?

Go deeper

Full explanation

An index is not built once: it is a replica of your sources that drifts the moment a document changes. Lifecycle is everything that keeps it correct.

  • Incremental ingestion — consume changes instead of re-crawling: CDC from the database log (e.g. Debezium), webhooks or change APIs from Drive, Confluence or SharePoint, plus a periodic reconciliation crawl for missed events. Upsert by a stable doc_id; hash each chunk and skip re-embedding unchanged ones.
  • Deletions — every chunk carries its doc_id, so one delete removes all its chunks. Many ANN indexes only tombstone deletes until compaction. A GDPR erasure must reach the index, caches and derived stores; embeddings can be inverted back toward the text, so treat them as personal data.
  • Versioning — store doc_version, chunker_version, embedding_model and content_hash per chunk, so staleness is queryable.
  • Model changes — vectors from two models live in incompatible spaces: never mix them in one index. Build a new (green) index, backfill, dual-write live changes, evaluate, then swap an alias atomically and keep the old (blue) one for rollback.
  • Freshness SLA — e.g. p95 edit-to-searchable under 15 min, deletions under 1 h; measure the lag and alert on it.
  • Dedup — exact hashes plus near-duplicate detection, or the top-k fills with five copies of one page.
Code Per-document sync and an atomic alias swap (Qdrant)
pythonPer-document sync and an atomic alias swap (Qdrant)
import hashlib, uuid
from qdrant_client import QdrantClient, models

client = QdrantClient("http://localhost:6333")
EMBED_MODEL = "text-embedding-3-small"  # pinned: queries must use the same model
ALIAS = "kb"                            # readers only ever query the alias

def match(key, value):
    return models.FieldCondition(key=key, match=models.MatchValue(value=value))

def sync_document(coll: str, doc_id: str, version: int, text: str | None) -> None:
    if text is not None:  # write the new version first: no gap where the doc vanishes
        chunks = chunk(text)
        vectors = embed_cached(chunks, model=EMBED_MODEL)  # cache keyed by content hash
        client.upsert(coll, points=[models.PointStruct(
            id=str(uuid.uuid5(uuid.NAMESPACE_URL, f"{doc_id}:{version}:{i}")), vector=v,
            payload={"doc_id": doc_id, "doc_version": version, "chunk_index": i,
                     "content_hash": hashlib.sha256(c.encode()).hexdigest(),
                     "embedding_model": EMBED_MODEL, "text": c})
            for i, (c, v) in enumerate(zip(chunks, vectors))])
    # Then drop older versions; text=None is a tombstone (delete or GDPR erasure)
    stale = models.Filter(must=[match("doc_id", doc_id)],
                          must_not=None if text is None else [match("doc_version", version)])
    client.delete(coll, points_selector=models.FilterSelector(filter=stale))

def swap_alias(new_coll: str) -> None:
    # Atomic flip once the green index passes eval; keep the old one for rollback
    client.update_collection_aliases(change_aliases_operations=[
        models.DeleteAliasOperation(delete_alias=models.DeleteAlias(alias_name=ALIAS)),
        models.CreateAliasOperation(create_alias=models.CreateAlias(
            collection_name=new_coll, alias_name=ALIAS)),
    ])
Real example

A company indexes 400k Confluence pages (~8M chunks) with a nightly crawl. Two incidents in month one: a policy edited at 9:00 still served the old text at 17:00, and an ex-employee's erasure request cleared the HR system while their 1:1 notes stayed retrievable. Fix: webhooks → queue → per-document sync with version-based cleanup, deletes as audited tombstones, a weekly reconciliation crawl. Six months later they switch embedding models: ~4B tokens to re-embed cost ~$80 at $0.02 per 1M tokens. The real work was the two-day backfill, dual-writes and an eval gate before the alias swap.

Trade-offs +3 · −3

+ You gain

  • Answers reflect the current source, edits and deletions included, within a measured SLA.
  • Model upgrades become routine and reversible instead of a risky big-bang re-index.
  • Per-chunk versions and hashes make staleness auditable and skip needless re-embedding.

− You pay

  • Real pipeline engineering: queues, retries, idempotency and reconciliation jobs.
  • Blue/green doubles storage and write load during every migration.
  • Source change feeds are often incomplete, so periodic full reconciliation is still required.

Use it when

Any RAG beyond a demo: sources that change, users with deletion rights, regulated data, or an embedding model you will eventually upgrade. That is every production system.

Avoid it when

A truly static corpus (an archived dataset, a fixed set of manuals) where a scheduled full rebuild is cheap and simpler than change feeds.

Numbers to know 4
  • GDPR: answer an erasure request without undue delay, normally within one month (Art. 12(3)).
  • Re-embedding 1B tokens with text-embedding-3-small ≈ $20 ($0.02 per 1M, list price as of 2026); throughput and rebuild time are the real bottleneck.
  • Embedding inversion (vec2text) recovered 92% of 32-token inputs exactly from their embeddings.
  • Example SLA: p95 edit-to-searchable < 15 min; deletions < 1 h; alert on the measured lag.
Common pitfalls 4
  • Upgrading the query embedder while the index still holds old vectors: results turn silently random.
  • Deleting the source document but not its chunks, cached answers or Semantic caching entries.
  • Random chunk ids: re-ingestion creates duplicates instead of replacing the old version.
  • Trusting webhooks alone: one dropped event leaves a page stale forever. Schedule reconciliation.
Interview questions 2

Answer out loud first, then reveal.

You must switch embedding models on a 50M-chunk production index. How?Show answer

Blue/green, never in place, because old and new vectors aren't comparable. I build a new collection with the new model and backfill from the canonical chunk store, not by re-parsing sources. While it runs, live changes and deletions are dual-written to both. Before flipping I run the retrieval eval set on both — recall@k, nDCG — plus a shadow comparison on real queries. Then I swap the alias atomically, with query embedding pinned to the same version, and keep blue for rollback. The cost is mostly backfill throughput and double storage, not embedding dollars.

A user exercises their GDPR right to erasure. What has to happen in your RAG system?Show answer

Erasure must reach every derived copy, not only the source. I map the person to every doc_id they own or appear in, emit tombstones, and delete all chunks by doc_id in every live index, including a green index mid-migration. Then I purge caches, answer logs and eval sets built from production data, and confirm the vector store actually compacts, since many ANN indexes only mark deletes. Embeddings can be inverted toward the original text, so I treat them as personal data. I log the deletion for audit and verify with a search that nothing comes back.