keepcalculator

06 Numbers and Powers

LLM Basics for Developers: 8 Concepts That Matter

Card No. 06·36132 · Updated · Standard formula, shown below

LLM basics for developers come down to understanding how language models generate text, what their limits are, and how to build reliable applications around them. Eight concepts are especially useful: tokens, context windows, next-token prediction, prompting, embeddings, retrieval-augmented generation, tool use, and evaluation.

1. Tokens: The Model’s Units of Text

Language models do not usually process text as whole words. A tokenizer breaks text into tokens, which may be words, parts of words, punctuation, or other symbols. For example, a long or uncommon word might be split into several pieces, while a short common word may be one token. Tokenization depends on the model and its vocabulary.

Tokens matter in practice because models accept and generate token sequences. Input and output limits are generally measured in tokens, and usage may also be counted that way. A character count is only a rough estimate: code, unusual names, and non-English text can tokenize differently from ordinary prose.

When an application needs to stay within a model’s limits, count tokens using the relevant tokenizer where possible. Do not assume that trimming a fixed number of characters will produce a predictable token count.

2. Context Windows: What the Model Can Consider

A context window is the maximum amount of tokenized material a model can process for a particular request. Depending on the system, this can include instructions, conversation history, retrieved documents, tool results, and the model’s response. The exact limit varies by model and product, so check the documentation for the one being used.

A large context window does not guarantee that every detail in a long prompt will receive equal attention. Important facts can be overlooked, especially when they are buried in lengthy or repetitive material. For long conversations, applications may summarize earlier turns or retrieve only relevant passages rather than resend everything.

  • Keep persistent instructions concise and specific.
  • Include only conversation history that helps answer the current request.
  • Leave room for the response when constructing a request near the model’s input limit.

3. Next-Token Prediction: How Text Is Generated

A language model generates text by estimating a probability distribution over possible next tokens, then selecting a token and repeating the process. The process is conditioned on the prompt and the tokens already generated. This is why a model can produce fluent explanations, code, and summaries without retrieving a verified answer from a database for every sentence.

Fluency is not proof of truth. The model’s objective is to generate a plausible continuation, not inherently to check facts against the world. It can produce an incorrect statement confidently, follow a misleading premise, or make up a citation. For factual or consequential uses, connect generation to trustworthy data and verify outputs with appropriate checks.

Generation settings can affect variation. Lower randomness-oriented settings often make outputs more consistent, while higher settings can encourage diversity; exact controls and effects differ across systems. These settings do not turn an unverified answer into a verified one.

4. Prompting: Give the Model a Clear Task

A prompt is the input that describes the task and supplies relevant context. Good prompts define the goal, constraints, audience, and desired output. For example, “Summarize this incident report in five bullet points for an on-call engineer; distinguish confirmed facts from open questions” is more actionable than “Summarize this.”

For developer applications, separate durable instructions from user-provided content when the interface supports it. State what the model should do when information is missing, and request a structured format when software will consume the result. A JSON-shaped request alone does not guarantee valid JSON; use a supported constrained-output feature if available, then validate the result in your code.

  • Provide relevant examples when the desired style or format is hard to describe.
  • Specify boundaries, such as “use only the supplied text” or “return an empty list if there are no matches.”
  • Test prompts on ordinary, ambiguous, and adversarial inputs, not just a favorable example.

5. Embeddings: Representing Meaning for Search

An embedding is a numerical vector produced from text or another input. Embedding models are trained so that useful relationships in the data can be reflected in vector space. Applications commonly compare vectors with a similarity measure to find passages that are semantically related to a query, even when they do not share exact keywords.

Embeddings support semantic search, clustering, recommendations, and retrieval systems. They are not concise explanations of a passage, nor do they establish that two texts are factually equivalent. Similarity scores are ranking signals, not truth scores.

For a document search system, a typical workflow is to split documents into passages, create and store an embedding for each passage, embed a user query, and retrieve promising matches. Passage size and overlap affect results: chunks that are too small may lose context, while chunks that are too large can make retrieval less focused.

6. Retrieval-Augmented Generation: Ground Answers in Sources

Retrieval-augmented generation, or RAG, combines a language model with a search or retrieval step. The application finds relevant material, includes selected passages in the model’s prompt, and asks for an answer based on that material. This can make answers more useful for private, changing, or specialized information that was not included in the model’s training.

RAG does not automatically make an answer correct. Search can miss the right passage, return outdated information, or rank irrelevant material highly. The model can also misread the retrieved text or make claims that the sources do not support. A robust system can show citations linked to the actual retrieved passages and let users inspect them.

  • Prepare documents carefully, preserving headings and useful metadata.
  • Measure retrieval quality separately from the quality of the generated answer.
  • Test questions with no answer in the source material and define when the system should say it cannot answer.

7. Tool Use: Let the Application Take Actions

Tool use lets a model request an operation that an application makes available, such as searching a catalog, running a calculation, or looking up a record. The model typically returns a structured request; the application executes it and provides the result for the model to use. The model does not gain access to a tool merely by mentioning it in a prompt.

Keep control of execution in ordinary application code. Validate arguments, enforce permissions, and handle failures and timeouts. Treat model-generated tool requests as untrusted input. A request to send a message, change a record, or trigger another side effect should follow appropriate authorization and confirmation rules rather than being executed just because the model proposed it.

8. Evaluation and Reliability: Test the Whole System

Evaluation is the process of checking whether a model-powered application meets its requirements. A single impressive example is not a meaningful test. Build a representative set of inputs and expected behaviors, including common cases, edge cases, ambiguous requests, and cases where the correct response is to abstain or ask for clarification.

Assess the parts that can fail independently: retrieval, formatting, tool selection, factual support, latency, and error handling. Automated checks can catch predictable issues, while human review is often needed for nuanced quality. After changing a prompt, model, document collection, or application code, rerun relevant tests. Production monitoring can reveal failures that were absent from the test set, but logs should be designed with privacy and data-retention requirements in mind.

Frequently Asked Questions

Are LLMs databases?
No. A model generates responses from learned patterns and its current input; it is not a dependable database lookup mechanism. Use a source of record or retrieval system when an answer must reflect specific, current data.

Does a bigger context window mean better answers?
Not necessarily. It allows more material to be included, but irrelevant or poorly organized context can distract from the task. Select and structure context rather than simply sending everything.

Do embeddings understand meaning?
They encode text into vectors that can support useful similarity comparisons. That is not the same as human understanding, and vector similarity alone cannot confirm that a claim is correct.

Does RAG eliminate hallucinations?
No. RAG supplies potentially relevant source material, but retrieval and generation can both fail. Ground claims in cited passages and test cases where sources are incomplete or absent.

Should developers fine-tune a model instead of using RAG?
They solve different problems. RAG supplies external information at request time; fine-tuning changes model behavior through additional training. Choose based on the task, data, update needs, and available evaluation evidence rather than assuming one replaces the other.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →