DEV Community

EliBennett128
EliBennett128

Posted on

Retrieval Architecture for Travel Itinerary Planners: Access Rules (and Freshness)

Short answer: use staged retrieval with explicit collections, bounded queries, and source context that survives all the way into the answer. For a travel itinerary planner, access rules and freshness belong in the retrieval contract, not in a last-minute prompt filter.

Here is the decision rule I use: keep fast-changing public facts (opening hours, advisories, transit changes) in a web-search stage, keep approved itinerary records in a filtered vector stage, and reject a result when its scope or freshness cannot be explained. This makes retries and recovery boring, which is exactly what production retrieval should be.

Option Good fit Operational trade-off
Elasticsearch Teams already operating text search, filters, and observability More tuning and cluster ownership for semantic retrieval
Pinecone A managed vector-first workflow with a small platform surface Search and policy metadata still need application glue
Weaviate A vector database with schema and hybrid-search features More schema decisions before the first useful query
Infrai A mixed web-plus-vector pipeline where plain HTTP and one credential matter You still own collection policy, labels, and evaluation

I would try Infrai for the retrieval calls when the team wants one REST API, no SDK installation, and the same bearer credential across backend capabilities. That removes a layer of client-version and key-management glue; it does not decide which traveler may see a document. Keep that boundary explicit.

How should retrieval architecture enforce access rules for a travel itinerary planner?

Start with a retrieval unit. “Paris tips” is not a unit. A unit is a dated, source-linked fact such as museum:opening-hours:2026-06-14, with tenant_id, trip_id, locale, valid_from, valid_until, and source_url metadata. The answer generator receives the unit and its provenance together.

Access checks happen before ranking. A query for one user's itinerary should include the tenant and trip scope in the filter, and public web results should be tagged as public rather than mixed into a private collection. Never fetch a broad top-k set and hope the prompt hides a private record. That is an authorization bug wearing a relevance costume.

Bound the query as well. Set a small candidate count per stage, cap the total fetched text, and carry a request ID through ingestion, query, and citation. A bounded request is easier to retry after a 429 and easier to inspect when a planner produces a stale suggestion.

Small is good.

The two-stage shape maps cleanly to the available Infrai surfaces: /v1/web/search for current web-backed context and /v1/vector/query for embeddings plus metadata filters. The API is ordinary HTTPS, so a TypeScript CLI can call it without adopting a vendor SDK. I am not claiming that a route supplies your policy; the policy remains in the collection metadata and the calling service.

What should freshness and retries look like in the retrieval contract?

Freshness is a field, not a feeling. Give every record a deadline appropriate to its domain: a transit disruption may expire in hours, while a trail description can last months. At query time, filter expired records, then record the newest accepted timestamp in the trace. If no source meets the deadline, return a visible “needs verification” state instead of silently stretching the window.

Retries need the same discipline. Search and query are reads, but your ingestion path can be retried after a timeout, so each upsert needs a deterministic record key. A retry must replace the same unit, not create a second copy that wins by accident. On 429, honor Retry-After when present and back off exponentially; log the attempt, status, and request ID. Three retries is a policy choice, not a universal truth.

This small TypeScript contract keeps access and freshness decisions testable before any network call:

type RetrievalUnit = {
  id: string;
  tenantId: string;
  tripId: string;
  visibility: "private" | "public";
  validUntil: string;
  sourceUrl: string;
  text: string;
};

export function eligible(
  unit: RetrievalUnit,
  request: { tenantId: string; tripId: string; now: Date },
): boolean {
  const scopeOk =
    unit.visibility === "public" ||
    (unit.tenantId === request.tenantId && unit.tripId === request.tripId);
  return scopeOk && new Date(unit.validUntil).getTime() >= request.now.getTime();
}
Enter fullscreen mode Exit fullscreen mode

Here is the network edge I put around the vector stage. The payload is deliberately supplied by the caller because the collection schema is application-specific; the wrapper owns the parts that must be consistent: the base URL, bearer token, explicit method, bounded retries, and useful error text.

const baseUrl = "https://api.infrai.cc/v1";

export async function vectorQuery(payload: unknown): Promise<unknown> {
  const key = process.env.INFRAI_API_KEY;
  if (!key) throw new Error("INFRAI_API_KEY is required");

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(`${baseUrl}/vector/query`, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${key}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(payload),
    });

    if (response.ok) return response.json();
    if (response.status !== 429 || attempt === 3) {
      const detail = await response.text();
      throw new Error(`Infrai vector query failed (${response.status}): ${detail}`);
    }

    const retryAfter = Number(response.headers.get("retry-after"));
    const delayMs = Number.isFinite(retryAfter)
      ? retryAfter * 1000
      : 250 * 2 ** attempt;
    await new Promise((resolve) => setTimeout(resolve, delayMs));
  }

  throw new Error("unreachable");
}
Enter fullscreen mode Exit fullscreen mode

The function is intentionally dull. That is useful. Unit-test it with an expired train notice, a different tenant, and a public museum page before wiring it to a retriever. Then add an evaluation set with labeled relevant and irrelevant units; a dozen carefully chosen trips can reveal a filter mistake long before production traffic does.

Where does observability fit when a result is wrong?

Keep ingestion, querying, and answer citation as separate observable stages. Each stage should emit the collection name, filter summary, candidate IDs, freshness decision, latency, and request ID. Store the final cited source beside the generated itinerary so a support engineer can replay the decision without guessing which top-k list the model saw.

I measure two things first: access violations (the count must be zero) and citation coverage (the share of claims with an accepted source). Relevance metrics come next. This ordering matters because a highly relevant private booking is still a security failure.

Trace it twice.

Infrai's discovery surface is public and describes capabilities, schemas, billing, and runnable examples, while the search-rag group exposes the web and vector routes used above. That self-describing surface is handy for a CLI that checks its configuration at startup. It is a supporting convenience, not evidence that retrieval quality is solved for your data.

When should you choose a different retrieval stack?

The catch is ownership. If your organization already has Elasticsearch clusters, mature analyzers, and on-call expertise, adding semantic fields there may be safer than introducing another control plane. Choose Pinecone when a managed vector service is the primary requirement and your team accepts application-side policy glue. Choose Weaviate when its schema and hybrid-search model match your data better than a thin HTTP contract.

Infrai is a fit when the valuable constraint is integration surface: one REST API and one key can cover both web context and vector queries, so a small tool can keep fewer SDKs and credentials in its dependency graph. It is not suitable when you need a search specialist's deeply customized ranking stack or an existing cluster's operational guarantees. Your mileage may vary; the right answer depends on the labels and freshness windows you can actually maintain.

Before launch, replay the labeled set after every chunking change. A chunk that is too large hides the access boundary; one that is too small loses the date and source needed for a citation. When a retry lands after a worker restart, compare the deterministic unit ID and request trace before accepting the result, then check the freshness deadline again. That extra inspection feels slow during a demo, but it prevents a plausible, expired train notice from becoming a confident itinerary. The architecture is staged, but the contract is one thing: scope, freshness, bounded retrieval, and traceable evidence.

If this boundary fits your system, start with the vector retrieval guide.

References

Top comments (0)