By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
You will never be asked to train a model to do this job. You will constantly be asked why an answer got cut off, why the bot ignored a document that was clearly in the search results, or why the same prompt behaves differently in staging and production. Every one of those questions is answered by three ideas: tokens, the context window, and sampling.
Models do not read characters or words. They read tokens — chunks of text roughly three-quarters of an English word. unbelievable might be two tokens; cat is one; a number like 4521 is often one or two.
Tokens matter for one practical reason: everything is measured in them. The context window is a token budget. Pricing is per token. Rate limits are per token. Truncation happens at a token boundary, mid-sentence, silently.
# Rough estimate only - real tokenisers differ per model family.
def approx_tokens(text: str) -> int:
return max(1, len(text) // 4)
system = 'You are Nova, the support assistant for Acme Outfitters.'
docs = open('help_centre.md').read() # 12 kB of help articles
user = 'Can I return a sale item?'
print(approx_tokens(system + docs + user)) # about 3,100 tokensThe context window is everything the model can see in one call: system prompt, conversation history, retrieved documents, the user's question, and the room left for the answer. Think of it as the size of the desk. You can only work with what fits on the desk, and the model has no memory of what you took off it.
The failure this causes in production is nastier than a truncation error. When the retrieved chunk containing the actual policy gets pushed out of the window, the model does not say 'I lost the document'. It answers confidently from whatever is left — usually general knowledge about how returns normally work. That is a hallucination with a perfectly innocent cause.
| Setting | What it does | How it shows up in testing |
|---|---|---|
| temperature | Higher = more random token choice | 0.0–0.3 for factual answers, 0.7+ for creative copy. High temperature on a support bot manufactures hallucinations. |
| top_p | Restricts choices to likely tokens | Another variance dial. Change one dial at a time or your test results become unexplainable. |
| max_tokens | Hard cap on the answer length | Truncation looks like a formatting bug. Always assert 'the answer ended with a full stop'. |
| stop sequences | Stops generation at a marker | Easy to break silently when prompts change; a classic regression cause. |
| seed (if supported) | Asks for repeatable sampling | Helpful for debugging, never a substitute for tolerant assertions. |
Retrieval systems do not search for keywords. They convert text into embeddings — lists of numbers where similar meanings sit close together. 'Refund' and 'money back' land near each other even though they share no letters. That is why search works on meaning, and also why it fails in a specific way: it returns things that are semantically nearby but factually wrong — every chunk about returns, including the one for a different country.
Key takeaways
Everything is measured in tokens: cost, limits, and truncation.
The context window is a budget; when it fills, documents fall off silently and answers get confidently wrong.
Temperature and top_p control variance — tune one at a time.
Embeddings retrieve by meaning, which produces 'nearby but wrong' documents.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.