A live-web RAG workflow needs a freshness decision before it needs another search call. Keep the age and availability of the evidence, the task’s freshness requirement and the action taken. Reuse a source only when its stored revision remains suitable for the question.
Route reuse, refresh and removal separately
import math
from datetime import datetime, timezone
def freshness_action(last_checked, now, ttl_seconds, availability='available'):
if availability not in {'available', 'removed'}:
raise ValueError('Unknown source availability')
if availability == 'removed':
return 'tombstone'
if (isinstance(ttl_seconds, bool)
or not isinstance(ttl_seconds, (int, float))
or not math.isfinite(ttl_seconds) or ttl_seconds < 0):
raise ValueError('Use a finite, non-negative TTL')
if last_checked.tzinfo is None or now.tzinfo is None:
raise ValueError('Timezone-aware timestamps are required')
age_seconds = (now - last_checked).total_seconds()
if age_seconds < 0:
raise ValueError('A future timestamp needs an explicit clock-skew policy')
if age_seconds > ttl_seconds:
return 'refresh'
return 'reuse'
now = datetime(2026, 10, 10, 12, tzinfo=timezone.utc)
checked = datetime(2026, 10, 10, 11, tzinfo=timezone.utc)
assert freshness_action(checked, now, 7200) == "reuse"
assert freshness_action(checked, now, 1800) == "refresh"
assert freshness_action(checked, now, 7200, "removed") == "tombstone"
An unknown availability state or a timestamp ahead of the declared clock is an input error here. Handle it explicitly rather than silently treating the source as fresh. A confirmed removal still follows the separate tombstone route.
The timestamps and TTL values are synthetic test choices, not a recommended freshness policy for every topic. A removed source follows a deletion route even if its previous timestamp is recent.
Refresh through the documented Search and Reader contracts
Use POST /api/v1/search with t and s for discovery, then select URLs from data.organic[].link. Use POST /api/v1/url with t: url and s containing a selected URL for reading. Keep the business status and extraction result separate; do not use a GET request with another provider’s q/engine envelope.
Record source URL, revision hash and access time with the accepted passage. A fresh extraction can still be irrelevant or unsupported. Check the answer against the passage before generation and allow an insufficient-evidence response.
Test the router, then evaluate the answers
The local router cases verify state transitions. They do not call a live language model or establish answer accuracy. The architecture guide covers the whole evidence pipeline.
- Cover fresh cache, expired cache, removed source and failed refresh.
- Keep stale fallback explicitly labelled and only use it where the application permits it.
- Compare answers against a frozen question/source set when evaluating quality.
- Do not infer hallucination reduction from the fact that a web request completed.
Reference documentation: www.searchcans.com — /google-search-api; www.searchcans.com — /reader-api.