cd /news/artificial-intelligence/from-tokens-to-rag-an-ai-field-guide… Β· home β€Ί topics β€Ί artificial-intelligence β€Ί article
[ARTICLE Β· art-66439] src=pub.towardsai.net β†— pub= topic=artificial-intelligence verified=true sentiment=Β· neutral

From Tokens to RAG: An AI Field Guide for Developers

Developers can demystify AI by understanding that AI, ML, deep learning, and LLMs are nested concepts, not synonyms, and that training and inference are the two halves of a model's life, with most app developers working only on inference. The article uses a 17-parameter XOR network to illustrate how deep learning stacks layers to build complex features from simple ones.

read10 min views2 publishedJul 21, 2026

Have you tried to get into AI and hit a wall of jargon on the first page? Training, inference, weights, tokens, embeddings, fine-tuning, context windows, RAG, hallucination, temperature. It reads like a foreign language, and every article assumes you already know the other ten terms.

Here is the good news: most of it is simpler than it sounds. This article builds the vocabulary and the mental models once, so the rest of your AI journey stops feeling like guesswork.

Think of it like learning HTTP before you pick up a web framework. You can skip it β€” but you will be guessing every time something breaks. This is your HTTP for AI.

The first thing to fix is a common mix-up. AI, ML, deep learning, and LLMs are not synonyms. They are nested, like Russian dolls β€” each one sits inside a bigger one.

Every LLM is deep learning, which is machine learning, which is AI. But it does not work the other way around. AI is much bigger than ML. Genetic algorithms, ant-colony optimization, and edge detection (Sobel/Canny) are all clearly AI, yet none of them learn from data. Keep this picture in your head and half the confusion disappears.

In machine learning, you do not write the rules. You show the model examples, and it figures out the rules on its own β€” stored as numbers called parameters (also called weights).

Why bother? Because for problems like finding cats in photos or translating a sentence, nobody can write the rules by hand. There are too many edge cases. So you let the model learn them from examples instead.

Compare that with traditional programming, where you write the rules and the program just applies them:

Here is the flip that matters: in machine learning, the rules are the output. You learn them from examples instead of typing them out.

FlavorIdeaExampleSupervised learn from labeled examplesspam / not-spamUnsupervised find structure, no labelscluster customers (k-means)Reinforcement learn by trial + rewardgame-playing, robotics

Where do LLMs fit? Mostly self-supervised β€” the label comes free from the text itself: predict the next word. Then they get polished with RLHF (reinforcement learning from human feedback) to be helpful and safe.

Strip away the mystery and training is a single loop, repeated an enormous number of times.

Two words you will see everywhere describe the two halves of a model’s life:

Remember this one line: almost everything you do as an app developer is inference. You use models that other people trained.

Abstract talk about β€œlearning rules” is easy to nod along to and hard to believe. So let’s watch it happen on the smallest possible problem.

XOR outputs 1 only when the two inputs differ:

x1  x2 | answer   ───────────────   0   0  |   0   0   1  |   1   1   0  |   1   1   1  |   0

Four rows. Two inputs. A tiny network with just 17 parameters can learn this rule. Here is its shape β€” 2 inputs, 4 hidden neurons, 1 output:

Those 17 numbers break down as 8 (inputβ†’hidden) + 4 (biases) + 4 (hiddenβ†’output) + 1 (bias). The hidden layer bends the space so XOR becomes separable. That is exactly why β€œdeep” learning stacks layers.

XOR is really OR, but not AND. Two hidden neurons can learn those two features, and the output combines them:

x1 x2 | A (OR) | B (AND) | out = A βˆ’ B βˆ’ 0.5 | XOR ──────┼────────┼─────────┼───────────────────┼─────  0  0 |   0    |    0    |       βˆ’0.5        |  0  βœ“  0  1 |   1    |    0    |       +0.5        |  1  βœ“  1  0 |   1    |    0    |       +0.5        |  1  βœ“  1  1 |   1    |    1    |       βˆ’0.5        |  0  βœ“

