Short answer: cache retrieval evidence, not the final itinerary. Keep a short-lived cache for query features and a versioned cache for media index results, then invalidate by content revision and destination policy. This costs more bookkeeping than a single response cache, but it prevents a changed opening hour or licensing rule from surviving inside a supposedly helpful trip plan.
The application here is a travel itinerary planner whose corpus contains media: destination guides, venue pages, transit clips, and editorial photos. The retrieval layer reranks those documents for each itinerary step. Its hard constraint is index cost at scale. Rebuilding every vector after every edit is wasteful; serving an old ranking without a freshness signal is worse, because users make real reservations from it.
The constraint: index work is the scarce resource
A planner request usually has three different clocks. The traveler’s wording changes per request, editorial content changes when a document is revised, and policy data changes on a schedule owned by another team. A cache design that gives all three one TTL cannot express those clocks.
I model a result as evidence with a provenance tuple: (document_id, revision, embedding_model, policy_version). The tuple is part of the cache key and part of the audit record. In payment systems I would never reconcile a ledger entry without its source version; search deserves the same exactly-once mindset when a ranking is copied into a user-visible plan.
The useful unit to cache is therefore a candidate set plus scores, not prose generated by the language model. Candidate sets are reusable across many itinerary prompts, while generated text embeds assumptions that are hard to invalidate. A 60-second query-feature cache can absorb repeated autocomplete traffic, and a revision-keyed candidate cache can live much longer without hiding edits.
How should a travel itinerary planner cache retrieval and reranking?
Use three boundaries, each with an explicit invalidation event:
| Boundary | Key material | Invalidate when | Main risk |
|---|---|---|---|
| Query features | normalized query, locale, date window | parser or policy version changes | old interpretation |
| Candidate retrieval | destination, filters, document revision, index generation | document revision or index generation changes | stale membership |
| Reranking evidence | candidate IDs, feature vector, model version | model, policy, or feature schema changes | inconsistent ordering |
The index generation is a monotonically increasing token published with each completed batch. Readers pin one generation for the whole request. That small rule avoids a mixed result in which the first page came from generation 41 and the second page came from generation 42. If a generation is unavailable, the reader can use the previous complete generation and mark the response as aged; it should not silently combine shards.
Pin the generation.
Here is the cache admission and freshness check in Go. The interface is deliberately generic so the same logic can sit over an in-process cache, a shared key-value store, or a disk-backed layer.
package retrieval import "time" type EvidenceKey struct { Destination string Revision string IndexGen uint64 Model string Policy string } type Evidence struct { DocIDs []string Scores []float64 ExpiresAt time.Time } func Fresh(e Evidence, now time.Time) bool { return now.Before(e.ExpiresAt) && len(e.DocIDs) == len(e.Scores) } func Admit(key EvidenceKey, e Evidence, now time.Time) bool { if key.Destination == "" || key.Revision == "" || key.IndexGen == 0 { return false } return Fresh(e, now) } The length check is not cosmetic. A partial write can leave IDs and scores out of alignment, which turns a cache hit into a relevance defect that is difficult to reproduce. Writes should be conditional on the generation token, and metrics should record hit, miss, stale, and rejected-admission counts separately. A single “cache hit rate” hides the failure mode that matters.
Invalidation is a data contract, not a timer
Every indexed document emits a revision event after its source transaction commits. The consumer records the event ID before applying it, so a retry cannot enqueue the same embedding job twice. The job itself is idempotent: (document_id, revision, embedding_model) identifies one intended write. If the event stream is delayed, the planner can still serve a prior complete generation, but the response carries the age and revision used for the audit trail.
A timer remains useful as a backstop. It catches missed events and bounds exposure, yet it must not be the primary correctness mechanism. For volatile facts such as opening hours, use a policy-specific freshness window; for stable editorial prose, revision keys can outlive that window. Your mileage may vary when upstream publishers cannot provide revisions; in that case, add a content hash and accept that freshness is probabilistic rather than pretending a TTL proves correctness.
The awkward case is a delete. Tombstones need to remain visible to the index builder until every serving generation that could contain the document has expired. Removing the cache key immediately only protects the next generation; it does nothing for readers pinned to the old one. Consider a venue page revised at 09:00 and removed at 09:03 while generation 41 is still serving a long-running itinerary request: the revision event must first make generation 42 exclude the document, the tombstone must remain consumable by any shard still building 42, and the serving layer must retain the provenance record long enough to explain why an earlier response contained the page. If the deletion is applied only to a key-value cache, an already materialized candidate list can continue to point at the venue; if it is applied only to the index, a stale reranking cache can reintroduce the old score. This is where teams often spend index budget twice: once rebuilding, then again repairing a result that still referenced a deleted venue.
Measuring cost without losing relevance
Track index CPU-seconds per published generation, embedding writes per revised document, cache bytes per destination, and the age distribution of served evidence. Pair those with retrieval recall on a fixed evaluation set and a freshness violation count. A cheaper index that raises violations is not a saving; it is deferred operational work.
Sample traces should carry the four provenance fields, the cache boundary that answered, and the invalidation event ID. Keep those fields for the retention period required by your compliance review. Do not log raw traveler queries when they can contain personal details; hash a normalized form and retain the salt outside analytics storage.
Rollout rules and the catch
Start in shadow mode: compute the versioned cache decision, but continue using the existing path, then compare rank changes and freshness ages. Promote one destination cohort at a time. Set an explicit rollback trigger, such as a rise in stale-result violations or a drop in judged recall, and roll back the cache policy rather than deleting generations that an in-flight request still needs.
The catch is that this architecture is not suitable when the product requires per-request, real-time inventory guarantees from an upstream system that has no revision or event feed. Keep a direct, uncached lookup for that slice, even if it raises latency. Conversely, a planner built only on slowly changing guides can use longer revision-keyed retention and a simpler invalidation worker. The decision follows data volatility and audit requirements, not a fashionable cache technology.
