Retrieval-augmented generation (RAG) is the most common production LLM pattern. You retrieve relevant chunks from a knowledge base, inject them into the prompt, and ask the model to answer based only on what was retrieved. The LLM choice matters, but it's one of several variables — here's how to get the whole system right.
What makes a good RAG model?
The ideal RAG model: (1) follows retrieved context faithfully and doesn't hallucinate when the answer is in the retrieved text, (2) correctly says 'I don't know' when the answer isn't in the retrieved context, (3) handles long contexts without 'lost in the middle' degradation, (4) is fast and cheap enough for your query volume.
Top model picks for RAG
Claude Sonnet 4.6 and GPT-4o are the top closed-source picks — both have strong instruction following and context faithfulness. Gemini 2.0 Flash is the best value for high-volume RAG with its 1M token context. For self-hosted, Llama 3.1 70B performs surprisingly well on RAG benchmarks.
- High accuracy, moderate cost → Claude Sonnet 4.6 ($3/$15 per 1M)
- Best value at volume → Gemini 2.0 Flash ($0.075/$0.30 per 1M)
- Maximum context (whole codebases) → Gemini 2.0 Pro (2M ctx)
- Self-hosted / private → Llama 3.1 70B via vLLM
Choosing your embedding model
The embedding model determines retrieval quality — a bad retrieval step can't be fixed by a good LLM. text-embedding-3-large (OpenAI) and Mistral Embed are the top closed-source options. For open-source, BGE-M3 (multilingual, 8192 token input) and Nomic Embed v2 are strong choices. Dimension: 256–1536 depending on your latency/accuracy tradeoff.
Chunk size and overlap
Chunk size is the most underrated RAG parameter. Too small: individual chunks lack context. Too large: retrieval returns irrelevant content and the model gets confused. Start with 512 tokens, 10% overlap, and tune from there. For structured documents (PDFs, contracts), semantic chunking by section outperforms fixed-size chunks.
Re-ranking
A bi-encoder (embedding search) retrieves candidates quickly but imprecisely. A cross-encoder re-ranker (Cohere Rerank, BGE Reranker) re-scores the top-k results at higher quality. Adding re-ranking typically improves RAG answer quality by 15–30% at the cost of an extra API call. Worth it for production systems where accuracy matters.
Estimating RAG costs
A typical RAG query: 500 input tokens (system + retrieved chunks) + 200 output tokens. At 100K queries/day: Claude Sonnet costs ~$180/day ($5.4K/month), Gemini Flash costs ~$4.50/day ($135/month). Don't forget embedding costs — 100K queries × 500 tokens = 50M tokens, ~$0.50/day on text-embedding-3-small.
Tip
Use the ModelStop cost calculator to model your specific token volumes. Batch your embedding calls to cut costs by 50%.
