RAG Freshness Control: Preventing Stale Answers in Fast-Moving Projects

RAG systems fail when retrieval indexes lag behind source changes. You need freshness controls so generated answers reflect current truth, not yesterday’s state.

Step 1: Tag chunks with source commit and indexed timestamp

{
  "chunk_id": "c_2041",
  "source_commit": "a1b2c3d",
  "indexed_at": "2026-03-11T01:05:00Z"
}

Step 2: Reject stale context beyond freshness SLA

def is_fresh(chunk, now, max_age_hours=24):
    return (now - chunk.indexed_at).total_seconds() < max_age_hours * 3600
Preview: first 50% is visible. Unlock to read the full article.
To view this content, you must be a member of CodeWithWilliamJiamin's Patreon at $1 or more
Already a qualifying Patreon member? Refresh to access this content.