---
title: "11 — LLM Fundamentals — Next-Token Prediction, Embeddings, and Vectors"
uid: llm-fundamentals
tags: ["llm", "roadmap:backend", "ai", "embeddings", "machine-learning", "fundamentals", "vectors"]
excerpt: "Three ideas under every backend AI tool: an LLM is a next-token predictor over a vocabulary, embeddings make meaning arithmetic, vectors are the space those coordinates live in."
date: 2026-08-13T03:28:25+0000
source: https://www.aveshina.my.id/en/blog/llm-fundamentals
---

I used to wave the backend roadmap's AI nodes off as ML-specialist trivia a backend dev could skip — until every AI tool in the roadmap turned out to sit on the same three ideas. The base that corrected that: **an LLM is a next-token predictor over a vocabulary; embeddings are the numeric coordinates that turn meaning into something arithmetic; vectors are the space those coordinates live in.** [1] The backend AI tools that fill the rest of the roadmap — Copilot, RAG, function calling, agents — are all built on these three ideas, and I can't reason about any of them without this base.

The frame that helped is that "AI" in the backend context is not one thing; it's a stack. At the bottom is the math (vectors). One layer up is the representation (embeddings — where meaning becomes vectors). One layer up is the model that consumes those representations (an LLM predicting the next token). Everything above — code completion, chatbots, agents, RAG — is plumbing around that core. Once the three foundation ideas are clear, the rest of the roadmap stops being a list of magic product names and becomes a set of engineering choices.

```figure
<svg viewBox="0 0 740 300" xmlns="http://www.w3.org/2000/svg" class="my-6 w-full max-w-2xl" role="img" aria-label="Three panels showing the AI foundation stack. Left panel: next-token prediction — a sentence 'the cat sat on the' with a probability cloud of candidate next words (mat 60%, floor 15%, chair 10%). Middle panel: embeddings — words plotted as dots in 2D, with similar words (king, queen) clustering together. Right panel: vectors — an arrow from the origin with magnitude and direction, labelled with numeric components. Arrows connect the panels left-to-right.">
  <g font-family="ui-sans-serif, system-ui, sans-serif" text-rendering="geometricPrecision">

    <!-- LEFT: next-token -->
    <rect x="30" y="40" width="210" height="220" rx="10" fill="#e0e7ff" stroke="#6366f1" stroke-width="1.5"/>
    <text x="135" y="62" font-size="12" font-weight="700" fill="#1e1b4b" text-anchor="middle">next-token prediction</text>
    <text x="135" y="95" font-size="11" font-family="ui-monospace, monospace" fill="#1e1b4b" text-anchor="middle">"the cat sat on the"</text>
    <text x="135" y="115" font-size="10" fill="#64748b" text-anchor="middle">▾</text>
    <rect x="55" y="125" width="160" height="22" rx="4" fill="#dcfce7" stroke="#16a34a"/>
    <text x="135" y="140" font-size="10" font-family="ui-monospace, monospace" fill="#052e16" text-anchor="middle">"mat"   60%</text>
    <rect x="55" y="151" width="160" height="22" rx="4" fill="#fef9c3" stroke="#ca8a04"/>
    <text x="135" y="166" font-size="10" font-family="ui-monospace, monospace" fill="#422006" text-anchor="middle">"floor" 15%</text>
    <rect x="55" y="177" width="160" height="22" rx="4" fill="#fee2e2" stroke="#dc2626"/>
    <text x="135" y="192" font-size="10" font-family="ui-monospace, monospace" fill="#7f1d1d" text-anchor="middle">"chair" 10%</text>
    <text x="135" y="230" font-size="9" font-style="italic" fill="#64748b" text-anchor="middle">a probability distribution</text>
    <text x="135" y="244" font-size="9" font-style="italic" fill="#64748b" text-anchor="middle">over the vocabulary</text>

    <!-- connector -->
    <line x1="240" y1="150" x2="270" y2="150" stroke="#64748b" stroke-width="1.5"/>

    <!-- MIDDLE: embeddings -->
    <rect x="270" y="40" width="210" height="220" rx="10" fill="#fef9c3" stroke="#ca8a04" stroke-width="1.5"/>
    <text x="375" y="62" font-size="12" font-weight="700" fill="#422006" text-anchor="middle">embeddings — meaning as points</text>
    <g>
      <circle cx="320" cy="120" r="4" fill="#ca8a04"/>
      <text x="328" y="124" font-size="9" fill="#422006">king</text>
      <circle cx="335" cy="135" r="4" fill="#ca8a04"/>
      <text x="343" y="139" font-size="9" fill="#422006">queen</text>
      <circle cx="345" cy="155" r="4" fill="#ca8a04"/>
      <text x="353" y="159" font-size="9" fill="#422006">prince</text>
      <circle cx="420" cy="195" r="4" fill="#db2777"/>
      <text x="428" y="199" font-size="9" fill="#500724">apple</text>
      <circle cx="435" cy="215" r="4" fill="#db2777"/>
      <text x="443" y="219" font-size="9" fill="#500724">orange</text>
      <circle cx="410" cy="230" r="4" fill="#db2777"/>
      <text x="418" y="234" font-size="9" fill="#500724">banana</text>
    </g>
    <text x="375" y="105" font-size="9" font-style="italic" fill="#64748b" text-anchor="middle">similar items cluster</text>

    <!-- connector -->
    <line x1="480" y1="150" x2="510" y2="150" stroke="#64748b" stroke-width="1.5"/>

    <!-- RIGHT: vector -->
    <rect x="510" y="40" width="210" height="220" rx="10" fill="#dcfce7" stroke="#16a34a" stroke-width="1.5"/>
    <text x="615" y="62" font-size="12" font-weight="700" fill="#052e16" text-anchor="middle">vector — magnitude + direction</text>
    <line x1="550" y1="220" x2="680" y2="220" stroke="#94a3b8" stroke-width="1"/>
    <line x1="550" y1="100" x2="550" y2="220" stroke="#94a3b8" stroke-width="1"/>
    <line x1="550" y1="220" x2="650" y2="130" stroke="#16a34a" stroke-width="2.5"/>
    <polygon points="650,130 642,134 645,142" fill="#16a34a"/>
    <circle cx="550" cy="220" r="3" fill="#16a34a"/>
    <text x="555" y="234" font-size="9" fill="#64748b">origin</text>
    <text x="640" y="125" font-size="9" font-family="ui-monospace, monospace" fill="#052e16">[0.7, -0.8]</text>
    <text x="615" y="180" font-size="9" font-style="italic" fill="#64748b" text-anchor="middle">the arithmetic underneath</text>
  </g>
</svg>
```

