醫療預約助理檢索:以引用紀錄帳本追溯重複證據
Healthcare Appointment Assistant Retrieval — Citation Ledgers for Duplicate Evidence
文章建議醫療預約助理在索引前正規化並合併重複預約證據,為每個來源保留引用帳本,並在剩餘證據衝突或不足時不作答。預約身份可由診所、臨牀人員、服務項目、開始時間、時區、就診形式及地點組成,再按來源更新時間及來源優先次序確定現行記錄,同時保留其他記錄供稽核。檢索時可再次按身份分組,避免重複來源佔據排序前列;同組來源的預約狀態不一致時,應交由審核,而非讓模型自行判定。
Short answer: canonicalize appointment evidence before retrieval, keep a citation ledger for every source pointer, and return no answer when the surviving records conflict.
The least complex system that gives a healthcare appointment assistant trustworthy answers is a canonical evidence layer in front of retrieval. Deduplicate appointment records before reranking, preserve every source reference in a citation ledger, and refuse to answer when the remaining evidence conflicts or is too thin.
Decision note: three ways to handle duplicate sources
| Approach | Grounding behavior | Operational cost | Best fit |
|---|---|---|---|
| Deduplicate after generation | The model sees repeated, possibly contradictory passages | Low to start, high to debug | Prototypes with disposable data |
| Deduplicate after retrieval | Reranker can over-score a repeated source | Medium; duplicate traffic remains | Small indexes with stable provenance |
| Canonicalize before indexing | One evidence unit has one current representation and many source pointers | Higher ingest discipline | Appointment systems where a wrong slot is costly |
Recommendation: canonicalize before indexing, then run a second, lightweight duplicate check on the retrieved set. This is a grounding decision, not a database-fashion decision. A solo SaaS founder has limited revenue-per-hour, so I outsource undifferentiated vector plumbing and spend that time on the evidence boundary: what makes a source the same appointment, and which citation can a support agent inspect later?
How should a healthcare appointment assistant deduplicate retrieval evidence?
Start with an evidence identity that is narrower than a document ID. For an appointment slot, a useful identity can include clinic, clinician, service, local start time, and timezone. Keep the appointment's upstream event ID as a source pointer, but do not use it as the only identity: an import replay can create a new event ID for the same slot.
Normalize fields before hashing. Convert Unicode punctuation, trim whitespace, case-fold names, and parse times into an explicit timezone. Do not erase values that affect clinical scheduling, such as visit modality or location. “Downtown” and “Downtown (telehealth)” are different evidence, even if every other field matches.
I initially treated the first matching record as canonical. That was a mistake. In one realistic import sequence, a 02:00 availability export says that 10:30 is open, a booking feed repeats the same slot with a new event ID, and a cancellation arrives at 02:04. A naive “first row wins” map keeps the open slot because the export happened to be read first. A naive “last row wins” map can do the opposite when files are delivered out of order. The canonical record therefore needs a deterministic freshness rule, such as source timestamp plus a source-priority tie breaker, and it must retain the losing records for audit. When timestamps tie, I would rather surface a conflict than invent an ordering from array position. That extra branch costs a few lines of code and saves a support call that would otherwise consume an entire shipping afternoon.
Keep it boring.
Here is the core shape in TypeScript. The function returns a canonical map and keeps source IDs attached for citations.
type Appointment = {
clinic: string;
clinician: string;
service: string;
startsAt: string;
timezone: string;
modality: "in_person" | "telehealth";
location: string;
status: "open" | "held" | "booked" | "cancelled";
sourceId: string;
sourceUpdatedAt: string;
};
const clean = (value: string) => value.normalize("NFKC").trim().toLocaleLowerCase();
function identity(a: Appointment): string {
return [
clean(a.clinic),
clean(a.clinician),
clean(a.service),
new Date(a.startsAt).toISOString(),
a.timezone,
a.modality,
clean(a.location),
].join("|");
}
function canonicalize(rows: Appointment[]): Map<string, Appointment[]> {
const groups = new Map<string, Appointment[]>();
for (const row of rows) {
const key = identity(row);
const group = groups.get(key) ?? [];
group.push(row);
groups.set(key, group);
}
for (const group of groups.values()) {
group.sort((a, b) => Date.parse(b.sourceUpdatedAt) - Date.parse(a.sourceUpdatedAt));
}
return groups;
}
The first element of each sorted group is the proposed current record; the full array is the citation trail. In production, reject malformed timestamps and record the rejection reason. Silent coercion turns a data-quality issue into a plausible-looking booking answer.
Reranking without amplifying a duplicate
Index one representation per canonical identity, with a compact citation payload: identity, current status, source IDs, and update time. At query time, retrieve a wider candidate set than the UI needs, group candidates by identity, and apply a diversity penalty before the final rerank. This prevents five copies of one clinic export from occupying all top positions.
The reranker should score relevance and freshness, but the answer policy should score evidence agreement separately. If two sources in one group disagree on status, expose the conflict to a review queue instead of letting a high semantic score choose silently. A healthcare assistant can say that availability needs confirmation; it should not manufacture certainty.
Keep the citation ledger outside the prompt text. Pass the model a stable citation label such as slot-17, while your application maps that label to source IDs, timestamps, and the canonicalization rule. This keeps prompts small and makes a later audit reproducible. It also gives you a clean test seam when a source import changes format.
The failure modes worth testing
Write fixtures for replayed exports, daylight-saving transitions, clinician name changes, and a cancellation that races an availability snapshot. Test that equivalent records collapse, materially different modality or location values stay separate, and every generated claim resolves to at least one current citation label.
A useful adversarial test asks the assistant for a slot that exists only in a duplicate loser. The expected result is either the current canonical status or a no-evidence response, never the stale value. Log identity keys, candidate counts before and after grouping, conflict counts, and citation resolution failures. Those counters tell me where to spend the next shipping week.
The catch is that pre-index canonicalization adds ingest complexity and can delay freshness if the pipeline is batch-only. It is not suitable when the source has no stable update timestamp or when records are intentionally independent observations, such as separate clinician notes. In those cases, keep a source-level retrieval index and use explicit provenance-aware reranking; a simple hash is the wrong abstraction.
I’m not sure a single freshness policy will fit every specialty. Your mileage will vary with scheduling rules, especially across timezones and recurring visits. Make the policy configurable, version it, and include its version in the ledger so an answer can be explained months later.
References
來源:DEV Community · dev.to