The AI Stack in One Picture: Six Layers Every AI Product Is Built From
Every AI product is built from six layers: data, model, retrieval, orchestration, serving and ops, with evals and security across all of them. A restaurant analogy, one request traced through all six, and what an AI engineer actually builds around the model call.
What you will learn
- Name the six layers of an AI product: data, model, retrieval, orchestration, serving and ops
- Explain why evals and security run across every layer instead of sitting at the end
- Trace one user request through all six layers
- Describe what an AI engineer builds around the model call, and the four weak spots they design for
Before you start
- Basic Python
- A rough idea of what an LLM is
Every AI product, big or small, is built from the same six layers: data, model, retrieval, orchestration, serving and ops. Once you can draw that one picture, every tool you meet later (a vector store, an agent framework, a tracing dashboard) has an obvious place to live.
Let's build the picture slowly, starting with something that has nothing to do with AI.
Think of a restaurant
A dish reaches your table only because six stations work together:
- The pantry: the ingredients on the shelves.
- The chef: the skill that can cook pretty much anything.
- The runner: fetches exactly what this one order needs from the pantry.
- The head chef: decides the steps and who does what.
- The waiter: takes the order and brings the plate.
- The manager: looks after costs, complaints and inspections.
A great chef alone is not a restaurant. In the same way, a great model alone is not a product.
The stack in one picture
Now translate each station into AI terms:
| Restaurant | Layer | What lives there |
|---|---|---|
| Pantry | Data | PDFs, wikis, support tickets, databases |
| Chef | Model | An LLM behind an API, or open weights you run yourself |
| Runner | Retrieval | Embeddings, vector search and RAG, which find the right pieces of data for this one question |
| Head chef | Orchestration | Prompts, tools, MCP and agents, which decide what happens in what order |
| Waiter | Serving | A FastAPI service, streaming and Docker |
| Manager | Ops | Tracing, cost, caching and versions |
Look at that red band. Evals and security are not something you bolt on after the last layer. They run across every layer, the whole time. Start with why you can't ship without an eval and guardrails for LLM agents.
The bottom: data and model
This pair is what you know, and what thinks about it.
Data
- Sources: documents, tickets, product tables.
- Clean it: parse PDFs, drop junk, keep useful metadata like the page number.
- Split it: cut it into chunks small enough to search. See chunking strategies for RAG.
Model
- Closed: a hosted API. You rent it per token.
- Open: weights you run on your own machines.
- Choose by task: quality, speed, cost and privacy.
Most bad answers start right here: wrong data goes in, or the wrong model is picked for the job.
The middle: retrieval and orchestration
Find the right facts, then decide the steps.
Retrieval
- Embeddings turn text into numbers by meaning, so similar sentences end up close together (what an embedding actually is).
- Those numbers are stored in a vector store, like Chroma or pgvector (vector databases).
- To search better, add hybrid search and reranking (hybrid search, reranking).
Orchestration
- Context: what goes into the prompt, and just as important, what stays out.
- Tools and MCP let the model call your own APIs (tool use).
- Agents are multi-step flows, built with a framework such as LangGraph.
This middle part is where most of an AI engineer's day-to-day code sits. The RAG pipeline article walks through retrieval and prompt assembly stage by stage.
The top: serving and ops
Put it in front of users, then keep it healthy.
Serving
- API: FastAPI endpoints.
- Streaming: the words appear as they are written, instead of after a long wait.
- Packaging: Docker, so it runs the same on your laptop and on the server.
Ops
- Tracing: see every step of every request (LLM observability and tracing).
- Cost: budgets, caching, and smaller models where they are good enough (caching layers).
- Versions: prompts, models and indexes are all tracked.
Here's the difference in one line: a prototype stops at the model. A product needs these two layers as well.
One request, through all six
Now follow one real request. A user asks:
Can I expense a second monitor for home?
- Serving: the request hits our API.
- Retrieval: we search the expense policy for "home office equipment".
- Data: the matching policy chunks come back, with their page numbers.
- Orchestration: build the prompt. The rules, the chunks and the question, in a clear order.
- Model: writes the answer and cites the page it came from.
- Ops: log the trace, the tokens and the cost.
One small question touched all six layers. And the model only showed up at step five.
What the AI engineer does all day
Think of a bridge going up across a river. The physicist discovers how steel behaves. The structural engineer doesn't invent steel: they know its limits well, design around them, test the load and sign the bridge off as safe. AI research invents the material, the model. The AI engineer is the structural engineer, who builds things that stand up in that material.
The model call is one step out of five
Take an assistant that answers questions from a company's policy documents. An employee asks: how many days of parental leave do I get?
- Find: search the right policy pages first, because the model has never seen this company's handbook.
- Prompt: put those pages and the question in front of the model, clearly.
- Check: is the answer grounded in those pages, and does it cite them? Or did the model just guess?
- Serve: wrap it in an API so the HR portal can call it.
- Watch: once it runs, keep an eye on cost, speed and bad answers.
The model call is in there somewhere. The other four steps are the job.
What the job is, and is not
| Area | The AI engineer does | Left to someone else |
|---|---|---|
| Models | Picks a model, calls it well, swaps it when a better one ships | Training a foundation model from scratch |
| Knowledge | Embeddings, vector search and RAG over company data | Designing new embedding architectures |
| Behaviour | Prompts, context, tools, MCP and agents | Proofs about attention |
| Quality | Golden datasets, evals, regression tests in CI | Chasing a leaderboard |
| Production | FastAPI, Docker, tracing, cost guards, security | GPU kernel work |
The job is wide, but it's all engineering.
Know the material: four weak spots
Steel bends and concrete cracks, and a good engineer designs around that. An LLM has its own weak spots:
- It makes things up. So ground it in real documents, and check the answer.
- It varies from run to run. Same question, slightly different answer. So test with evals, not with one lucky try.
- It has a limited window. Only so much text fits in one call, so choose carefully what goes into the context.
- It costs money per token. So cache, trim and track the bill.
For the full list of gaps and their fixes, see What an LLM Can and Cannot Do. For the window and the bill, see LLM Tokens, Context Windows and Cost.
Common mistakes
- Treating the model as the product. A prototype stops at the model. Users need serving, and you need ops to keep it healthy.
- Leaving evals and security for the end. They are not a seventh box. Test and protect each layer as you build it.
- Blaming the model first. Most bad answers start with wrong data going in, or the wrong model for the job.
- Trusting one good run. The model varies, so one lucky answer proves nothing.
Quick recap
| Layer | Job | In the second-monitor request |
|---|---|---|
| Data | What you know: sources, cleaned and chunked | Policy chunks with page numbers |
| Model | What thinks about it: closed API or open weights | Writes the answer, cites the page |
| Retrieval | Find the right facts for this question | Search for "home office equipment" |
| Orchestration | Decide the steps and the context | Rules, chunks, question in order |
| Serving | Put it in front of users | The request hits the API |
| Ops | Keep it healthy and affordable | Logs trace, tokens and cost |
| Evals and security | Across every layer | Run at every step, not only at the end |
Try it yourself
Pick an AI app you use, like a support chat or a coding assistant. Guess its layers: where does its data come from, and what does it retrieve? Then find the gap: which layer would you not know how to build yet? That's the layer to study next.
Related course on Udemy
Become an AI Engineer: LLMs, RAG, Agents and MCP
Build real AI systems in Python: LLM APIs, RAG, evals, agents and MCP.View on Udemy ↗: Become an AI Engineer: LLMs, RAG, Agents and MCP (paid course, opens in a new tab)Related posts
Tokenization: What an LLM Actually Sees When You Type
A language model never sees letters, only token ids. Use tiktoken to watch strawberry become three ids, see a space or a capital change them, fix the letter-counting problem, and compare English, German and Hindi token counts.
LLM Tokens, Context Windows and Cost: What One Question Really Costs
Follow one four-word help desk question that becomes 911 input tokens. Learn what fills the context window, why chat memory grows every turn, how max_tokens cuts a reply, and how to price a call.
What an LLM Can and Cannot Do: One Prediction Loop, Its Strengths and Its Gaps
A large language model predicts the next token, over and over. That one loop makes it strong at drafting, summarising and classifying, and weak at fresh facts, exact maths, memory and guaranteed truth. See why with a three-line tiktoken script, and learn the fix for each gap.
Structured LLM Output with Pydantic: Describe the Shape Once, Check Every Reply
An LLM replies with a string. Pydantic turns that string into a typed object or a clear error. Validate a User, generate its JSON Schema, then follow one customer e-mail through a Ticket model where the first reply says refund, fails the check, and the retry fits.