DEV Community

JamesAnderson121
JamesAnderson121

Posted on

Travel Itinerary Retrieval: Document Lineage and Freshness for Planner Systems Explained

When an itinerary changes, retrieve the newest valid document for the trip, but keep the older version available for explanation. That is the decision rule: current answers need an explicit version boundary, not a larger top-k.

Short answer: store each itinerary revision as an immutable document, retrieve by a stable trip key plus an “active at” timestamp, and carry the revision ID into every chunk and citation. A planner can then answer “what is booked now?” without losing the ability to explain what changed.

This is a retrieval architecture problem, not a vector-database shopping problem. A travel itinerary planner may have a booking confirmation, an airline schedule update, a hotel message, and a manually edited day plan that all refer to the same trip. Similar wording does not make those records interchangeable.

How can a travel itinerary planner retrieve the right document version?

Start with two identities: trip_id identifies the journey, while revision_id identifies one immutable snapshot of its source document. A chunk gets both IDs, along with effective_from, effective_until, source_type, and a content hash. The active revision is a query decision; the source document itself never gets rewritten in place.

That distinction fixes a common failure mode. A team overwrites “Paris-plan.md” after a train time changes, re-embeds the file, and later discovers that an answer cites a chunk whose text no longer matches the booking record. The index may be fresh, but the evidence trail is gone. Version lineage gives the answer layer something stable to display and gives an evaluator a precise target.

The retrieval flow is deliberately plain. Normalize the user's trip reference, resolve the permitted revision set, search only chunks in that set, then group results by revision_id before composing an answer. A reranker may improve ordering, but it must not decide which revisions are valid. Freshness and authorization happen before ranking.

Keep history.

Here is a small, runnable Python sketch. It uses an in-memory list so the version rule is visible without hiding it behind a framework.

from dataclasses import dataclass
from datetime import datetime, timezone


@dataclass(frozen=True)
class Chunk:
    trip_id: str
    revision_id: str
    text: str
    effective_from: datetime
    effective_until: datetime | None
    source_type: str


def active_chunks(chunks: list[Chunk], trip_id: str, at: datetime) -> list[Chunk]:
    candidates = [
        chunk
        for chunk in chunks
        if chunk.trip_id == trip_id
        and chunk.effective_from <= at
        and (chunk.effective_until is None or at < chunk.effective_until)
    ]
    newest_by_revision = {}
    for chunk in candidates:
        newest_by_revision.setdefault(chunk.revision_id, []).append(chunk)
    if not newest_by_revision:
        return []
    newest_revision = max(
        newest_by_revision,
        key=lambda revision: max(
            item.effective_from for item in newest_by_revision[revision]
        ),
    )
    return newest_by_revision[newest_revision]


now = datetime.now(timezone.utc)
records = [
    Chunk(
        trip_id="trip-204",
        revision_id="rev-08",
        text="Rail from Lyon to Paris departs at 09:40 on 2026-06-18.",
        effective_from=datetime(2026, 5, 2, tzinfo=timezone.utc),
        effective_until=None,
        source_type="rail_confirmation",
    ),
    Chunk(
        trip_id="trip-204",
        revision_id="rev-07",
        text="Rail from Lyon to Paris departs at 08:55 on 2026-06-18.",
        effective_from=datetime(2026, 4, 11, tzinfo=timezone.utc),
        effective_until=datetime(2026, 5, 2, tzinfo=timezone.utc),
        source_type="rail_confirmation",
    ),
]

for chunk in active_chunks(records, "trip-204", now):
    print(chunk.revision_id, chunk.text)
Enter fullscreen mode Exit fullscreen mode

The example chooses one active revision after filtering. In production, keep the previous revision available for a “what changed?” request, but do not mix it into a current-plan answer unless the prompt asks for history. That one separation prevents an old departure time from winning because it happens to be semantically closer to the question.

The data model that keeps freshness explainable

Versioning works best when the ingestion record is richer than a file path. I use an event-like record for every source update: the source identifier, observed time, effective time, revision ID, parser version, and a pointer to the raw payload. Chunks inherit the revision ID; they do not invent their own notion of freshness.

