DEV Community

ColbyHayes3521
ColbyHayes3521

Posted on

Healthcare Appointment Retrieval Architecture — Failure Recovery With Grounded Citations

A healthcare appointment assistant has one awkward constraint: recovery is successful only when the answer still points to the scheduling text that supports it. Restoring a fast search endpoint is not enough.

Short answer: recover from an append-only ingestion ledger, rebuild only the affected documents, and require every response to carry a query-time evidence manifest; when that manifest is incomplete or contradictory, return a narrow fallback instead of an appointment claim.

This keeps the two important states separate. The index answers “what can I retrieve?” The evidence manifest answers “what supported this exact response?” Diagnosis, triage, and emergency guidance stay outside the assistant’s authority. The job here is smaller: chunk appointment documents, retrieve relevant passages, and preserve usable citations when a document or query step fails.

Ship the boundary first.

What should healthcare appointment assistant retrieval architecture recover after failure?

Recover provenance before prose. For each source document, retain a stable source ID, its revision ID, its chunking policy version, and the processing result. For each query, retain the IDs and locators of the passages admitted as evidence. A retry can then reconstruct a known transformation rather than guess which writes completed.

That distinction matters because failures have different scopes. A failed document fetch should leave that revision pending. A chunking failure should invalidate only the affected source revision. An empty retrieval result should change one response, not trigger an index rebuild. Conflicting passages should block a confident answer even when search itself is healthy. These are recovery decisions, so they deserve different states rather than one generic “RAG failed” alert.

The retrieval-augmented generation paper frames generation as conditioned on retrieved external passages. For an appointment assistant, the operational consequence is direct: if the admitted passage set cannot support a scheduling claim, generation must lose permission to make that claim. It may ask which clinic or location the patient means, state that the detail could not be verified, or direct the patient to the scheduling office.

No citation, no claim.

I’m not sure one evidence threshold can fit every appointment flow. A missing parking instruction and a missing preparation instruction do not carry the same consequence. Resolve that uncertainty with a reviewed set of questions, approved passages, and expected fallbacks, then set policy per intent rather than tuning until answers merely sound confident.

The build log starts with a replayable ledger

The concrete constraint is partial progress. A worker may process four documents and stop on the fifth; rerunning the whole corpus wastes time, while trusting the index alone makes it hard to tell whether the fifth document is absent, old, or merely undiscoverable. An append-only ledger gives each source revision an explicit state and makes the intended next action visible.

Use deterministic chunk IDs derived from the source ID, revision, policy version, and chunk position. Processing the same input under the same policy then targets the same logical chunks. Keep the previous accepted revision available until the new revision’s chunks and citation fields pass validation. This is not a claim that old content is current. It is a containment rule: a failed refresh must not silently replace citable material with a partial revision, while freshness monitoring tells operators that the accepted revision is aging.

Here is the smallest TypeScript shape I would ship. The interfaces hide the chosen queue and vector index because those are undifferentiated infrastructure; the recovery contract is where product risk lives.

type SourceRevision = {
  sourceId: string;
  revisionId: string;
  title: string;
  body: string;
};

type IndexedChunk = {
  id: string;
  sourceId: string;
  revisionId: string;
  locator: string;
  text: string;
};

type LedgerState = "pending" | "accepted" | "rejected";

interface IngestionLedger {
  record(revision: SourceRevision, state: LedgerState): Promise<void>;
}

interface RetrievalIndex {
  upsert(chunks: IndexedChunk[]): Promise<void>;
  accept(sourceId: string, revisionId: string): Promise<void>;
}

function chunkRevision(revision: SourceRevision, size = 800): IndexedChunk[] {
  const chunks: IndexedChunk[] = [];

  for (let start = 0, position = 0; start < revision.body.length; start += size, position += 1) {
    const text = revision.body.slice(start, start + size).trim();
    if (!text) continue;

    chunks.push({
      id: `${revision.sourceId}:${revision.revisionId}:v1:${position}`,
      sourceId: revision.sourceId,
      revisionId: revision.revisionId,
      locator: `characters ${start}-${start + text.length}`,
      text
    });
  }

  return chunks;
}

async function ingest(
  revision: SourceRevision,
  ledger: IngestionLedger,
  index: RetrievalIndex
): Promise<void> {
  await ledger.record(revision, "pending");
  const chunks = chunkRevision(revision);

  if (chunks.length === 0 || chunks.some((chunk) => !chunk.locator)) {
    await ledger.record(revision, "rejected");
    throw new Error("Revision has no citable chunks");
  }

  await index.upsert(chunks);
  await index.accept(revision.sourceId, revision.revisionId);
  await ledger.record(revision, "accepted");
}
Enter fullscreen mode Exit fullscreen mode

The example deliberately does not retry everything. Transport interruptions may justify bounded retries in an adapter, but invalid input should stop immediately. Before accepting a revision, production validation should check expected chunk IDs, nonempty text, locators, and retrieval probes that map representative appointment questions to reviewed passages. A count is useful, but it cannot prove grounding.

For the answer path, create an evidence manifest before generation: request ID, admitted chunk IDs, source revisions, locators, and the decision made by the evidence gate. Don’t place patient-entered free text into broad operational logs by default. The manifest can use internal identifiers while the user-facing citation renders the source title and locator.

Recovery choices and their catches

An ingestion ledger is not suitable when the corpus is disposable and can be rebuilt comfortably inside the recovery objective. In that case, a clean rebuild plus fixed retrieval probes has fewer moving parts. Stick with snapshot restoration when the entire index is one validated unit and source-level replay would add bookkeeping without improving recovery time.

The ledger approach also does not guarantee freshness, correctness, or good chunk boundaries. It records what happened. Source ownership, refresh deadlines, and reviewed retrieval tests decide whether the accepted state deserves trust. That is the catch — more precise recovery creates more state to retain, inspect, and expire.

Recovery unit Best fit Main trade-off
Full snapshot Small corpus with a practical complete rebuild Simple operation, coarse rollback
Source revision Independent documents with uneven update schedules Precise replay, larger ledger
Query evidence manifest Grounding and citation failures on individual requests Clear answer audit, added request metadata

Measure active revision age, pending revision age, rejected revision count, retrieval misses, evidence-gate refusals, and citations missing a locator. Latency alone is misleading: a quick result can still point to the wrong revision. Run failure drills after the pending ledger write, during chunk storage, before revision acceptance, and between retrieval and generation. The expected behavior is stable: replay reaches the same logical chunk IDs, the previously accepted evidence remains available during an incomplete refresh, and unsupported requests take the controlled fallback.

For a one-person service, that testability is the revenue-per-hour choice. I’d outsource storage and queue operation behind narrow interfaces, ship weekly, and keep the evidence policy in application code. Owning a vector engine does not create better citations.

What changes when the corpus and traffic grow?

Scale the recovery unit only after measurements identify a bottleneck. If source-level replay creates a hot partition, group documents by a stable scheduling boundary such as organization or source collection, and retain the contributing revision IDs in every query manifest. If manifest retention becomes expensive, store the compact identifiers needed to reproduce the citation decision rather than full passage text, subject to the system’s retention policy.

Concurrency also needs one hard rule: an older revision cannot become accepted after a newer revision has already won. Enforce that comparison at the acceptance boundary, not in a worker’s memory. Then test it with reordered jobs.

The final decision is deliberately plain. Choose snapshots for cheap complete rebuilds, source ledgers for selective replay, and query manifests wherever a grounded appointment answer must survive scrutiny. None of these mechanisms makes unsupported content safe. The answer gate still has to decline.

Sources

Top comments (0)