Zenaique

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?

Short answer·Hard·4.0 · 0·~3 min·Asked atOpenAIPhonepeRazorpay·Relevant atAnthropicDatabricks
Attempt it

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.

Free · 2 AI evals / day
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

A $1M/month RAG bill is a real budget conversation, and the CFO's 50% cut with a 1-point faithfulness ceiling is a realistic ask if you sequence the optimizations correctly. The trap is to jump to fixes without profiling, or to ship the highest savings move first and burn weeks of eval risk for a smaller marginal win.

The senior signal is doing the profile, ordering by leverage divided by risk, and tying every change to a measurable check on the golden eval set. This deep dive walks the cost profile, the six highest leverage levers, the order to ship them, and the combined effect within a quarter.

Profile the bill before touching anything

A typical $1M/month production RAG stack breaks down roughly as follows.

  • LLM generation: 50-65%, or $500K-650K/month. Frontier-model token cost on every query.
  • Vector DB: 10-20%, or $100K-200K/month. Storage and read capacity for the index.
  • Reranker: 5-15%, or $50K-150K/month. Cross-encoder calls per query.
  • Embedding API: 5-15%, or $50K-150K/month. Ingest plus query-time embedding.
  • Infra: 5-10%, or $50K-100K/month. Serving, monitoring, networking.

The LLM dominates. Roughly two-thirds of the bill, depending on whether you use a frontier model on every query or already mix tiers. Cost engineering follows the dominant line; chasing the embedding API saves at most 15% even if you cut it to zero, while a 40% cut on the LLM saves 25%+ of the total.

The second observation is that the optimizations interact. Prompt caching reduces LLM token cost; top-k reduction reduces input tokens to the LLM, which reduces what is left for caching to discount. Order the changes so you measure each in isolation against the previous baseline, not against a moving target.

Profiling tools: most cloud providers expose cost per service dashboards; LLM vendors expose per-model token usage; you wire your own cost per query telemetry into the serving layer. Aim for daily resolution before you ship the first optimization.

Lever 1: prompt caching (zero risk, ship in week 1)
Levers 2 and 3: retrieval-side optimizations
Lever 4: generator routing (highest savings, highest validation work)
Levers 5 and 6: caching and self-hosting
Stacking the levers and hitting the CFO's target
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
OptimizationCost savedQuality riskValidation effortShip week
Prompt caching20-40% of LLMnoneshadow A/B1
Top-k reduction10-25% of LLMlow (often improves)faithfulness curve2
Vector quantization50-75% of vector DBlow (reranker recovers)recall@k3-4
Generator routing30-50% of LLMreal, boundedper-tier eval + A/Bmonth 2
Semantic answer cache5-20% of pipelinestalenesshit ratio + freshnessmonth 2
Self-hosted Llama 43-5x on volume tiermodel quality gap4-6 week pilotmonth 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.
Sign in to see more production examples.

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?
A

Train a small XGBoost or distilled BERT model on past traffic, labels from faithfulness scores on each tier. Tune the routing threshold to maximize routing to small model rate subject to the slice level faithfulness eval staying within 1 point. Re-tune monthly as traffic shifts.

3 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

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.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Why profiling comes before any optimization

  • The rough cost breakdown of a typical $1M/month RAG stack

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Which metric best measures whether a RAG answer is grounded in the retrieved context?
MCQ·Medium