4.4.10 · D1Alignment, Prompting & RAG

Foundations — Prompt engineering best practices

1,606 words7 min readBack to topic

Before you can read the parent note fluently, you need to see what each symbol and word means. This page builds every one of them from absolute zero. We go slowly and in order — each idea leans only on the ones above it.


0. What is "text" to a machine? — the token

The picture: imagine a long train, and each carriage holds one token. The model reads the carriages left to right.

Why the topic needs it: the whole game of prompting is choosing which carriages to put at the front of the train. When the parent note says "next-token predictor," token is that carriage.


1. The symbol — one token at a time

So is the first token, the second, and so on. The little underneath is just a label saying "which one."

The picture: put a number under each carriage in the train above. = "the token in carriage 3."

Why the topic needs it: the model generates text one carriage at a time, left to right. To talk about "the next one," we must be able to point at "position ."


2. The symbol — "everything before now"

The tiny <t is literally saying "positions less than ."

The picture: stand at carriage and look backwards. Everything behind you is .

Why the topic needs it: the model decides the next token by looking only at what came before it. That backward-looking pile of text is exactly .


3. The bar — "given that…"

The picture: a spinner whose slices resize depending on the context you feed it.

Why the topic needs it: when the parent writes , it is saying "the probability of an answer, given your prompt." Rewriting the prompt reshapes the spinner.


4. The distribution — a spinner over all possible next tokens

The picture (see figure above): the spinner has one slice per possible next word. A big slice = "very likely next." The model "samples" by spinning and reading where it lands.

Why the topic needs it: "steering the distribution" (parent's phrase) literally means "reshaping this spinner" toward the slice you want.


5. The product symbol — building a sentence token by token

So the parent formula reads in plain words: "the chance of the whole answer is the chance of token 1 (given the prompt), times the chance of token 2 (given the prompt and token 1), times the chance of token 3, … all the way to the end."

The picture: a chain of links. Each link is one token's probability; multiply them all to get the strength of the whole chain.

Why the topic needs it: it shows why generation is left-to-right and step-by-step, which is the deep reason Chain-of-Thought works — more tokens means more links to spread hard computation across.


6. The context window — how far back the model can see

The picture: a fixed-width viewing frame sliding over the token train. Only carriages inside the frame count as .

Why the topic needs it: the prompt lives inside this window. It explains the "lost in the middle" mistake — the model attends less to carriages sitting in the middle of a very long frame, so key instructions go at the start and end.


7. — the number of examples (shots)

The picture: demonstration cards laid on the table before you ask the real question.

Why the topic needs it: few-shot prompting and in-context learning are defined by . The examples reshape the spinner without ever changing the model's internal numbers ("no weight update").


8. Putting it together — the prerequisite map

Each foundation feeds the next, and together they feed the topic:

Token = a text carriage

Position x_t

History x before t

Given bar = conditional P

Distribution = the spinner

Entropy = spinner spread

Product Pi = chain of tokens

Context window = viewing frame

Few-shot count k

Prompt engineering

Related deeper pages once these click: Temperature and sampling (how the spin actually picks a slice), Retrieval-Augmented Generation (RAG) (stuffing facts into the window), Prompt injection & LLM security (attacks through the same input channel), Hallucination in LLMs (confident wrong slices), and Alignment & RLHF (how the spinner got shaped in training).


Equipment checklist

Test yourself — cover the right side and answer aloud.

What is a token?
A small piece of text (word or word-fragment) the model reads and writes; the "carriage" of the token train.
What does mean?
The token at position — carriage number .
What does mean?
All tokens before position — everything the model looks back at to guess the next one.
How do you read ?
"The probability of given " — the chance of once is known/assumed.
What is a probability distribution here?
The full fan of chances over every possible next token, all summing to — the "spinner."
What does high entropy mean for the spinner?
It is flat/spread-out — the model is uncertain and may sample a wrong-but-common token.
What does do, and why multiply?
Multiplies each token's probability together; we multiply because all tokens must occur in sequence (AND), like consecutive coin flips.
What is the context window?
The maximum number of tokens the model can view at once — the frame the prompt must fit inside.
What does count, and what are zero-shot vs few-shot?
= number of worked examples; is zero-shot, is few-shot.