HorizonLux · RAG

Retrieval that answers well and bills quietly

Most RAG systems retrieve several times more than the answer needs. We fix the chunking and retrieval decisions behind that.

Get a cost review
Guides

RAG Cost Optimization: Where Retrieval Spend Actually Goes

RAG cost optimization in practice. Why top-k times chunk size decides your bill, what embedding and storage really cost, and when long context is cheaper.

Three RAG cost centres shown as blocks, with generation far larger than embedding and vector storage

TL;DR

RAG cost is decided by two numbers multiplied together: how many chunks you retrieve, and how big each chunk is. Everything else is rounding. Retrieve twenty 512-token chunks and you have sent roughly 10,000 input tokens before the system prompt, on every single question, forever.

The part teams miss is that RAG has three separate cost centres, and only one of them scales with traffic. Embedding is mostly a one-off, vector storage is a fixed monthly floor that bills on a quiet month exactly as it does on a busy one, and generation is the per-query line that dominates almost every real bill.

The reflex fix for expensive retrieval, cutting top-k, is also usually the right one, and it tends to make answers better rather than worse. The relevant passage stops competing with fifteen near-misses.

Retrieval that answers well and bills quietly? We make chunking, top-k and caching decisions on measured evidence rather than framework defaults. See how we build AI systems that hold up on the invoice.

Key Takeaways

  • Top-k multiplied by chunk size sets the input tokens on every query. Halving either roughly halves generation cost.
  • Generation is typically the overwhelming majority of a RAG bill; embedding and storage are small but fixed.
  • Cutting from twenty chunks to five commonly saves 60% or more, and frequently improves answer quality.
  • Chunk overlap is charged twice over: it inflates embedding tokens and vector count together.
  • Rerankers bill per search, not per document, and chunks over ~500 tokens are auto-split so each piece counts.
  • Long context costs one to three orders of magnitude more per query than retrieval, until prompt caching narrows it.

The three cost centres of a RAG pipeline

The cost of a RAG pipeline is almost always quoted as one number. It is three, and they behave completely differently, which is why teams model one of them and get surprised by the other two.

Cost centre When it bills Scales with Typical share
Embedding cost Once at ingest, then on churn Corpus size and overlap Small, often cents
Vector search and storage Every month, regardless of traffic Number of vectors Small but fixed
Generation Every query top-k x chunk size The overwhelming majority
Reranking Every query, if used Searches, not documents Small unless misconfigured

The consequence worth internalising: a RAG system has a floor. If your traffic halves, your bill does not, because storage and any always-on infrastructure bill the same. That is a different shape from an agent, where cost is almost entirely variable, and it changes how you should think about a quiet month.

Three RAG cost centres drawn to scale, with generation dwarfing embedding and storageThree blocks representing the monthly cost centres of a retrieval pipeline, drawn in proportion. Embedding is a very small block, billed once at ingest and then only as documents change. Vector storage is a small block that bills every month regardless of how much traffic the system receives. Generation is an enormous block beside them, because every query sends top-k chunks through the model, and it is the only one of the three that scales with traffic. The visual point is that the two cost centres teams forget are the small ones, while the one they can most easily control is the one that dominates the bill.Three cost centres, drawn to scaleembeddingonce, then on churnvector storageevery month, traffic or notgenerationtop-k x chunk size, every querythe only one that scales with trafficThe two you forget are small. The one you control is the whole bill.
Proportions from a typical mid-size corpus at meaningful query volume. Your split will differ; the shape rarely does.

Why top-k times chunk size is the whole game

Here is the arithmetic that decides a RAG bill, and it fits on one line:

input tokens per query = system prompt + (top-k x chunk size) + question

That product is your RAG token usage, and it is the number worth putting on a dashboard.

With a 400-token system prompt, top-k of 20 and 512-token chunks, that is roughly 10,700 input tokens per question. The user typed maybe fifteen words. Everything else is retrieved context, and you pay for all of it whether the model uses it or not.

