Back to Engineering Insights
Cloud Architecture
Mar 27, 2026
By LeanOps Team

Scaling RAG, Vector Databases, and AI Agents Without Destroying Your Cloud Budget

Scaling RAG, Vector Databases, and AI Agents Without Destroying Your Cloud Budget

The RAG Cost Cliff Nobody Warns You About

Your RAG prototype works beautifully. It retrieves context from your knowledge base, feeds it to an LLM, and returns accurate, grounded answers. The whole thing costs maybe $50 per month on your dev account.

Then you go to production. Traffic ramps to 10,000 queries per day. Then 50,000. Then 500,000. And suddenly your monthly infrastructure bill looks nothing like what you budgeted.

Here is what happens at scale that nobody talks about during the prototype phase:

  • Embedding generation that cost $30/month at prototype scale costs $3,000-15,000/month at production scale
  • Vector database storage that was free on the starter plan now costs $2,000-20,000/month
  • LLM inference that seemed cheap per query becomes your largest line item at $5,000-50,000/month
  • AI agent orchestration adds a multiplier of 3-8x on every other cost because agents make multiple calls per user request

The total cost of a production RAG system at scale is typically 10-50x what teams estimate based on their prototype. And the cost curve is not linear. It is stepped, with painful jumps at specific scale thresholds.

This guide will show you exactly where those cost cliffs are, what triggers them, and how to optimize your RAG stack so you can scale to millions of queries without your cloud bill scaling alongside.

The Real Cost Breakdown of a RAG Pipeline

Let me walk you through every cost component of a RAG pipeline at three different scale points. These numbers are based on typical architectures using common tools.

Embedding Generation Costs

Every RAG query starts with turning the user's question into a vector embedding. At scale, this is one of your largest costs.

ScaleQueries/MonthEmbedding ModelMonthly Cost
Small100,000OpenAI text-embedding-3-small$2-5
Medium1,000,000OpenAI text-embedding-3-small$20-50
Large10,000,000OpenAI text-embedding-3-small$200-500
Enterprise100,000,000OpenAI text-embedding-3-small$2,000-5,000

That looks manageable. But here is the catch: those numbers assume one embedding per query. In practice, RAG systems often re-embed documents during ingestion, run multiple embedding passes for hybrid search, and generate embeddings for agent sub-queries. The real multiplier is 3-10x on those base numbers.

Self-hosted alternative: Running an open-source embedding model like sentence-transformers on a GPU instance costs $200-800/month for a single g5.xlarge on AWS (NVIDIA A10G). That single instance handles 500-2,000 embeddings per second, which covers roughly 1-5 billion embeddings per month. At enterprise scale, self-hosting saves 80-95% compared to API-based embeddings.

Vector Database Costs

This is where costs get surprising. Vector databases have three cost components that scale differently:

Storage: Storing vectors costs $0.10-0.40 per million vectors per month on managed services. A knowledge base with 10 million document chunks at 1536 dimensions (OpenAI) requires roughly 60GB of vector storage. That is $50-200/month in storage alone.

Compute (search): Query processing is the expensive part. Each vector similarity search requires scanning or traversing an index. At high query volumes, you need more replicas and larger instances.

Network: Moving embeddings between your application and vector database incurs data transfer costs, especially across regions.

Here is what the major vector databases actually cost at scale:

Database10M Vectors, 100K Queries/Month10M Vectors, 10M Queries/Month100M Vectors, 10M Queries/Month
Pinecone (Serverless)$70-150$200-800$1,500-5,000
Weaviate Cloud$100-250$400-1,200$2,000-6,000
Qdrant Cloud$80-200$300-900$1,200-4,000
Self-hosted pgvector on RDS$200-400 (fixed)$200-800 (fixed + read replicas)$800-2,500
Self-hosted Milvus on EKS$300-600$500-1,500$1,500-5,000

The hidden cost trap: managed vector databases charge per "read unit" or "query unit." At low volumes, this is cheap. But AI agents that make 5-15 vector lookups per user request blow through these units fast. A system that looks like 1M queries/month from the user's perspective might actually be 10M vector lookups from the database's perspective.

For a detailed comparison, read our vector database cost comparison guide.

LLM Inference Costs

This is almost always the largest cost in a RAG pipeline. And it scales directly with query volume and context window size.