There are two clocks here. observed_at says when the system received a message. effective_from says when the itinerary should be treated as true. An airline notice received late can have an earlier effective time than a message received on time. If the planner stores only ingestion time, a delayed notice can appear to be the newest truth.

Chunk boundaries still matter. Split around semantic units such as a reservation, a transfer, or a day-level activity, and repeat the trip and revision metadata on every chunk. A tiny chunk that says “09:40” is not useful by itself; a chunk that includes the date, station, and revision can be cited without asking the model to reconstruct context from a neighbor.

Do not silently merge revisions during indexing. If a new confirmation supersedes an old one, mark the old revision inactive for current retrieval and retain it for history. A delete operation should be an explicit policy decision, because legal retention, customer support, and debugging may require the original payload even after it leaves the active index.

What should chunking and freshness mean for itinerary answers?

Chunking is a precision decision. Smaller units make it easier to exclude an unrelated day or reservation, while larger units preserve context such as a multi-leg connection. Freshness is a truth decision. A chunk can be highly relevant and still be wrong for the requested travel date.

I keep these signals separate in the candidate record:

Signal Question it answers Failure when omitted
Similarity Does this passage discuss the request? A matching phrase from the wrong trip can surface.
Revision validity Is this version active for the requested time? A cancelled train can look current.
Provenance Which source and revision support the claim? The answer cannot explain its evidence.
Scope Is this chunk allowed for the caller? A support agent may see another traveller's data.

The ranker should consume candidates only after validity and scope filters have run. I also make the answer contract preserve source_type, revision_id, and the relevant effective time in the citation object. That is enough for a UI to show “rail confirmation, revision 08” beside a departure time rather than presenting an untraceable sentence.

Here is the evaluation case I would put in a notebook before wiring a production endpoint: ask for the current departure, ask what changed since yesterday, ask about an old revision explicitly, and ask a question about a different trip with similar city names. The expected result is not just a text string. It is a selected revision, an allowed evidence set, and a refusal when no valid evidence exists.

One subtle trap is a partial update. A hotel message may revise check-in time without replacing the whole itinerary. Treating that message as a complete new snapshot can erase unchanged reservations. Imagine rev-08 contains the rail confirmation, two hotel stays, and a museum booking. A later message says only “late check-in is available until 22:00.” If ingestion stores that message as a full replacement, the next query can retrieve a revision with a correct check-in note but no hotel address, because the address lived only in rev-08. If ingestion appends the note to the old chunks without a new revision, a historical question can accidentally inherit a future policy. The repair is architectural: either build a complete materialized revision from all authoritative components, or label the message as a patch and resolve it before retrieval. Record which source supplied each field, and make the resolver fail closed when two authoritative updates overlap without an ordering rule. Then test a sequence such as confirmation, amendment, delayed amendment, and cancellation. The expected output should name the selected revision and the fields it changed, not merely produce a fluent itinerary. Mixing snapshot and patch models produces answers that are current in one field and stale in another.

A practical rollout and the uncomfortable limits

Ship the ingestion ledger before the chatbot. Log every revision transition and make the active-revision query inspectable. Then run a shadow set containing changed train times, duplicate booking numbers, late-arriving notices, and two trips with the same destination. Compare the selected revision and citation metadata, not only the generated prose.

I budget tokens around the evidence that survives filtering. Sending five chunks from three revisions to the answer model is expensive and confusing; sending one well-scoped chunk with a clear source label is usually easier to evaluate. The notebook-to-prod handoff should record the candidate count, selected revision, and prompt tokens so a quality improvement does not hide a cost regression.

The catch is that immutable revisions add storage, metadata, and lifecycle work. They are not suitable when the source system itself has no meaningful revision or effective time and the product only needs a disposable summary. In that case, a simpler cache with a short expiry may be the honest choice. Stick with a revisioned design when users can dispute an answer, when schedule changes matter, or when support staff must reconstruct a past itinerary.

I’m not sure one global freshness window can serve every travel source. Airline schedules, restaurant reservations, and a traveller’s handwritten note have different update semantics. Let the source owner define the policy, then encode that policy in tests. Your mileage may vary, but the uncertainty should live in a named rule rather than in the model's confidence score.

Three words: version first, rank second.

References

Top comments (0)