## Next-token prediction: what an LLM actually does

Strip away the mythology and an **LLM is a model that, given a sequence of tokens, outputs a probability distribution over what the next token could be** [1][2]. The input is the text so far; the output is a list of candidate next tokens, each with a probability. The model then samples one (guided by parameters like **temperature** — high temperature spreads probability toward less likely tokens, low temperature concentrates on the most likely), appends it to the input, and repeats. Token by token, the response is built.

The thing to internalize is that this is *probabilistic pattern-matching over a huge training corpus*, not retrieval or reasoning in the human sense. The model has learned, from trillions of tokens of text, what tends to follow what. "The cat sat on the" is followed by "mat" more often than "chair" in the training data, so "mat" gets higher probability. The miracle is that doing this competently at scale produces behavior that *looks* like understanding — enough that the distinction gets blurry in practice. But the mechanism is next-token prediction, full stop.

Two consequences for backend work:

- **No determinism by default.** The same prompt can yield different outputs, controlled by temperature and sampling. If I need determinism (a function that returns parseable JSON), I set temperature low and use constrained decoding or structured output modes.
- **Context is the only memory.** The model has no persistent state between requests beyond what I put in the prompt. Every conversation history, every document, every instruction lives in the context window of the current request. That's why context management (and RAG — more in a later post) is the central backend problem of LLM applications.

## Embeddings: meaning as coordinates

An **embedding** is a dense vector representation of a piece of data — a word, a sentence, an image — in a lower-dimensional space where *similar items end up close together* [3]. The classic demonstration: in a well-trained embedding space, the vector for "king" minus the vector for "man" plus the vector for "woman" lands you near "queen." The model has captured enough of the *meaning* of these words that analogies become arithmetic.

The reason embeddings matter for backend work is that they make **similarity computable**. Two pieces of text can be compared by computing the distance (cosine similarity, usually) between their embedding vectors. "Cat sat on the mat" and "the feline rested on the rug" have similar embeddings because they mean similar things, even though they share few words. That capability is the foundation of semantic search, retrieval (RAG), recommendation, and clustering — all of which are backend features, not ML research.

The practical pipeline: I take a body of text (a doc, a knowledge base), pass each chunk through an embedding model to get a vector, store those vectors in a vector database (or a Postgres + pgvector), and at query time embed the user's query and find the nearest stored vectors. The model does the magic once (turning text into coordinates); the rest is the database work I already know.

## Vectors: the arithmetic underneath

A **vector** is a mathematical object with magnitude and direction, represented as an ordered list of numbers — its components [4]. In ML, a 768-dimensional vector is just a list of 768 floats. The vector is the substrate embeddings and model internals all live on; "embedding" is a vector whose coordinates happen to encode meaning, and an LLM's internal state is a vector whose coordinates encode the evolving context.

The operations that matter for backend AI work are few:

- **Distance / similarity.** Cosine similarity (angle between two vectors) or Euclidean distance (straight-line). How close are two embeddings?
- **Averaging.** Mean of a set of vectors — sometimes used to summarize a body of text.
- **Nearest-neighbor search.** Given a query vector, find the closest stored vectors — the core operation of a vector database.

