DEV Community

Cover image for Your LLM Is Reading Too Much: How RAG Can Lower AI Costs
Shekhar maheshwari
Shekhar maheshwari

Posted on

Your LLM Is Reading Too Much: How RAG Can Lower AI Costs

When teams talk about Retrieval-Augmented Generation, they usually focus on accuracy. RAG helps a model answer with current, relevant information and reduces hallucinations.

That is true, but it misses another practical benefit:

RAG can make an AI application much cheaper to run.

The reason is simple. Every time you call an LLM, you pay for what the model reads as well as what it writes. If you repeatedly send a long policy manual, a large product catalog, or an entire conversation history, the model processes all of it—even when only a small part is useful.

RAG gives us a better option. Search first, retrieve only the relevant information, and let the model read that smaller set of evidence.

The Short Version
LLMs charge for input tokens as well as output tokens.
Sending more context than necessary increases cost and latency.
RAG retrieves a focused evidence set before calling the model.
Deterministic parsing and structured filters can reduce the work even further.
The goal is not to retrieve everything that might be relevant. It is to retrieve enough trustworthy information to answer the question correctly.

Most of the Waste Is in the Prompt

A simplified LLM bill looks like this:

request cost = input tokens × input rate
             + output tokens × output rate
Enter fullscreen mode Exit fullscreen mode

The input is not just the user's question. It may include the system prompt, chat history, reference documents, product records, examples, formatting rules, and tool definitions.

Imagine a support assistant with a 40,000-token policy manual. A customer asks one question about refunds, but the application sends the complete manual on every request. The model may only need two paragraphs, yet you still pay for it to process everything else.

RAG changes the flow:

Question
   ↓
Search and filtering
   ↓
A small set of relevant evidence
   ↓
Grounded LLM response
Enter fullscreen mode Exit fullscreen mode

If retrieval cuts the reference material from 40,000 tokens to 2,000, the model avoids reading 38,000 unnecessary tokens each time. That saving becomes significant once the application handles thousands of requests.

Search Should Do Search Work
Without retrieval, we often ask the LLM to do several jobs at once: find the relevant information, ignore unrelated content, apply business rules, resolve ambiguity, and write the answer.

An LLM can do this, but it is an expensive way to search.

A search engine, vector database, or hybrid retrieval system can narrow the candidate set before generation. Metadata filters can remove products from the wrong category, incompatible devices, expired policies, or records the user is not allowed to access.

The model then receives a cleaner prompt and has a smaller job: explain the evidence.

A Practical Multi-Intent Example
Consider this request to a telecom shopping assistant:

Find a case for my iPhone 15 and a screen protector for my Galaxy S24, both under $50.
This looks like one sentence, but it contains two separate product searches. Each accessory must remain connected to the correct phone, and both searches must respect the budget.

One approach is to send the sentence and a large product catalog to an LLM and ask it to work everything out. A more efficient pipeline looks like this:

User query
   ↓
Deterministic telecom parsing
   ↓
Multi-intent routing
   ↓
Typesense retrieval with compatibility and price filters
   ↓
A small set of matching products
   ↓
LLM writes the final
Enter fullscreen mode Exit fullscreen mode

The parser can recognize the devices, accessory categories, and budget using phrase matching and regular expressions. That does not require an LLM call.

Conceptually, the result looks like this:

{
  "requests": [
    {
      "category": "case",
      "device": "iPhone 15",
      "maximum_price": 50
    },
    {
      "category": "screen protector",
      "device": "Galaxy S24",
      "maximum_price": 50
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

The routing layer handles the two intents separately. Typesense searches the correct categories and applies compatibility and price filters. Only the matching products reach the final prompt.

This matters for both cost and quality. The LLM does not have to inspect a broad catalog, guess which accessory belongs to which device, or remove incompatible products. It receives focused evidence and turns it into a useful answer.

Sometimes You Do Not Need Generation
Not every message in a chat interface needs a generated response.

Requests such as these are often structured searches:

  • Show me cases compatible with an iPhone 15.
  • Find plans under $80.
  • Look up order 12345. If the application can answer with a product list, account record, or database result, it may be able to skip generation completely.

That gives us three useful execution paths:

Exact lookup          → search or database response
Grounded explanation → retrieval + smaller LLM
Complex
Enter fullscreen mode Exit fullscreen mode

The cheapest model call is still the one you do not make.

RAG Can Also Become Expensive

Adding a vector database does not automatically reduce cost. A careless RAG implementation can make the system more expensive.

One common mistake is retrieving too much. Increasing top_k may improve recall, but every extra result adds tokens to the prompt. Ten similar passages are not necessarily better than three useful and diverse ones.

Another mistake is putting an LLM at every stage: one model rewrites the query, another classifies it, another reranks the results, and a final model writes the answer. That may be justified for difficult use cases, but it can also turn one model call into four.

Conversation history is another source of hidden cost. Even if document retrieval is efficient, an unlimited chat history can make the prompt grow on every turn. Keep the history relevant to the active task and store durable state in a structured form where possible.

Finally, do not ignore output length. A product lookup usually does not need an essay. Short, task-appropriate answers reduce cost and are often better for users.

What a Cost-Aware Pipeline Looks Like
In practice, I would design the flow around a few questions:

  1. Can the request be normalized or parsed without an LLM?
  2. Are there explicit filters such as category, compatibility, price, date, or permissions?
  3. Can search answer the request directly?
  4. If generation is required, what is the smallest useful evidence set?
  5. Does the task need a large model, or can a smaller model handle the grounded answer?

The resulting architecture might normalize the request, apply structured filters, run lexical and semantic retrieval, deduplicate the results, and pass only a bounded evidence set to the appropriate model.

Measure Cost per Successful Task
Token usage is important, but it should not be measured in isolation. An answer that is cheap and wrong simply creates another request or sends the customer to support.

Useful metrics include:

  • Input and output tokens per request
  • Number of retrieved tokens that are actually used
  • Retrieval and generation latency
  • Requests answered without an LLM
  • Small-model and large-model routing rates
  • Retry rate
  • Cache-hit rate
  • Cost per successfully completed task

These metrics reveal whether the pipeline is genuinely becoming more efficient or merely moving the cost somewhere else.

The Principle I Keep Coming Back To
The purpose of RAG is not to send the model as much potentially useful information as possible.

It is to find the

smallest trustworthy set of evidence that can answer the question.

That principle leads to better engineering decisions. Parse predictable inputs without an LLM. Apply business rules before retrieval. Use search for search problems. Keep the context focused. Call a larger model only when the task truly needs one.

RAG reduces cost when it changes what the model is responsible for. Search retrieves. Filters remove irrelevant options. Caches reuse stable work. The LLM focuses on the part it does best: turning the right evidence into a clear answer.

Your model does not need to read everything you know. It only needs what helps it answer the question in front of it.

Top comments (0)