Bottom line: Generation is roughly a third of a RAG query’s cost. Chunking, embedding, reranking and the index host together are the other two thirds, and they are paid whether or not the answer is good. Model the whole pipeline before promising a price.

Cost per 1,000 queries

Ordinary web corpus, 10k documents, 400 tokens per chunk:

Component Unit cost Per 1,000 queries
Embedding queries $0.02/Mtok $0.01
Vector search (managed) $0.08/1k $0.08
Reranker, 100 candidates $0.80/1k pairs $80.00
Generation, 6k in / 400 out $3 / $15 per Mtok $24.00
Total $104

The reranker dominates. At 20 candidates it drops to $16 and the total to $40 — a 60% cost cut for the 6 NDCG points measured earlier.

One-off indexing

10k documents × 400 tokens = 4M tokens at $0.02/Mtok = $0.08 to embed. Indexing is cheap; re-indexing weekly is cheap; re-indexing on every document edit is where teams quietly lose money. Debounce edits and batch re-embeds.

Where the hidden lines are

  • Chunk overlap. 20% overlap is a 20% tax on embedding and storage forever.
  • Context stuffing. Six chunks at 400 tokens is 2,400 input tokens per query; retrieval that returns ten doubles it.
  • Retry on low confidence. Every retry is a full second pass.
  • Cache misses from timestamped prompts. A timestamp in the RAG template kills caching across the whole pipeline.

The cheap wins, in order

  1. Cut reranker candidates to 20
  2. Enable prompt caching on the static system prompt
  3. Cap retrieved chunks at 5 and rerank before truncating
  4. Cache query embeddings for repeat questions
  5. Only then consider a cheaper generator

Swapping the generator first is the common mistake: the model is a third of the bill, and a cheaper one usually costs an extra retrieval round, which comes straight back.

Unit economics check

At $40 per 1,000 queries and 200k queries/month, that is $8,000. If the product charges $0.02 per query gross, the margin is thin before infra and storage. Run these numbers before pricing, not after — the reranker line surprises people who only ever modelled token cost.

Designing the measurement

Log per stage per query: retrieved, reranked, prompt tokens, cached tokens, output tokens, latency. Cost is a sum over stages and a total without the breakdown cannot be optimised.

1
2
SELECT stage, avg(tokens), avg(usd), count(*)
FROM rag_stage_costs WHERE day = current_date GROUP BY stage;

Run for a week before choosing the generator. The reranker line is usually the surprise, and it is measurable in an afternoon.

Boundary conditions

Chunk overlap multiplies embedding and storage forever — 20% overlap is a 20% permanent tax. Chunk size does the same to prompt tokens. Both are decided once and rarely revisited, which is exactly why they carry the largest hidden cost.

Retrieval count and answer quality are not linear: 20 chunks is often within 3 points of 5 and costs four times the input. Rerank first, then truncate — truncating by retrieval score alone discards the chunks the reranker would have promoted.

Failure triage

  1. Cost per query rising with flat traffic → chunk count or overlap changed, diff the config
  2. Reranker dominant → candidate count; halve it and re-measure NDCG
  3. Cache hit rate near zero → timestamp in the system prompt
  4. Cost fine, quality poor → the generator is not the problem; fix chunking

Rollout

Price the pipeline before pricing the product. At $40 per 1,000 queries and a $0.02 unit price the margin is thin before storage; at $104 it is negative. Put the cost per query on a dashboard next to the quality metric so a model swap that halves cost and drops NDCG 6 points is a visible trade rather than a surprise at month end.

FAQ

How much does it cost to index 10,000 documents?

10k documents at 400 tokens each is 4M tokens, which costs $0.08 to embed at $0.02 per million tokens. Indexing is cheap, and so is re-indexing weekly. Re-indexing on every document edit is where teams quietly lose money, so debounce edits and batch re-embeds.

Why is my RAG cache hit rate near zero?

A timestamp in the RAG prompt template kills caching across the whole pipeline. Removing it is one of the cheap wins, alongside caching query embeddings for repeat questions. Enabling prompt caching on the static system prompt also helps.

Should I swap in a cheaper generator to cut RAG costs?

Only after the other wins. Generation is roughly a third of the bill, and a cheaper model usually costs an extra retrieval round, which comes straight back. Cut reranker candidates to 20, enable prompt caching, cap retrieved chunks at 5, and cache query embeddings first.

How many chunks should I retrieve per query?

Cap retrieved chunks at 5 and rerank before truncating. Six chunks at 400 tokens is 2,400 input tokens per query, and retrieval that returns ten doubles it. 20 chunks is often within 3 points of 5 on quality while costing four times the input.

What is the cost per query if I cut reranker candidates from 100 to 20?

At 20 candidates the reranker drops from $80.00 to $16 per 1,000 queries and the total falls from $104 to $40 — a 60% cost cut, for the 6 NDCG points measured earlier. The reranker dominates the bill, so candidate count is the first cheap win.