Retrieval-augmented generation (RAG) lets a language model answer questions using your own documents by fetching the relevant passages and including them in the prompt. It's a popular architecture, but its cost is spread across several places, and the biggest one isn't the one most teams budget for first.
The three cost components
A RAG system's bill comes from three separate places:
- Indexing — converting your documents into embeddings once (and again whenever they change). This is a one-time or periodic cost that scales with the size of your corpus.
- Query embedding — embedding each user question so it can be matched against the index. It's tiny per query, because questions are short.
- Generation — the language model call that writes the answer from the retrieved context. This is almost always the dominant ongoing cost.
Why generation dominates, and why retrieved context is the lever
Every chunk you retrieve is added to the model's input. Retrieve 5 chunks of 300 tokens each and you've added 1,500 input tokens to every single query — on top of the user's question and your system prompt. Output tokens also cost more per token than input tokens, but it's usually the retrieved context that makes the input side large.
A worked per-query example
The prices below are illustrative, to show the structure of the calculation — substitute your provider's current rates.
Assume input tokens cost $3 per million and output tokens $15 per million. One query sends about 1,750 input tokens (1,500 of retrieved context + 200 of system prompt + 50 for the question) and gets a 300-token answer.
- Input: 1,750 × $3 ÷ 1,000,000 ≈ $0.00525
- Output: 300 × $15 ÷ 1,000,000 = $0.0045
- Total ≈ $0.00975 per query, or about $97.50 a day at 10,000 queries a day
What changing one setting does
Retrieve 3 chunks instead of 5 and the input drops to about 1,150 tokens. The per-query cost falls to roughly $0.00795 — around 18% lower — from a one-line configuration change, and whether answer quality holds up is something you can test directly. That's why the number of chunks retrieved and the chunk size are the first knobs to examine.
Indexing is usually the cheap part
Embedding models are priced far lower than generation models. Embedding a 10-million-token corpus at an illustrative $0.10 per million tokens costs about $1. It only becomes meaningful with very large or very frequently changing corpora — which is why re-indexing only when documents actually change, instead of on a fixed schedule, is a sensible habit.
What's not in the token math
The vector database that stores your embeddings isn't billed per token. Managed services charge for storage and queries, and self-hosting has its own infrastructure cost. Add that to the model costs for a realistic total.
Ways to reduce cost without hurting quality
The usual levers, roughly in order of impact:
- Retrieve fewer or smaller chunks, and test that answers stay good.
- Use a smaller, cheaper model for straightforward questions.
- Keep the system prompt identical between calls so prompt caching can discount it.
- Re-index only when the underlying content changes.
Estimate your own pipeline
Our RAG Cost Calculator takes your corpus size, retrieval settings, and query volume and breaks the estimate into indexing, query embedding, and generation — so you can see which part of your own pipeline is driving the spend.