ModelInput Cost (per 1M tokens)Output Cost (per 1M tokens)Typical RAG Query Cost (2K context + 500 output)
GPT-4o$2.50$10.00$0.01
GPT-4o-mini$0.15$0.60$0.0006
Claude 3.5 Sonnet$3.00$15.00$0.014
Claude Haiku$0.25$1.25$0.001
Llama 3 70B (self-hosted)~$0.50-1.00*~$1.00-2.00*$0.002-0.004

*Self-hosted costs based on GPU amortization at reasonable utilization.

At 1M queries/month with GPT-4o: $10,000/month in inference alone. At 1M queries/month with GPT-4o-mini: $600/month. At 1M queries/month with self-hosted Llama 3 70B: $2,000-4,000/month.

The model choice alone creates a 5-15x cost difference for the same quality of answers on many tasks.

AI Agent Orchestration Costs (The Hidden Multiplier)

This is where budgets truly explode. AI agents do not make one LLM call per user query. They make 3-15 calls depending on the task complexity.

A typical AI agent workflow:

  1. Parse user intent (1 LLM call)
  2. Decide which tools/knowledge bases to query (1 LLM call)
  3. Generate embedding and search vector DB (1 embedding + 1-5 vector queries)
  4. Evaluate retrieved context for relevance (1 LLM call)
  5. Generate response with citations (1 LLM call)
  6. Self-check for hallucination (1 LLM call, optional but recommended)

That is 5-6 LLM calls, 1 embedding, and up to 5 vector searches per user query. Your "1M queries/month" is actually 5-6M LLM calls, 1M embeddings, and 5M vector lookups.

The cost multiplier table:

ArchitectureLLM Calls per User QueryVector Lookups per User QueryEffective Cost Multiplier
Simple RAG (retrieve + generate)11-31x
RAG with re-ranking23-52-3x
Multi-step agent3-63-84-8x
Multi-agent system5-155-208-20x

A multi-agent system at 1M user queries/month with GPT-4o could cost $80,000-200,000/month in LLM inference alone. That same system with smart optimization can cost $5,000-15,000/month.

8 Strategies to Cut RAG Infrastructure Costs by 40-70%

1. Implement Semantic Caching

This is the single highest-impact optimization for RAG. Instead of processing every query from scratch, cache the full response for semantically similar queries.

How it works: when a query comes in, generate its embedding and search your cache (a separate vector index) for similar previous queries. If a match exists above your similarity threshold (typically 0.92-0.95), return the cached response. No LLM call needed.

Tools: GPTCache, LangChain CacheBackedEmbeddings, or build your own with Redis + vector similarity.

Realistic hit rates: 20-40% for diverse query patterns, 50-70% for customer support or FAQ-style workloads.

Savings: At a 40% cache hit rate, you eliminate 40% of your LLM inference costs. On a $20,000/month LLM bill, that is $8,000/month saved.

2. Use Tiered LLM Routing

Not every query needs your most expensive model. Route queries to the cheapest model that can handle them.

The routing strategy:

  • Simple factual lookups (40-60% of queries): GPT-4o-mini or Claude Haiku ($0.0006-0.001 per query)
  • Complex reasoning tasks (20-30%): GPT-4o or Claude Sonnet ($0.01-0.014 per query)
  • Ambiguous or high-stakes queries (10-20%): Most capable model with extended context

Use a lightweight classifier (can be rule-based or a small LLM call) to categorize incoming queries. The classifier costs pennies but saves dollars per query on model selection.

Savings: 50-70% reduction in LLM inference costs compared to routing everything through a premium model.

3. Optimize Your Chunking Strategy

Most teams use fixed-size chunks (500-1000 tokens) because that is what the tutorial showed them. This creates two cost problems:

  • Chunks that are too large include irrelevant context, wasting input tokens on every LLM call
  • Chunks that are too small require retrieving more of them, multiplying vector search costs

The better approach: Use semantic chunking that respects document structure. Paragraphs, sections, and logical boundaries create chunks that are both smaller and more relevant. Tools like LangChain's semantic chunker or Unstructured handle this automatically.

Also: Include metadata summaries in each chunk so the retriever can make better relevance decisions without pulling full chunks. This reduces the number of chunks you need to retrieve per query from 5-10 to 2-4.

Savings: 20-40% reduction in LLM input token costs and 30-50% reduction in vector search volume.

4. Self-Host Embeddings (At Scale, This Is Not Optional)

If you are generating more than 10 million embeddings per month, self-hosting is not just cheaper. It is dramatically cheaper.