This is the secret of depth in one table. Early neurons build simple features (OR, AND); later neurons combine them into something richer. An LLM does the same thing β€” with billions of features instead of two.

Here is the real loss dropping as the network trains. Loss is just how wrong it is right now β€” lower is better.

epoch      loss    what the network "knows" ─────────────────────────────────────────────      0    0.5835   nothing β€” every guess β‰ˆ 0.5    500    0.3573   starting to separate cases  1,000    0.0733   "getting it"  2,000    0.0064   essentially solved  5,000    0.0014   polished β€” 4/4 correct ─────────────────────────────────────────────   β‰ˆ 20,000 tiny guess-and-correct steps   …to learn a rule you'd write in one line of code.

Sit with that for a second. Nobody handed the network the rule. It discovered XOR by being wrong thousands of times and nudging its knobs after each mistake.

The XOR toy is the whole story of an LLM, just multiplied by an almost unimaginable factor.

This is intuition, not literal math. But the shape of the cost is exactly this, scaled up roughly 100 billion times.

A language model has one job: given some text, predict what comes next. It is a supercharged autocomplete.

Input: "The capital of Italy is"                 β–Ό   Rome    β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡β–‡  81%   a       β–‡β–‡β–‡                 6%   located β–‡β–‡                  4%

The surprising part is what falls out of that simple goal. Get really good at β€œnext word” across the whole internet, and you accidentally learn grammar, facts, reasoning, translation, and code. The model generates one token, appends it, and repeats β€” a process called autoregressive generation.

L        L         M   β”‚        β”‚         └─► MODEL      a neural network (a math function)   β”‚        └───────────► LANGUAGE   trained on human text & code   └────────────────────► LARGE      two things: DATA & PARAMETERS

β€œLarge” is not marketing. It is a real jump in scale:

Classic ML model    ~10²–10⁴     dozens–thousands "Small" LM          ~10⁸         hundreds of millions Frontier LLM        ~10¹¹–10ΒΉΒ²   hundreds of billions – trillions  ← "LARGE"

This is the idea behind scaling laws: more parameters, plus more good data, plus more compute, tends to give you a smoothly more capable model. With LLMs, scale is the point.

Models do not read letters or whole words. They read tokens β€” sub-word chunks β€” and each token is really just a number.

"Developers love coffee!"        β–Ό  (sub-word chunks)[ "Develop" ][ "ers" ][ " love" ][ " coffee" ][ "!" ]   1042        513       2415        8871        0        β–Ό  [1042, 513, 2415, 8871, 0]

A useful rule of thumb: 1 token β‰ˆ 4 characters β‰ˆ ΒΎ of a word, so 1,000 tokens is roughly 750 words. This matters for a very practical reason β€” tokens are the unit of billing and the unit of the context window. You pay per token, and you fit a limited number of them.

Here is a detail that surprises people. The same sentence can cost twice as much depending on the language:

English:  "Developers love coffee!"           [ Develop | ers | love | coffee | ! ]                 β‰ˆ 5 tokens
Turkish:  "YazΔ±lΔ±mcΔ±lar kahveyi Γ§ok sever!"   (same meaning)           [ Yaz | Δ±lΔ±m | cΔ± | lar | kah | veyi | Γ§ok | sev | er | ! ]  β‰ˆ 10 tokens

Agglutinative languages stack suffixes onto word roots, so they split into more tokens β€” roughly 2Γ— the tokens means 2Γ— the cost. It is worth knowing which languages your product serves.

That imbalance is not random. Most models are trained on web content, and the web leans heavily toward a few languages:

Source: W3Techs, top 10M sites, late 2025. Shares shift over time.

If tokens are how a model reads text, embeddings are how it represents meaning. Each token becomes a vector β€” a list of numbers β€” and similar meanings land close together in that space.

