Design real AI-powered systems that scale: RAG pipelines, recommendation engines, semantic search, LLM APIs, and evaluation frameworks. Know the trade-offs that interviewers test.
Use this exact structure in any AI system design interview. It signals you think like an engineer, not just a researcher.
| Component | Bottleneck | Solution |
|---|---|---|
| Embedding | GPU cost at scale | Batch embed, smaller model (e5-small) |
| Vector search | Latency at 100M+ vectors | HNSW with proper ef_search |
| LLM generation | Cost + latency | Semantic cache, smaller model for simple Qs |
| Context window | Too many chunks | Re-rank, limit to top-3 |
Neither keyword nor semantic alone is best. Combine them:
k=60 is a common default. This is robust and doesn't require tuning per-query weights.
Route queries to cheaper models when possible:
| Approach | Latency | Cost (high QPS) | Privacy | When to Use |
|---|---|---|---|---|
| OpenAI/Anthropic API | 2–10s | High | Data leaves org | Prototyping, low volume, general tasks |
| Self-hosted (vLLM) | 0.5–3s | Low at scale | Full control | High QPS, sensitive data, cost optimization |
| Fine-tuned + served | 0.2–1s | Lowest | Full control | Domain-specific, latency-critical |
| Quantized (4-bit) | Fast | Very low | Full control | Edge deployment, memory-constrained |
Before shipping. Use golden test set (human-labeled Q&A pairs).
| Metric | What It Measures |
|---|---|
| RAGAS Faithfulness | Answer grounded in retrieved context? |
| RAGAS Answer Relevance | Answer addresses the question? |
| BLEU / ROUGE | Text similarity (weak proxy) |
| LLM-as-judge | GPT-4 scores outputs 1–5 |
| Human eval | Gold standard, slow |
| What to Monitor | Signal | Action |
|---|---|---|
| Input data drift | Query embedding distribution shifts | Re-embed and re-index docs |
| Retrieval quality | Avg similarity score of retrieved chunks drops | Tune chunking or embedding model |
| LLM errors | Rate of 4xx/5xx from provider | Fallback provider, retry logic |
| Latency P95 | Spikes > SLA | Check cache hit rate, queue depth |
| Cost per query | Token usage trending up | Shorten prompts, downgrade model |
| Hallucination rate | LLM-judge scores decline | Add retrieval grounding, stricter prompt |
| User thumbs down | Spike in negative feedback | Sample + human review bad examples |