A single g5.xlarge instance ($1.006/hour on-demand, $0.30-0.40/hour on spot) running sentence-transformers generates 1,000-2,000 embeddings per second. That is roughly 2.5-5 billion embeddings per month from one GPU.

At 100M embeddings/month with OpenAI's API: $2,000-5,000/month. At 100M embeddings/month self-hosted on spot: $220-290/month.

Self-hosting saves 90%+ at this scale. The tradeoff is operational complexity, but if you already run Kubernetes, deploying an embedding model is straightforward.

For smaller teams, consider AWS Bedrock or GCP Vertex AI embedding endpoints, which offer a middle ground between API pricing and self-hosting.

5. Implement Vector Index Tiering

Not all vectors need to be in hot storage. Apply the same lifecycle thinking you use for S3 storage tiers to your vector data.

Hot tier: Vectors accessed in the last 30 days. Keep in your primary vector database with full indexing. Fast search, higher cost.

Warm tier: Vectors accessed in the last 30-90 days. Move to a secondary index with reduced replicas. Slightly slower search, 50-70% cheaper.

Cold tier: Vectors not accessed in 90+ days. Archive to a columnar store (Parquet on S3) with a basic ANN index. Only searched when hot and warm tiers return no results. 80-95% cheaper.

Most RAG knowledge bases follow a power law: 10-20% of vectors handle 80-90% of queries. Tiering based on access frequency keeps costs low while maintaining performance for the queries that matter.

Savings: 40-60% on vector storage costs.

6. Batch Agent Operations

AI agents that make individual API calls for every sub-task are wasting money on per-request overhead. Batch similar operations together.

Embedding batching: Instead of embedding one query at a time, collect queries over a 50-100ms window and embed them in a single batch call. OpenAI and most embedding APIs support batching, and the per-token cost is the same, but you reduce HTTP overhead and can optimize GPU utilization for self-hosted models.

Vector search batching: Pinecone, Weaviate, and Qdrant all support batch queries. A single batch request for 10 queries is faster and cheaper than 10 individual requests.

LLM call batching: Where possible, combine multiple small LLM calls into one structured prompt. Instead of making 3 separate calls to classify, retrieve, and generate, design a prompt that handles all three in one pass. This reduces latency and cuts per-request overhead.

Savings: 15-30% reduction in API and compute costs from reduced overhead.

7. Right-Size Your Vector Database Infrastructure

If you are running self-hosted vector databases on Kubernetes, you are probably overprovisioned. Vector search is memory-intensive but not necessarily CPU-intensive.

Memory sizing: Your vector index needs to fit in RAM for fast search. Calculate: vectors x dimensions x 4 bytes (float32) = RAM needed. 10M vectors at 1536 dimensions = 57.6GB. Add 20% overhead for the index structure = 69GB. You need a node with at least 69GB of available RAM.

CPU sizing: Vector search is parallelizable but not as CPU-hungry as people assume. For most workloads, 4-8 vCPUs per billion vectors in the index is sufficient. Teams routinely overprovision CPU by 3-5x.

Replica sizing: You need replicas for availability and to distribute query load. But many teams run 3 replicas for workloads that only need 2. Each unnecessary replica doubles your memory and compute costs.

Use Kubecost or the Kubernetes VPA in recommendation mode to see actual resource utilization before sizing.

Savings: 30-50% on vector database compute costs.

8. Monitor Cost Per Query as Your North Star Metric

You cannot optimize what you do not measure. Track the fully-loaded cost of every RAG query:

Cost per query = Embedding cost + Vector search cost + LLM input tokens cost + LLM output tokens cost + Infrastructure overhead (compute, networking)

Break this down by:

  • Query type (simple lookup vs. complex reasoning vs. agent workflow)
  • Model used
  • Cache hit vs. miss
  • Number of agent steps taken

Tools like LangSmith (LangChain), Helicone, or Portkey track LLM costs per request automatically. For a complete picture, combine with your cloud cost monitoring to include infrastructure costs.

Set targets: most RAG systems can achieve $0.001-0.005 per query for simple lookups and $0.01-0.05 for complex agent workflows. If your costs are above these ranges, there is significant optimization opportunity.

The RAG Cost Optimization Roadmap

Here is the order to implement these optimizations for maximum impact with minimum effort:

