RAG vs Long-Context: Cost & Latency Tradeoff

Should you use a 1M-token long-context model or build a RAG pipeline?

Compare total cost and latency of a RAG pipeline (embedding index plus a small retrieved context per query) against always stuffing your whole corpus into a long-context model like Gemini 1.5 Pro. Runs entirely in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

When is long-context cheaper than RAG?

Long-context wins when your corpus is small (a few thousand tokens) or your query volume is very low, so the saved engineering and infrastructure of RAG is not worth it. Above a few hundred thousand tokens of corpus at meaningful query volume, RAG is almost always far cheaper because you only pay for the small retrieved slice each call.

RAG vs long-context cost calculator

Long-context models can hold hundreds of thousands or millions of tokens in a single prompt, which makes a tempting shortcut: skip the vector database and just paste your whole corpus into every request. That convenience has a cost — you pay for the entire corpus on every single query. This tool puts that number next to the cost of a RAG pipeline so you can decide with arithmetic instead of intuition.

How it works

Two strategies are priced over a 30-day month:

  • Long-context: every query sends the full corpus as input. Monthly cost is corpus_tokens × price_per_token × queries_per_day × 30. There is no indexing cost, but the per-query input is enormous.
  • RAG: a one-time embedding pass over the corpus (corpus_tokens × embed_price), then each query sends only the retrieved chunk (retrieved_tokens × query_price). Monthly cost is the amortized embedding plus retrieved_tokens × query_price × queries_per_day × 30.

Latency is modelled as a function of input size: long-context pays a per-token processing cost on the whole corpus, while RAG pays a fixed retrieval overhead plus processing of only the retrieved slice.

The intuition behind the cost gap

The core dynamic is multiplication. With long-context, the corpus cost multiplies with every single query. If you have a 500,000-token corpus and run 1,000 queries per day, you are paying for 500 million input tokens per day — every day. RAG pays for those 500,000 tokens once (the embedding pass), then pays for perhaps 2,000–4,000 tokens per query (the retrieved chunks). At meaningful query volume, the difference is typically an order of magnitude or more.

The crossover happens when the engineering overhead of RAG — the vector database, the embedding pipeline, the retrieval tuning, the reranking — costs more than the token savings justify. For a corpus of a few thousand tokens and low query volume, long-context can be the rational choice simply because there is nothing to build.

Latency: the second dimension

Long-context models have high time-to-first-token because every token in the context must be attended to before the model generates the first output token. A 200,000-token context is inherently slower than a 3,000-token one. RAG adds a small, predictable retrieval step — a vector search is typically tens of milliseconds — but the subsequent generation call processes far fewer tokens and returns faster.

For interactive applications with strict latency budgets, RAG often wins on speed as well as cost once the corpus exceeds a certain threshold. The exact threshold depends on the model and infrastructure, which is why this tool lets you tune the numbers for your situation.

What this calculator does not include

The comparison here is between token costs only. Real RAG deployments have additional costs that the calculator omits:

  • Vector database: managed services like Pinecone, Weaviate Cloud, or pgvector on a hosted Postgres have their own pricing based on vectors stored and queries served
  • Reranking: a cross-encoder reranker can improve retrieval quality significantly but adds an extra model call per query
  • Embedding refreshes: if your corpus updates frequently, the corpus must be re-embedded, which adds periodic cost
  • Engineering time: building and maintaining a RAG pipeline has an ongoing maintenance cost that long-context does not

For small corpora or early prototypes, these hidden costs may easily exceed the token savings — which is exactly when long-context is the pragmatically correct architecture choice, even if it looks expensive on a per-token basis.

Illustrative example

Suppose you have a 300,000-token internal knowledge base and handle around 500 queries per day:

  • Long-context: 300,000 tokens × 500 queries = 150 million input tokens per day. At even a modest per-token rate, this compounds quickly into a significant monthly bill.
  • RAG: a one-time embedding of 300,000 tokens (paid once), then approximately 2,000 retrieved tokens per query × 500 queries = 1 million input tokens per day — roughly 150× less daily token consumption.

Enter your actual corpus size, query volume, and token prices into the calculator to see the precise crossover for your workload.