Stay up to date with AI tools, model releases, and developer workflows that matter.
Weekly. Free. One click to leave.
Sources indicate that 7 Day Free Trial. Cancel Anytime.
A retrieval-augmented generation (RAG) app is usually drawn as a language model plus a vector database. When it goes live, the part that fails first is rarely the retrieval. It is GPU memory on the generation model, because a model that loads fine for one request can run out of memory when several people send long questions at once.
This article shows how to estimate that limit before you deploy, with a short script you can run, and then covers what else in the pipeline can slow responses down.
Serving a model takes more than its weights. The GPU also holds:.
the key-value (KV) cache, which grows with the length of every active request.
activations and batching overhead.
memory used by the inference runtime itself.
SitePoint's guide to running a local LLM on 10GB of VRAM makes the same point for a single desktop GPU: the usable budget is the total VRAM minus overhead, and the KV cache grows with the context window, so the real model budget is smaller than the number on the box.
For a RAG service, the KV cache matters even more. Retrieved passages are pasted into the prompt, so every request carries a long context, and every concurrent request holds its own cache.
The cache size per token depends on the model's architecture: two tensors (keys and values) for every layer, for every KV head. This script turns those numbers into a rough limit on concurrent requests:.
def kv_bytes_per_token(layers, kv_heads, head_dim, dtype_bytes=2):.
# Keys and values, for every layer, for one token.
return 2 *layers *kv_heads *head_dim *dtype_bytes.
def max_concurrent(vram_gb, weights_gb, ctx_tokens, per_token, reserve_gb=2.0):.
budget = (vram_gb - weights_gb - reserve_gb) * GIB.
return int(budget // (ctx_tokens * per_token)).
per_token = kv_bytes_per_token(32, 8, 128).
print(per_token // 1024, "KiB per token").
for ctx in (4096, 8192, 16384):.
n = max_concurrent(24, 16, ctx, per_token).
print(ctx, "tokens ->", n, "concurrent requests").
For a 24 GB GPU holding about 16 GB of fp16 weights with 2 GB kept in reserve, it prints:.
4096 tokens -> 12 concurrent requests.
8192 tokens -> 6 concurrent requests.
16384 tokens -> 3 concurrent requests.
The numbers are estimates. Real runtimes add their own overhead, and the architecture values come from the model's configuration file, so read them from the model you actually use. The pattern is what matters: doubling the context length halves the number of requests that fit. A RAG prompt that stuffs in ten retrieved chunks costs real capacity.
Industry observers note that serving runtimes do not simply crash when the cache is full. The vLLM documentation on optimization and tuning explains that when KV cache space is insufficient for all batched requests, the engine preempts some of them and recomputes them later, which can hurt end-to-end latency. Its suggested remedies include giving the cache more memory, reducing the number of concurrent sequences or batched tokens, or sharding the model across GPUs.
So the symptom of undersizing is often not an error. It is slow, uneven responses under load. Test with realistic prompt lengths and several simultaneous consumers, not a single request.
Embedding and ingestion have a different profile from generation. Embedding is often lighter than serving a large language model, and some teams run it on CPU. Document parsing, chunking and tokenization also run on CPU, so a fast GPU cannot make up for a slow CPU upstream. SitePoint's tutorial on a local RAG system for private documents walks through chunking, embeddings, vector storage and reranking, and is a good map of which stages run where.
RAM: vector indexes, document loaders and caches all live in system memory, so large collections need more of it.
Industry observers note that storage: model files, indexes, logs and backups add up. Fast storage shortens model loading and re-indexing.
Network: if the vector database, application server and model server sit in different places, latency adds to every request.
Two layouts are common. A single instance runs everything and is simplest for prototypes and internal tools. Separated services put ingestion and retrieval on smaller machines and keep the GPU for generation, which scales better as traffic grows.
Memory estimates only hold if the GPU memory is really yours. On a shared or time-sliced GPU, other workloads can take memory and compute away from your service, which makes capacity hard to strategy. Hosting providers describe this in different terms, such as passthrough, vGPU, MIG and time-slicing. For a view of how one GPU hosting provider explains those allocation methods, GPU Mart's GPU virtualization guide compares them. It is a hosting organization's page, so confirm any provider's claims about isolation and performance with your own load test.
Whatever provider you choose, ask these questions:.
Is the physical GPU assigned to you exclusively, or partitioned or time-sliced?
Do you have root access to install your own drivers, CUDA libraries and containers?
Which minimum commitments, regions and support terms apply?
According to recent reports, A small stack can run as a handful of containers: an API service for request handling and prompt assembly, an ingestion worker, a vector database and a model server. Keeping them separate lets you monitor each one's memory and CPU use and move the heavy one to bigger hardware without rewriting the rest.
Recent findings suggest that for a service that stays up all month, a fixed monthly term is easier to forecast than hourly capacity. Hourly capacity suits testing quantization settings or processing a one-off document batch.
Is GPU memory always the bottleneck for RAG?
Industry observers note that not always. Generation usually hits memory first, but slow parsing, a small CPU or a distant vector database can dominate response time.
Does quantization solve the memory problem?
It shrinks the weights, but the KV cache still grows with context length and concurrency. Test with your real prompt sizes.
Should embeddings run on the GPU?
It depends on volume. Small workloads can run on CPU, while a large ingestion job may benefit from a GPU for a limited time.
Size a RAG service for the worst realistic moment, not the single-request demo. Estimate the KV cache from the model's architecture, remember that long retrieved contexts reduce how many requests fit, watch for preemption under load, keep CPU, RAM, storage and network in the strategy, and find out whether the GPU is exclusive or shared. The script above is small, but it turns a vague worry about memory into numbers you can check.
7 Day Free Trial. Cancel Anytime.