PhaseActionsTimelineExpected Savings
Quick wins (Week 1-2)Semantic caching, LLM model routing, chunk size optimization2-5 days each30-50%
Infrastructure (Week 3-6)Self-host embeddings, right-size vector DB, batch operations1-2 weeks each20-40% additional
Advanced (Month 2-3)Vector index tiering, cost-per-query monitoring, continuous optimizationOngoing10-20% additional

Start with semantic caching. It has the highest ROI of any optimization and can be implemented in a day with GPTCache or a custom Redis-based cache.

Cost Targets by Scale

Use these benchmarks to evaluate whether your RAG system is cost-efficient:

Scale (Queries/Month)Target Monthly Cost (Simple RAG)Target Monthly Cost (Agent RAG)
100,000$100-500$500-2,000
1,000,000$500-3,000$3,000-15,000
10,000,000$3,000-15,000$15,000-80,000
100,000,000$15,000-60,000$60,000-300,000

If your costs are significantly above these ranges, you are leaving optimization on the table. If they are below, you have either optimized well or may be underinvesting in quality (check your response accuracy).

Frequently Asked Questions

What is the most expensive part of a RAG pipeline?

LLM inference is almost always the largest cost, typically 50-70% of total RAG spending. Vector database costs are second at 15-25%, followed by embedding generation at 5-15%. However, AI agent architectures multiply LLM costs by 3-15x, making agent orchestration the primary cost driver for complex systems.

Should I use a managed vector database or self-host?

Below 5 million vectors and 1 million queries/month, managed services like Pinecone or Weaviate Cloud are usually cheaper when you factor in engineering time. Above those thresholds, self-hosting with pgvector (if you already run PostgreSQL) or Milvus on Kubernetes becomes significantly cheaper. The crossover point is typically $500-1,000/month in managed service costs.

How do I reduce LLM costs without sacrificing answer quality?

Tiered routing is the answer. Use a lightweight classifier to route simple queries (factual lookups, yes/no questions) to cheaper models like GPT-4o-mini or Claude Haiku, and only route complex reasoning tasks to premium models. Most RAG workloads are 40-60% simple queries. Combined with semantic caching (which serves repeated queries for near-zero cost), you can typically cut LLM inference costs by 50-70% with no measurable quality loss.

What is semantic caching and how effective is it?

Semantic caching stores the full response for a query along with its embedding. When a new query arrives, you compare its embedding against cached queries using vector similarity. If the similarity exceeds a threshold (typically 0.92-0.95), you return the cached response instead of running the full RAG pipeline. Effectiveness depends on query diversity. FAQ and customer support workloads see 50-70% cache hit rates. Open-ended research queries see 20-30%.

How do AI agents make RAG costs worse?

AI agents make multiple tool calls and LLM invocations per user request. A simple RAG query costs 1 LLM call and 1-3 vector searches. An AI agent handling the same query might make 5-6 LLM calls, 5+ vector searches, and potentially external API calls. The cost per user query jumps 4-20x compared to simple RAG. Optimizations like caching, batching, and model routing become even more critical for agent-based systems.

Can I run production RAG on a startup budget?

Absolutely. At 100,000 queries/month, a well-optimized RAG system costs $100-500/month using GPT-4o-mini for inference, a managed vector database starter plan, and semantic caching. The key is avoiding premature scaling. Start with a managed stack, monitor your cost per query, and only move to self-hosted infrastructure when managed costs exceed $1,000-2,000/month. Read our guide on free cloud optimization tools for startups for more budget-friendly approaches.

How do I forecast RAG infrastructure costs for my business case?

Use this formula: (projected monthly queries) x (average LLM calls per query) x (average tokens per call) x (model price per token) + vector database costs + embedding costs + compute overhead. Apply a 1.5x safety multiplier for production overhead. Then use our cloud cost forecasting framework to build a layered forecast that accounts for growth and variability.

Scale Smart, Not Expensive

RAG, vector databases, and AI agents are powerful technologies. But without cost awareness built into your architecture from the start, they become the fastest-growing line item on your cloud bill.

Start measuring cost per query today. Implement semantic caching this week. Evaluate your model routing strategy this month. Those three actions alone typically cut RAG infrastructure costs by 40-60%.

And if your AI infrastructure costs are growing faster than your user base, reach out to our team. We help companies build RAG and AI agent systems that scale efficiently, not expensively. For ongoing infrastructure management, explore our cloud operations services.

Because the companies that win the AI race will not be the ones spending the most on infrastructure. They will be the ones spending the smartest.