RAG Query Cost and Latency Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

Introduction: RAG query pipeline cost and latency estimates

A retrieval-augmented generation (RAG) request typically retrieves relevant documents or chunks from a vector database, adds that context to an LLM prompt, and generates a final answer. This calculator estimates the cost and latency of that RAG serving path from the workload, pricing, retrieval, cache, and index-refresh inputs you provide.

Use the RAG estimates for planning monthly spend, testing the value of a higher answer-cache hit rate, comparing model or vector-store assumptions, and identifying whether tokens, retrieval fan-out, retrieval timing, or model time is driving the result. The latency figures are simplified average-style estimates rather than service-level guarantees.

RAG inputs explained (units and how they’re used)

These inputs describe the request volume, token usage, retrieval work, caching behavior, and index maintenance costs of the RAG pipeline.

Formula: RAG query cost model

The RAG monthly cost model combines model inference, vector reads, and recurring embedding refresh. Per-query amounts are calculated by allocating the monthly embedding cost across Q queries where applicable.

1) RAG LLM cost

For each uncached RAG request, billable model tokens are approximated as P + R. With one blended price per 1K tokens (M):

LLM cost per query:

Cllm = (P+R)M 1000

2) RAG vector read cost

Each uncached RAG query triggers F retrievals. If the vector store charges V dollars per 1,000 retrievals:

Vector cost per query:

C_vector = (F × V) / 1000

3) RAG embedding refresh amortization

A RAG index also has a recurring maintenance cost when new or changed content is re-embedded. With E documents, T tokens per document, and a monthly refreshed fraction D:

To compare index upkeep with serving cost, the calculator spreads this monthly RAG embedding cost across monthly queries Q:

Embedding refresh cost per query:

C_embed = (E × T × D × p) / (1000 × Q)

Cold-cache vs warm-cache RAG cost

For RAG answer caching, this calculator treats a cache hit as avoiding both retrieval and LLM inference because a stored final answer is returned. Under that simplifying assumption:

Embedding refresh remains in both RAG scenarios because maintaining the index is modeled independently of answer-cache performance.

RAG retrieval and generation latency model

This RAG latency estimate adds base LLM time to linear retrieval time, using the requested fan-out and per-retrieval latency.

Production cached answers still have routing, lookup, and network overhead. To represent part of that overhead in this model, use a lower effective cache hit rate rather than assuming every hit removes the full cold-path time.

How to use: RAG cache cost worked example with the default inputs

This RAG example uses the page defaults: Q=100,000, P=800, R=600, M=$0.003, F=8, h=0.35, L_r=45ms, L_llm=700ms, V=$0.15, p=$0.0001, E=250,000, T=750, and D%=20 (therefore D=0.20).

Cold RAG cost/query is approximately 0.0042 + 0.0012 + 0.0000375 = $0.0054375 (~$0.0054), implying monthly cold serving of approximately $543.75.

Warm RAG cost/query at 35% answer-cache hits is approximately (1−0.35)×(0.0042+0.0012) + 0.0000375, or $0.0035475 (~$0.00355). The resulting monthly warm serving estimate is approximately $354.75.

Cold RAG latency is approximately 700 + 8×45 = 1060ms. Under the simplified cache-hit treatment, warm latency is approximately 0.65×1060 = 689ms. In this example, base LLM time is the larger latency component, model tokens are the larger serving-cost component, and embedding refresh is small per query because it is allocated across a high query volume.

How to interpret RAG cost and latency results

Read the RAG results by separating variable request-path expense from the index-refresh cost that is allocated across the month.

Scenario comparison: RAG caching and retrieval fan-out levers

The RAG scenario table identifies operational changes that affect the calculator’s cost and latency inputs; the displayed Optimized row applies only the built-in cache and fan-out changes described below.

Lever What you change Primary impact Secondary effects / notes
Increase cache hit rate (h) Better cache keys, longer TTLs, semantic caching Reduces modeled serving cost and latency on cached queries Embedding refresh is not reduced by caching in this model
Reduce prompt tokens (P) Smaller context, better chunking, tighter instructions Reduces RAG model cost and often model time Context that is too small can reduce answer quality
Reduce fan-out (F) Tighter filtering, reranking, better embeddings Lowers vector-read cost and linear retrieval latency It can also lower prompt tokens when fewer passages are included
Lower LLM latency (L_llm) Faster model, lower maximum output, higher throughput Directly lowers the modeled generation component Model price per 1K tokens (M) and answer quality may also change
Lower refresh rate (D%) Refresh only changed documents with incremental pipelines Lowers embedding-refresh overhead Freshness requirements may limit how far this can be reduced

The calculator’s Optimized scenario raises the entered cache hit rate by 0.20, capped at 0.95, and sets fan-out to 80% of the entered value, with a minimum of one retrieval. It leaves token counts, model price, embedding refresh, base LLM latency, and per-retrieval latency unchanged, so treat it as a narrow cache-and-retrieval what-if rather than a complete architecture recommendation.

Assumptions and limitations of this RAG serving model

This RAG calculator intentionally uses a compact model, so its estimates should be calibrated against observed production traces and invoices.

RAG pricing and timing sourcing note

For a usable RAG estimate, enter current provider pricing for M and p, vector-database pricing for V, and measured production values for L_r and L_llm. Sampling real request traces and running the calculator separately with p50 and p95 timing inputs provides a more informative planning range than relying on one average.

Arcade Mini-Game: RAG Query Cost and Latency Calculator Calibration Run

Use this quick arcade run to practice separating useful scenario inputs from common planning mistakes before you rely on the calculator output.

Score: 0 Timer: 30s Best: 0

Start the game, then use your pointer or arrow keys to catch useful inputs and avoid bad assumptions.

Enter workload characteristics to compute cost and latency outcomes for your retrieval augmented generation pipeline.
Scenario Cost / Query Monthly Cost Latency (ms)
Cold cache $0 $0 0
Warm cache $0 $0 0
Optimized $0 $0 0