Foundation Models Deep Dive
Understand the foundation models you build on: GPT, Claude, Gemini, Llama and Mistral families, how they differ, and a practical framework for choosing a model for your Java application.
On this page
You build on foundation models the way you build on a database engine — you rarely make one, but choosing and understanding the one you use matters. This tutorial surveys the major families, how they differ, and a practical framework for choosing that does not rely on leaderboards.
Key Takeaways
- Foundation models are the broad, adaptable base you build on via prompting and retrieval, not retraining.
- The families differ in strengths, context length, latency and price — not in a single ranking.
- Test on your own task. Benchmarks are a rough filter; your inputs are the real benchmark.
- Because your code uses an abstraction, evaluating several models is cheap — do it.
The major families
| Family | Provider | Typically strong at | Access |
|---|---|---|---|
| GPT | OpenAI | General reasoning, tool use, ecosystem | Hosted API |
| Claude | Anthropic | Long context, code, careful instruction-following | Hosted API |
| Gemini | Multimodal, long context, Google Cloud integration | Hosted API | |
| Llama | Meta | Open weights, self-hostable, customisable | Open weight |
| Mistral | Mistral AI | Efficient open-weight models, strong for size | Open + hosted |
These shift constantly — new versions ship monthly and the relative strengths move. Treat any specific claim about "the best model" as perishable, and re-evaluate periodically.
Hosted vs open-weight
The first branch in choosing a model is whether you call an API or run the model yourself.
Hosted (GPT, Claude, Gemini): highest capability, no infrastructure, pay per call. The default for most applications, and where the frontier lives.
Open-weight (Llama, Mistral, and others): you run it, so you get privacy, no per-call fee, and customisation — at the cost of operating inference infrastructure and a generally lower capability ceiling. See Spring AI with Ollama and small language models.
What actually differs between models
Beyond the marketing, the dimensions that affect your application:
- Reasoning depth — how well it handles multi-step problems. The clearest differentiator on hard tasks.
- Context length — how much it can consider at once, from tens of thousands to millions of tokens. Matters for long documents and large retrieval sets. See tokenization and context windows.
- Instruction following — how reliably it obeys complex, constraint-heavy prompts.
- Tool use — how well it selects and calls tools, which matters enormously for agents.
- Latency — time to first token and total generation time, which shapes user experience.
- Price — per-token cost, which at scale is a real budget line.
- Multimodality — whether it handles images, audio, and how well.
A framework for choosing
Do not choose from a leaderboard. Choose like this:
// Because your code depends on ChatModel, swapping models for evaluation is a
// one-line change. Run your real task through each and compare on the axes you
// care about — not on a general benchmark.
List<ChatModel> candidates = List.of(gpt4oMini, claudeSonnet, gemini);
for (ChatModel model : candidates) {
EvalResult result = evaluate(model, yourRealTaskSet);
log.info("model={} accuracy={} p95LatencyMs={} costPer1k={}",
model, result.accuracy(), result.p95Latency(), result.costPer1000());
}Model versions and deprecation
Providers version and deprecate models. A model you built on can change behaviour with a new version, or be retired. Protect yourself:
- Pin model versions explicitly rather than using a floating "latest" alias, so behaviour does not shift under you.
- Keep a regression eval so you can test a new version before adopting it. See LLMOps for generative AI.
- Design for portability — depend on the
ChatModelabstraction, not a provider SDK, so a deprecation is a config change, not a rewrite.
Understanding what is under the hood
You do not need to build a transformer to use one well, but understanding the architecture explains a lot of model behaviour — why context length is limited, why tokens cost what they do, why models hallucinate. That is the next tutorial.
Next
Frequently Asked Questions
What is a foundation model?
How do I choose between GPT, Claude, and Gemini?
Should I use open-weight models like Llama or Mistral?
Do model benchmarks predict real-world performance?
Related tutorials
- Transformer Architecture ExplainedThe transformer architecture explained for engineers, not researchers: self-attention, multi-head attention, positional encoding and why it explains context limits, token cost and hallucination.
- Fine-Tuning LLMs: LoRA & QLoRAUnderstand fine-tuning for engineers: LoRA and QLoRA, instruction tuning, RLHF and DPO, and the crucial decision of when to fine-tune versus when retrieval or prompting is the better tool.
- Vector Databases Deep DiveHow vector databases work under the hood: the HNSW index, approximate nearest-neighbour search, cosine vs Euclidean distance, product quantization and metadata filtering — for Java developers.
- Embedding Models & Semantic SearchHow embedding models power semantic search: bi-encoders vs cross-encoders, re-ranking, hybrid search combining keywords and vectors, and choosing embeddings for retrieval quality.