Short answer: keep citation tracing in the retrieval record, not in the generated answer. Store the source id, span offsets, and retrieval scores beside every candidate, then rerank that compact set. This keeps customer-support answers auditable while keeping the expensive index small.
The constraint that changed the design
Support search looks cheap until the index has millions of ticket messages, attachments, and policy revisions. Embedding every byte is an index-cost decision, not a quality virtue. I measure cost per active document and recall at the top 50 before choosing a model or database.
The useful unit is a citation-ready chunk. It has stable provenance: ticket_id, revision, authoring time, character offsets, and an access-control snapshot. The text can be replaced during re-indexing, but the provenance key must remain resolvable. A model can then cite the exact policy paragraph instead of gesturing at an entire ticket.
The retrieval architecture has two passes. A lexical or vector index fetches a generous candidate set. A reranker scores only that set, which caps compute and makes index growth predictable. The answer generator sees the top records plus their evidence metadata. It never invents a citation after the fact.
How should retrieval architecture handle citation tracing and relevance reranking?
Start with a plain contract. It is more valuable than a clever prompt.
type Candidate = {
chunkId: string;
ticketId: string;
revision: number;
text: string;
start: number;
end: number;
retrievalScore: number;
aclVersion: string;
};
type Reranked = Candidate & { rerankScore: number };
type Score = { index: number; score: number };
type ScoreDocuments = (query: string, documents: string[]) => Promise<Score[]>;
async function rerank(
query: string,
candidates: Candidate[],
scoreDocuments: ScoreDocuments,
): Promise<Reranked[]> {
const scores = await scoreDocuments(query, candidates.map((item) => item.text));
return scores
.map(({ index, score }) => ({ ...candidates[index], rerankScore: score }))
.filter((item): item is Reranked => item !== undefined)
.sort((a, b) => b.rerankScore - a.rerankScore);
}
function citation(item: Candidate): string {
return `${item.ticketId}@r${item.revision}#${item.start}-${item.end}`;
}
The endpoint above is an internal boundary, not a product recommendation. In production I would validate that every returned index is in range, reject duplicate chunk ids, and carry the ACL version into the final authorization check. A score without provenance is not evidence.
For a support query such as “refund for a duplicate charge,” the initial search might return 200 chunks. Reranking 200 is already a cost choice; reranking 2,000 for every chat message is a budget leak. Cache normalized queries for a short window, but invalidate that cache when a policy revision changes. A stale answer with a fresh-looking citation is worse than a slower answer.
What belongs in the index, and what stays outside it?
Index the fields that change retrieval: normalized subject, message text, product area, locale, and a coarse timestamp. Keep raw attachments, audit events, and access decisions in durable storage. Attachments can be OCR'd into a separate collection with their own retention rule; stuffing every binary derivative into one index inflates both rebuild time and storage.
Chunk boundaries deserve a test. Split on speaker turns and policy headings before applying a token limit, then retain a small overlap only when a sentence crosses the boundary. Measure answer recall with and without overlap. More overlap raises index cost and can make near-duplicate candidates crowd out distinct evidence.
I once assumed that adding a second embedding field would be a harmless hedge. The bill and rebuild window said otherwise. The better hedge was a 1,000-query evaluation set with labels for “direct answer,” “related context,” and “wrong product.” Your mileage may vary with language mix, but the measurement loop transfers.
Log candidate count, reranker latency, selected citations, ACL rejections, and index bytes per active ticket. Track recall@50 and citation validity separately. A system can retrieve the right ticket yet cite the wrong span; those are different failures. The same ledger works for real-estate listing discovery: record the listing revision and field offsets so a price or address citation can be checked after an update.
| Failure | Symptom | Guardrail |
|---|---|---|
| Revision drift | Citation opens an older policy | Resolve ticketId + revision and retain immutable text |
| Permission leak | Answer quotes a restricted ticket | Recheck ACL after reranking and before generation |
| Duplicate chunks | Many near-identical results | Deduplicate by source span, then diversify by ticket |
| Index bloat | Rebuilds and storage grow faster than tickets | Archive cold revisions and cap attachment derivatives |
| Reranker timeout | Search falls back to random ordering | Set a deadline and return lexical order with a visible trace |
The fallback should preserve evidence fields. If the reranker times out, returning the top lexical candidates with their citations is an honest degradation. Returning an uncited summary is not.
Measure it.
For a rollout, I would freeze a small corpus snapshot and run the same queries through each index build. Compare recall@50, valid-citation rate, bytes per active ticket, and p95 reranker latency. Then change one variable: chunk overlap, candidate count, or an embedding model, never all three at once. A support team can inspect ten failed queries in an afternoon; that is often more useful than a week of aggregate relevance scores because the inspection exposes concrete causes such as a superseded refund policy, a hidden ACL, or a listing whose address moved between revisions. Keep those labels with the evaluation set. When a new index saves bytes but loses the “wrong product” label, the trade-off is visible before it reaches agents.
When is this architecture the wrong fit?
This two-pass design is not suitable when every document must be searched with exact transactional semantics, or when policy changes must be visible within milliseconds across regions. Use a database-native query path for those requirements and treat generation as optional. It is also a poor fit for tiny collections where a full scan is cheaper and easier to reason about.
The trade-off is deliberate: a smaller candidate index lowers recurring cost, while a reranker and provenance store add moving parts. Teams that cannot operate an evaluation set, deadlines, and revision retention should stick with a simpler lexical search and hand-written links. Fancy retrieval without ownership is operational debt.
Don't hide the decision behind a dashboard. Put the budget and freshness target in the design review, then test them against both support tickets and a real-estate listing discovery sample if the same platform will serve both.
The original retrieval-augmented generation paper describes combining a parametric generator with non-parametric memory; citation tracing is the practical bookkeeping that makes that memory inspectable. The exact split, chunk size, and cache window still need measurements from your support corpus.
Top comments (0)