I don't need to implement any of these; I need to know they exist, because the APIs of every vector DB (Pinecone, Weaviate, pgvector) are built around them. "Find me the 10 documents most similar to this query" is a nearest-neighbor search over embeddings, and knowing that lets me reach for the right tool.

## AI vs. traditional software development

One more framing node from the roadmap: the contrast between traditional and AI-assisted development [5]. Traditional development is deterministic and explicit — I write every step, the computer follows it exactly. AI-assisted development delegates some of the "write the step" work to a model that proposes code based on patterns it learned. The model is probabilistic; correctness comes from review, testing, and iteration rather than from the model being guaranteed right.

This isn't a replacement of traditional development; it's a tool layered on top. The backend still runs deterministic code; the AI helps write it. The shift in mindset is being comfortable with "the model suggested this, now I verify it" rather than "I wrote this, therefore it does what I intended." Both modes still demand the same end state: tested, correct code in production. The AI changes the *writing* speed, not the *verification* obligation.

## How I use this

The three foundation ideas translate into three concrete habits:

- **Treat LLM outputs as probabilistic.** I set temperature appropriately, use structured output modes when I need parseable results, and never assume the same prompt gives the same answer twice. For deterministic flows I constrain the model and validate its output.
- **Reach for embeddings when I need semantic similarity.** Keyword search is brittle; embedding search captures meaning. For any "find related X" feature, the first question is now "should this be embedding-based?"
- **Context window is a backend budget.** Everything the model needs must fit in the prompt, which makes context selection (what to include, what to truncate) a real engineering problem. RAG, summarization, and tool-calling are all solutions to the context-budget problem.

The framing — *predict, embed, vector* — is the load-bearing idea. Every AI feature in the rest of the roadmap (Copilot suggesting code, RAG retrieving docs, an agent calling a function) is an application of these three. Knowing the foundation makes the features legible.

## References

[1] Cloudflare, "What is a large language model (LLM)?," 2024. [Online]. Available: [https://www.cloudflare.com/en-gb/learning/ai/what-is-large-language-model/](https://www.cloudflare.com/en-gb/learning/ai/what-is-large-language-model/)

[2] "New to LLMs? Start Here," Towards Data Science. [Online]. Available: [https://towardsdatascience.com/new-to-llms-start-here/](https://towardsdatascience.com/new-to-llms-start-here/)

[3] Cloudflare, "What are Embeddings in Machine Learning?," 2024. [Online]. Available: [https://www.cloudflare.com/en-gb/learning/ai/what-are-embeddings/](https://www.cloudflare.com/en-gb/learning/ai/what-are-embeddings/)

[4] "A Gentle Introduction to Vectors for Machine Learning," Machine Learning Mastery. [Online]. Available: [https://machinelearningmastery.com/gentle-introduction-vectors-machine-learning/](https://machinelearningmastery.com/gentle-introduction-vectors-machine-learning/)

[5] "What is vibe coding?," IBM, 2024. [Online]. Available: [https://www.ibm.com/think/topics/vibe-coding](https://www.ibm.com/think/topics/vibe-coding)

```quiz
Q: What does an LLM actually output at each step?
- A probability distribution over possible next tokens, which is then sampled
- A single definitively correct next token
correct: 0
explain: An LLM outputs probabilities for the whole vocabulary at each step; sampling (guided by temperature) picks one. Token by token, the response is built. The mechanism is probabilistic pattern-matching, not retrieval or guaranteed correctness.

Q: What does the temperature parameter control?
- How spread the probability is — high temperature allows less likely tokens; low temperature concentrates on the most likely
- The maximum number of tokens in the response
correct: 0
explain: Temperature shapes the sampling distribution. High temperature spreads probability toward unlikely tokens (more creative/random); low temperature concentrates on the top candidates (more deterministic). For parseable output, set it low.

Q: What does an embedding encode, and why is that useful for backend work?
- It encodes meaning as vector coordinates, making similarity between items computable (nearest-neighbor search, semantic retrieval)
- It compresses text to save storage space
correct: 0
explain: Embeddings place semantically similar items close together in vector space, so similarity becomes a distance calculation. This is the foundation of semantic search, RAG, recommendation, and clustering — all backend features.

Q: Why is the context window described as a backend budget?
- The model has no memory beyond the current prompt; everything it needs must fit in the context, so selecting what to include is a real engineering problem
- The context window stores the model's training data
correct: 0
explain: The model's only memory per request is the prompt. Conversation history, retrieved documents, and instructions all compete for context space. RAG, summarization, and tool-calling are all strategies to manage this budget.

Q: How does AI-assisted coding differ from traditional coding in terms of correctness?
- The model proposes probabilistically; correctness still comes from review, testing, and iteration — the verification obligation is unchanged
- The model guarantees correct output, so testing is unnecessary
correct: 0
explain: AI assistance changes writing speed, not verification obligation. The model is probabilistic; production correctness still comes from review and tests. The mindset shift is being comfortable verifying model-suggested code rather than assuming it's right.
```
