Your production RAG costs $1M/month. The CFO wants this cut in half with a max 1-point faithfulness regression. What highest leverage cost optimizations do you deploy, in priority order?
Production RAG cost is $1M/month. Quality budget: faithfulness can drop at most 1 point. Walk through the highest leverage cost optimizations in priority order. For each, name the expected cost reduction, the quality risk, and how you'd validate the change before rolling it out.
Profile first; the LLM eats 50-65% of cost. Ship in order: prompt caching, top-k reduction, vector quantization, generator routing, semantic cache, self-hosted Llama. Gate each change on the eval set.
Think of your RAG bill like a household budget. Before you cut anything, you figure out where the money actually goes. In most homes the rent or mortgage is the biggest line item; in RAG, it is the smart-AI call that writes the answer. Once you know that, you attack the biggest bills first, but you start with the changes that cannot hurt quality: turn on the discount card the AI provider already gives you, send shorter shopping lists, and shrink your storage closet. Only then do you try the riskier moves, like using a cheaper helper for easy questions or running your own AI on your own machines. After each change, you check that the answers are still as honest as before. If they slip more than a tiny bit, you back the change out.
Detailed answer & concept explanation~9 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
11 min: walk the profile, defend the ordering, give expected savings and validation for each of the six levers, and close with the 40-55% combined estimate.
| Optimization | Cost saved | Quality risk | Validation effort | Ship week |
|---|---|---|---|---|
| Prompt caching | 20-40% of LLM | none | shadow A/B | 1 |
| Top-k reduction | 10-25% of LLM | low (often improves) | faithfulness curve | 2 |
| Vector quantization | 50-75% of vector DB | low (reranker recovers) | recall@k | 3-4 |
| Generator routing | 30-50% of LLM | real, bounded | per-tier eval + A/B | month 2 |
| Semantic answer cache | 5-20% of pipeline | staleness | hit ratio + freshness | month 2 |
| Self-hosted Llama 4 | 3-5x on volume tier | model quality gap | 4-6 week pilot | month 3-4 |
Real products, models, and research that use this idea.
- Anthropic's prompt caching docs show 90% cost reduction on cached tokens, with a 5-minute default cache window suitable for RAG system prompts.
- OpenAI's prompt caching auto-caches repeated prefixes and is documented to cut cost 50% on cached portions.
- Pinecone serverless tiering moves cold vectors to cheaper storage automatically, often cutting vector DB cost 60-80% for large corpora.
- Anthropic Claude 4.7 contextual retrieval reduces the effective top-k needed because each chunk carries its own context, often dropping prompt size 30-40%.
- Self-hosted Llama 4 on B200 clusters with vLLM achieves 3-5x cost per token savings vs hosted APIs at sustained 100K+ TPS.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you build the generator router classifier, and how do you tune its threshold against the 1-point faithfulness budget?
QHow do you decide when to switch from API to self-hosted Llama 4?
QWhat is the right TTL for semantic answer caching, and how do you invalidate on corpus updates?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Jumping to fixes without profiling. If you do not know the cost breakdown, you optimize the wrong layer. The LLM dominates; embedding cost is rarely worth chasing first.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.