Two things follow, and the second one surprises people:

  • The corpus size barely matters for per-query cost. Ten thousand documents or ten million, you still send top-k chunks. Corpus size drives embedding and storage, which are the small lines. This is exactly backwards from most people's intuition.
  • Cutting top-k is nearly free quality-wise, and often positive. The relevant passage is usually in the top few results. Chunks six through twenty are mostly near-misses that dilute attention and give the model more opportunity to cite the wrong thing.
Input tokens sent per query at increasing values of top-kSix bars showing the input tokens sent on every query as top-k rises, using 512-token chunks with a 400-token system prompt and a short question. At a top-k of three the query sends roughly two thousand tokens. At five it sends about three thousand. The bars climb steadily to roughly ten thousand seven hundred tokens at a top-k of twenty, which is a common framework default, and to nearly sixteen thousand at thirty. The relationship is linear, so every additional chunk retrieved costs the same again on every question the system ever answers. The first few chunks usually contain the answer, which is why the common default sits far to the right of where the useful information is.Input tokens per query, by top-k2.0Kk=33.0Kk=55.6Kk=108.1Kk=1510.7Kk=2015.8Kk=30the answer is usually in herecommon defaultLinear, and charged on every question the system will ever answer.
512-token chunks, 400-token system prompt. Each extra chunk costs the same again, forever.

Put your own corpus and traffic in and the calculator will split the bill three ways and price the top-k change specifically.

Usually the biggest lever in the whole system.

Questions answered, not chunks fetched.

Multiplies with top-k on every single query.

Refine the inputs

Drives re-embedding.

Monthly
$997.58
$0.00998 per query · 22.5K vectors
0.2% is fixed cost that bills whether or not anyone asks a question.
Plus $0.230 once, to embed the corpus.
vs stuffing the corpus in context
80xmore per query
$0.802 vs $0.00998
With prompt caching on a stable corpus it narrows to 8.2x, which is where it becomes a real decision.
Open the full calculator

Where the money goes

RAG has separate cost centres, and only one of them scales with traffic. Embedding and storage bill the same on a quiet month.

generation$996.00 · 99.8%
storage$1.57 · 0.2%
embedding$0.012 · 0.0%

What each change is worth

Each figure is this model re-run with that one input changed. They are not additive.

  1. Retrieve 5 chunks instead of 20saves $614.40/mo
  2. Halve the answer lengthsaves $70.00/mo
  3. Halve the chunk overlapsaves $0.103/mo

Chunk size: the setting that moves everything

Chunk size looks like a retrieval-quality knob. It is also a cost knob, and it pulls in more than one direction at once.

Smaller chunks send fewer tokens per retrieved result, which lowers generation cost proportionally at a fixed top-k. But they produce more chunks overall, which raises vector count and storage, and they carry less context each, which can push you to raise top-k to compensate. Raise top-k by the same factor you cut chunk size and you have saved nothing.

Larger chunks send more tokens per result and cost more per query, but each result carries more context so a lower top-k often suffices.

The number to optimise is neither one alone. It is tokens sent per query, which is the product. Tune for the smallest product that still answers correctly, and check the answer quality rather than assuming.

One easily-missed detail: chunk overlap is charged twice. Overlapping text is embedded more than once and stored more than once, so a 20% overlap raises both embedding tokens and vector count by 20%. Those are the cheap lines, so it rarely matters much, but it is pure waste if the overlap is not earning better retrieval.

Reranking: priced per search, not per document

This one catches teams out because the pricing model does not work the way the mental model does.

Rerankers bill per search, where a search is one query plus up to roughly 100 documents. That makes reranking cheap in the normal case: a hundred thousand queries against a 50-candidate set is one search each, so a hundred searches per thousand queries.

Two things quietly multiply it:

  • A candidate set above 100 documents costs more than one search. Fetching 150 candidates is two searches, not one and a half.
  • Chunks longer than about 500 tokens are automatically split, and each piece counts as its own document. So raising chunk size from 400 to 600 tokens can double your rerank bill without changing a single other setting, because 50 candidates suddenly count as 100 documents.