cat β€’     β€’ dog             β€’ kitten            β€’ king   β€’ coffee                β€’ queen              β€’ tea        β€’ man   β€’ woman

The classic party trick is that this space has structure you can do arithmetic on: king βˆ’ man + woman β‰ˆ queen. Embeddings are what power semantic search, recommendations, and RAG β€” and they deserve a deeper look of their own.

Every modern LLM is built on one architecture: the Transformer (that is the β€œT” in GPT). You do not need the math, but you should know the one idea that makes it work.

Attention means that when the model reads each word, it weighs every other word to decide what matters right now.

"The trophy didn't fit in the suitcase because it was too big."
it ──attends most to──► trophy   (not the suitcase)

That single idea buys two big wins: the model reads the whole input in parallel (fast on GPUs), and it captures long-range relationships that older models kept forgetting. The paper that introduced it, back in 2017, was fittingly titled β€œAttention Is All You Need.”

You have probably heard β€œgenerative AI” used as a catch-all. Here is the clean distinction.

A discriminative model judges or sorts existing content. A generative model creates new content: LLMs (text and code), diffusion models (images), speech and audio, video. An LLM is simply the text-shaped instance of generative AI.

You will hear a lot about the eye-watering cost of training frontier models. It comes down to a simple product.

πŸ’Έ Training cost β‰ˆ params Γ— tokens Γ— passes

Thousands of GPUs, weeks to months of runtime, tens to hundreds of millions of dollars β€” plus data cleaning, failed runs, and human feedback. But here is the good news for you: you will almost never train from scratch. Your job is to use and adapt models that already exist, which is dramatically cheaper.

The core trick is transfer learning: train once, then reuse and adapt many times. In practice you climb the cheapest rung that solves your problem.

RUNG                COST      WHEN TO USE ──────────────────────────────────────────────────────── 1. Prompting        cent      start here for ~everything 2. RAG              low       model needs YOUR / fresh knowledge 3. Fine-tuning      medium    need a consistent style / format / skill 4. Train scratch    extreme   almost never β€” only frontier labs ────────────────────────────────────────────────────────   β–² ~90% of real product work lives on rungs 1 & 2.

You will also hear these cost-cutting techniques thrown around:

If GitHub is where code lives, Hugging Face is where models live β€” an open hub of pre-trained models at every size. Tiny ones that run on a laptop, large open models like Llama, plus embedding models and image models, mostly free to build on. It is the main reason you rarely start from scratch: someone has usually already trained a model close to what you need.

This one trips up almost everyone at first. An LLM has no memory between calls. Each request is completely stateless. Chatbots seem to remember your conversation only because the app resends the whole history every single turn.

Everything the model can see fits inside its context window β€” measured, of course, in tokens.

Three practical consequences follow directly from this:

Once you accept that context is everything, RAG (retrieval-augmented generation) stops sounding fancy and starts sounding obvious.

The basic idea is nothing more than: put the right text in the prompt. The hard part β€” finding that text across thousands of documents β€” is the β€œretrieval” half, and it is a topic worth its own deep dive.

These two get confused constantly, so here is the clean mental model side by side.

The one-line version to remember:

They solve different problems, and in real systems they are often used together.

That is the whole map. AI contains ML contains deep learning contains LLMs. A model learns by guessing and correcting billions of times, trains once and runs inference forever. It reads text as tokens, represents meaning as embeddings, and pays attention across a limited context window. When it needs your knowledge, you reach for RAG; when it needs a new behavior, you reach for fine-tuning.

None of these ideas is as complicated as the jargon made it seem. You now share the vocabulary and the mental models that everything else builds on β€” and from here, it all compounds.

From Tokens to RAG: An AI Field Guide for Developers was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

── more in #artificial-intelligence 4 stories Β· sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/from-tokens-to-rag-a…] indexed:0 read:10min 2026-07-21 Β· β€”