Build a RAG-Powered Voice Assistant with Grounding Guarantees
Machine LearningModel answerLast updated
Design a retrieval-augmented voice assistant that answers from a trusted knowledge base under a 500ms latency budget while minimizing hallucinations.
The Problem
Your team is building a voice assistant for a product support platform. Instead of letting the underlying language model answer from its training weights, every response must be grounded in a curated internal knowledge base — think product documentation, support articles, and how-to guides. Your job is to design the end-to-end system.
Functional requirements
- Users can have multi-turn conversations. References like "the one you just mentioned" or "does it also apply to the older model?" must resolve correctly.
- The system retrieves supporting passages before generating any answer.
- A verification step confirms that what the assistant says is actually supported by the retrieved content.
- When the knowledge base cannot support an answer, the assistant must say so explicitly rather than guess.
Non-functional requirements
- Latency: the user must hear the first word within 500ms of finishing their utterance.
- Hallucination budget: fewer than 2% of generated claims should be unsupported by retrieved sources.
- Freshness: source documents update daily; the index must reflect changes within minutes to a few hours.
Scale
- Knowledge base: 1 million documents.
- Traffic: 10,000 queries per second (QPS) average, ~2.5× at peak.
What to cover
- Retrieval pipeline — embedding strategy, index design, hybrid retrieval, and reranking.
- Multi-turn handling — how context from prior turns feeds into retrieval.
- LLM integration — how you structure the prompt and enforce grounding rather than hoping the model behaves.
- Verification layer — how you check grounding without blowing the latency budget.
- Evaluation — how you measure groundedness, abstention quality, and retrieval accuracy in production.
- Trade-offs — where you sacrifice retrieval depth or answer completeness to meet the latency constraint.
No need to write production code. A clear architecture with concrete component choices, a latency breakdown that sums to under 500ms, and honest discussion of where things can fail is what a strong answer looks like.
Hints
Hint 1
Start by decomposing the 500ms budget across every stage — ASR, retrieval, reranking, generation, verification, and TTS. Showing that the numbers add up is half the answer.
Hint 2
Multi-turn retrieval quality lives or dies on query rewriting. A bare embedding of 'does it work with the older one?' retrieves almost nothing useful. Think about what must happen before the first vector search call.
Hint 3
Verification and latency are in direct tension. The insight that unlocks both is that you don't have to verify the whole answer before speaking — think about what the unit of verification can be.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Approach
This is fundamentally a latency-constrained pipeline design problem. The 500ms budget is tight enough that every component choice either earns its place or gets cut. A strong answer commits to numbers early, explains why each component is necessary, and identifies the two or three places where the design could fail.
1. Clarify before designing
A few things to nail down first:
- Where does the 500ms clock start? It starts when ASR detects end-of-speech. ASR is streaming during the utterance, so it sits mostly off the critical path.
- Chunk size? At roughly 300 tokens per chunk, 1M documents yields around 10M chunks. At 768-dimensional float16 embeddings that's ~15GB raw, or 2–4GB with product quantization — fits in memory on a modest sharded cluster.
- What counts as a hallucination? A claim in the response that cannot be traced to a retrieved passage. Abstaining is always preferable to guessing.
2. Latency budget (critical path)
| Stage | Component | Target |
|---|---|---|
| Query rewrite | Small LLM (~1B params) | 40ms |
| Hybrid retrieval | BM25 + ANN in parallel | 30ms |
| Reranking | Distilled cross-encoder | 60ms |
| Answerability gate | Score threshold classifier | 5ms |
| LLM generation (first sentence) | Distilled 7–8B, prefill ~3k tokens | 180ms |
| Sentence verification | NLI entailment model | 40ms |
| TTS (first sentence) | Streaming synthesis | 80ms |
| Total | ~435ms |
This leaves ~65ms of headroom for network and scheduling jitter.
3. Multi-turn query rewriting
This is the most commonly underestimated component. Raw utterances like "what about the pro version?" are useless as retrieval queries. Before any search happens, a small rewriter LLM resolves coreferences and reformulates the query into a self-contained question — e.g., "Is the AirPods Pro 2 compatible with iOS 16?" — using the last N turns stored in a Redis session keyed by session_id.
Evaluate this stage independently. Retrieval quality on multi-turn conversations is almost entirely determined here, so it deserves its own recall metric.
4. Hybrid retrieval
Use both dense and sparse retrieval in parallel, then fuse the results.
- Dense (ANN): embeddings fine-tuned on in-domain (query, clicked article) pairs with hard negatives mined from BM25. HNSW or IVF-PQ index, sharded across 4–8 nodes and replicated for throughput. Returns top-100 by cosine similarity.
- Sparse (BM25): Elasticsearch or Lucene. Strong on exact tokens — model numbers, error codes, setting names — where dense retrieval is notoriously weak.
- Fusion: Reciprocal Rank Fusion (RRF) merges the two ranked lists without requiring score calibration.
Apply metadata filters (product, version, locale) at query time to keep retrieved chunks relevant and reduce the reranker's job.
Serving 10k QPS: the ANN index shards handle throughput. The cross-encoder reranker on 50 pairs per query equals 500k pair classifications per second — roughly 20–40 A10-class GPUs running batched inference. Budget for this upfront.
5. Enforcing grounding in the LLM
Prompting alone is not enough. You need two things working together:
Structured context. Format each retrieved chunk as [S1] (Manual: Product X > Battery, updated 2024-09) <chunk text>. The model sees labeled, attributed sources.
Fine-tuning on abstention. Instruct the model to cite [S#] after every sentence and emit a fixed abstention token when the sources don't cover the question. Critically, include distractor-only contexts in fine-tuning data — cases where the retrieved chunks look plausible but don't actually answer the question. Without these examples, models reliably over-answer.
Voice style constraint. Cap output at 1–3 short sentences, most important fact first. Shorter outputs generate faster, are easier to verify, and are less likely to stray beyond what the sources support.
Two abstention gates:
- Pre-generation: if the top reranker score is below a calibrated threshold, skip the LLM entirely and return a canned "I don't have that information" response. This is the cheapest and most reliable safety net.
- Post-generation: the verifier rejects unsupported sentences.
6. Verification without blowing the budget
The naive approach — verify the full answer, then speak — doesn't fit in 500ms. The unlock is sentence-level gated streaming:
- Stream LLM tokens. When a sentence boundary is detected, extract the sentence and its cited chunk IDs.
- Run an entailment model (fine-tuned DeBERTa or a distilled verifier trained on LLM-judge labels) to score P(supported | cited chunks).
- Route by score:
- Pass: send to TTS immediately.
- Fail on sentence 1: fall back to abstention or a templated response pointing to the source article.
- Fail on a later sentence: drop it and close the answer naturally.
Verification of sentence k overlaps with generation of sentence k+1, so only the first check is strictly on the critical path. For high-stakes query classes where you need stronger verification (Chain-of-Verification, ~2–4 extra LLM calls), play a short audio earcon ("Let me check on that…") to buy ~500ms more without feeling broken.
7. Caching
Head-heavy workloads like product support see 30–50% cache hit rates on normalized queries. Cache both retrieval results and generated answers, keyed on (rewritten query, product, locale). Invalidate by doc_id when source content updates so cached answers stay grounded in current documents. Also apply KV/prefix caching for the system prompt across all generation calls.
8. Evaluation strategy
Offline:
- Retrieval: Recall@k and nDCG on a labeled (query, gold chunk) set, including multi-turn conversations.
- Groundedness: claim-level precision — decompose answers into atomic claims, check each against sources (FActScore / RAGAS faithfulness). Use a strong LLM judge calibrated against ~1–2k human labels; report inter-rater agreement.
- Abstention quality: build an unanswerable test set. Measure false abstention rate (good questions the system refused) alongside hallucination rate. Optimizing only for hallucinations inflates abstentions; track both.
Online:
- Implicit signals: barge-in rate, rephrase rate, session abandonment.
- Explicit signals: thumbs up/down.
- Shadow the verifier against a stronger offline judge to catch drift in grounding quality before it affects users.
Common mistakes to avoid
- Embedding raw multi-turn utterances. The rewriter is not optional; skipping it tanks retrieval recall on anything past turn one.
- Prompting for grounding without fine-tuning. Instruction-tuned models will hallucinate plausibly even when told not to. Fine-tuning on abstention examples is necessary.
- Verifying the whole answer before streaming. This adds hundreds of milliseconds and breaks the latency budget. Sentence-level streaming verification is the right model.
- Ignoring the cost of the cross-encoder at scale. 10k QPS × 50 pairs is a lot of GPU. Size this out explicitly; it's often the most expensive component after generation.