The strategic point: a reranker only earns its cost if it lets you send fewer chunks to the model. Fetch fifty candidates, rerank, send the best four, and you have traded a small fixed cost for a large generation saving. Fetch fifty, rerank, and still send twenty, and you have added cost for nothing.

RAG vs long context

The RAG vs long context cost question is the one that keeps coming back, and it deserves a real answer rather than a slogan.

Now that context windows run to hundreds of thousands of tokens, the obvious question is whether retrieval is still worth the machinery. Why not send the whole corpus every time?

The measured answer is that retrieval is dramatically cheaper per query. Research comparing the two architectures on document-grounded generation found long-context prompting processing around 247,000 input tokens per query against roughly 8,500 for retrieval, with the cost difference landing at more than an order of magnitude and, in the extreme, around three. Latency follows the same shape: tens of seconds against roughly one.

Input tokens per query for retrieval, long context, and long context with cachingThree horizontal bars comparing input tokens sent per query. Retrieval sends a very short bar, roughly eight and a half thousand tokens, because only the top few chunks travel. Long context sends an enormous bar, roughly two hundred and forty seven thousand tokens, because the entire corpus is placed in the window on every query. A third bar shows long context with prompt caching: the same volume of tokens travels, but the stable corpus prefix bills at about a tenth of the input rate, so the effective cost falls close to the retrieval bar without the retrieval machinery. The comparison shows retrieval winning decisively on raw cost, while caching turns the choice into a genuine trade-off for corpora that rarely change.Input tokens billed per queryretrieval~8,500 tokenslong context~247,000 tokens, the whole corpus, every questionlong context, cachedsame tokens, billed at about a tenthCaching is what turns an obvious answer back into a real decision.
The middle bar is why retrieval exists. The bottom bar is why the question keeps coming back.

But prompt caching changes the arithmetic, and this is the part most comparisons omit. If your corpus is stable, the stuffed context is a fixed prefix, which is exactly what caching is for. Cached tokens bill at roughly a tenth of standard input price, so long context stops being absurd and becomes merely expensive.

That makes it a real decision rather than an obvious one:

Your situation Likely right answer
Corpus larger than any context window Retrieval. There is no choice to make.
Large corpus, high query volume Retrieval. The per-query gap compounds.
Small stable corpus, moderate volume Long context with caching. Skip the machinery.
Small corpus that changes constantly Retrieval. Churn destroys the cache hit rate.
Answers must cite exact sources Retrieval. You get provenance for free.

The honest summary: retrieval wins on cost at scale and wins on provenance always, while long context plus caching is genuinely competitive for a small corpus that does not change. Anyone telling you one of these always wins is selling something. The caching mechanics and break-even math are in our prompt caching guide.

When retrieval feeds an agent

One combination deserves a warning, because the two cost structures multiply rather than add.

If retrieval happens inside an agent loop, every step retrieves and every step re-sends everything the previous steps retrieved. A twelve-step agent doing retrieval at each step is not paying twelve times the retrieval cost. It is paying retrieval cost per step plus the accumulated weight of all previously retrieved chunks travelling again on every subsequent step.

Two rules keep it under control. Retrieve once per task where you can, not once per step. And drop retrieved chunks from the transcript once they have been used, rather than carrying them for the rest of the run. The compounding arithmetic behind that is in AI agent costs.

How we approach retrieval cost at HorizonLux

HorizonLux is a software development company specialising in AI, and RAG systems are a large share of what we build, so these are working defaults rather than recommendations we have read about.

  • Top-k is tuned against measured answer quality, not set to the framework default and forgotten. We look for the point where quality starts to degrade, then step back one, and that number is almost always lower than teams expect.
  • Chunking is costed before it ships. Tokens sent per query is a design output, not something discovered from the first invoice.
  • Retrieval inside agent loops is treated as a red flag until someone can say why it must happen per step rather than once per task.
  • The system prompt is ordered for caching from the first commit, stable content first, retrieved chunks last, so caching remains available even if we do not enable it on day one.
  • The three cost centres are tracked separately. A rising bill that is storage means something completely different from a rising bill that is generation.

What to do this week

  • Print your actual input tokens per query. System prompt plus top-k times chunk size. If it is over 10,000 for a question a human could answer from one paragraph, you have found your problem.
  • Halve top-k on a copy and run your evaluation set. Compare answer quality honestly before assuming it got worse.
  • Check whether your reranker changed your top-k. If it did not, it is cost without benefit.
  • Check your chunk size against 500 tokens if you rerank, because crossing that line silently doubles the document count.
  • Decide RAG versus long context on your actual corpus size and churn, not on which is fashionable.

Retrieval is one of the cheapest architectures available for grounding a model in your own data, and most systems still overpay for it by a factor of three or four. Almost all of that is one number set too high on the first day and never revisited. The wider sequence this fits into is our guide to LLM cost optimization, and if you are still working out which part of your stack is responsible, start with why is my AI bill so high.

Want retrieval that holds up on quality and on cost? We design the chunking, retrieval and caching decisions together, because changing one moves the others. See how we approach AI development, or tell us what your invoice looks like.

Frequently asked questions

What is RAG cost optimization?

RAG cost optimization is reducing what a retrieval pipeline spends without reducing answer quality. In practice it concentrates on one product: top-k multiplied by chunk size, which sets the input tokens on every query. Secondary levers are chunk overlap, which inflates embedding and storage, reranking configuration, and answer length. Corpus size matters far less than most teams assume, because it drives only the small fixed lines.

What drives the cost of a RAG pipeline?

Generation dominates almost every real bill, because each query sends top-k chunks through the model. Embedding is mostly a one-off at ingest plus a smaller ongoing cost as documents change, and vector storage is a fixed monthly amount that bills whether or not anyone asks a question. A rough rule: if your bill moves with traffic it is generation, and if it does not, it is storage.

How do I reduce RAG costs without hurting answers?

Cut top-k first. Most systems retrieve several times more than the answer needs, and reducing it usually improves answers because the relevant passage stops competing with near-misses. Then check tokens sent per query, cap answer length, and make sure any reranker is actually letting you send fewer chunks. Only after that is it worth changing embedding models or vector stores.

Is RAG cheaper than long context?

Per query, almost always, and often by one to three orders of magnitude, because retrieval sends a few thousand tokens where long context sends the whole corpus. Prompt caching narrows the gap substantially for a corpus that rarely changes, since the stuffed context becomes a cacheable prefix billed at roughly a tenth of input price. Retrieval still wins on provenance and on any corpus larger than a context window.

Does chunk size affect RAG cost?

Yes, in both directions. Smaller chunks send fewer tokens per retrieved result but produce more vectors and may force a higher top-k, cancelling the saving. Larger chunks cost more per result but often need fewer of them. Optimise the product of top-k and chunk size, which is tokens sent per query, rather than either number on its own.

How much does reranking cost in RAG?

Less than most people fear, provided it is configured carefully. Rerankers bill per search, where a search is one query plus up to about 100 documents, so a typical 50-candidate setup is one search per query. It inflates when the candidate set exceeds 100 documents, or when chunks longer than roughly 500 tokens are auto-split and each piece counts separately. Reranking only pays if it lets you send fewer chunks onward.

Is embedding a large corpus expensive?

Rarely. Embedding models are priced around a hundredth of generation models per million tokens, so embedding a ten-million-token corpus costs a few dollars once. What recurs is churn: the share of documents changing each month and needing re-embedding. Chunk overlap raises both the initial and ongoing cost, since overlapping text is embedded more than once.

Sources

Related articles

More on guides from the HorizonLux team.

Retrieval that answers well and bills quietly

Most RAG systems retrieve several times more than the answer needs. We fix the chunking and retrieval decisions behind that.

Prefer email? [email protected]