AI Engineering Glossary: LLM, RAG, Agent, and MCP Terms Explained
Plain-English definitions of the AI engineering terms used across this wiki, from tokens and embeddings to RAG, tool use, agents, MCP, and evals.
On this page· Where the terms fit
Why this matters
AI engineering has its own vocabulary, and much of it is used loosely online: "agent" means anything from a single prompt to an autonomous system, and "RAG" is used for any app that touches a database. Precise words make precise designs. These are the definitions this wiki uses. Each entry starts with a one-sentence summary, followed by the details that matter when you build with it.
Where the terms fit#
Most terms name a part of this architecture, or something that flows through it:
Hover or tap a component to see what it does.
Show text descriptionHide text description
The diagram shows a production AI web application as boxes inside two trust zones: your own infrastructure, and third-party model APIs. Solid arrows are requests, dashed arrows are asynchronous jobs and telemetry, and arrows with moving dots are streamed responses.
- User: The person using your product in a browser or mobile app.
- React UI: Renders the chat or feature UI, sends requests to your API, and renders streamed tokens as they arrive. Never holds model API keys.
- API layer: The only place that talks to model providers. Validates input, checks auth and rate limits, assembles context, calls the model, and streams the answer back over Server-Sent Events.
- Auth: Identifies the user and decides what data and tools they may access. Every model call and tool call inherits these permissions.
- Redis: Fast key-value store for per-user rate limits, response caching, and short-lived session state.
- Postgres: The system of record: users, conversations, and documents. The pgvector extension stores embeddings so the same database answers similarity searches for RAG.
- Job queue: Holds slow work (document indexing, long agent runs, batch jobs) so API requests return quickly. Jobs survive restarts and can be retried.
- Workers: Node.js processes that pull jobs from the queue: chunk documents, request embeddings, write vectors to Postgres, and run long tasks with retries.
- Observability: Collects a trace for every request and job, with prompts, token counts, latency, and cost, so you can debug bad answers and run evals on real traffic.
- Model APIs: Hosted models reached over HTTPS: an LLM for generation and tool use, and an embedding model for vector search. Stateless: every request must carry its full context.
Chat request. The UI posts the message to your API, which verifies the session, checks the rate limit in Redis, retrieves context from Postgres, calls the model, and streams tokens back to the browser over SSE.
Document indexing. An upload is acknowledged immediately and queued. A worker chunks the document, requests embeddings from the model API, and writes the vectors to pgvector.
Observability. The API and workers emit a trace for every request and job, with token counts, latency, and cost. Traces feed dashboards, alerts, and evals on real traffic.
Definitions#
A
- Agent
A system where an LLM decides its own next steps in a loop, calling tools and reading their results until a goal is met.
An agent gives the model control over the sequence of steps: it chooses which tool to call, observes the result, and decides what to do next. This flexibility suits open-ended tasks but costs more, takes longer, and is harder to test than a fixed workflow, so agents need step limits, permissions, and evals.
See also: Workflow, Tool use (function calling), Agent loop
- Agent loop
The cycle of calling the model, executing any tools it requests, appending the results, and calling it again until it stops.
Your code runs the loop: send the conversation and tools, check stop_reason, execute requested tools, append tool_result blocks, and repeat. Production loops cap the number of iterations, time, and cost, and log every step so failures can be traced.
See also: Agent, Tool use (function calling), Stop reason
C
- Chunking
Splitting documents into smaller passages so each one can be embedded and retrieved on its own.
Good chunks are self-contained: they follow headings or paragraphs, run a few hundred tokens, and carry metadata such as source URL, title, and section. Chunk size is a trade-off between precise retrieval (small chunks) and enough surrounding context (larger chunks).
See also: Embedding, RAG (retrieval-augmented generation)
- Context engineering
Deciding exactly which instructions, data, tools, and history the model sees on each request.
Models only know what is in the request. Context engineering covers the system prompt, which documents to retrieve, how to summarize long histories, which tools to expose, and in what order to place it all so the request is accurate, cheap, and cache-friendly.
See also: Context window, System prompt, RAG (retrieval-augmented generation)
- Context window
The maximum number of tokens a model can read and write in one request, including the system prompt, history, tools, and output.
Everything the model knows about your task must fit in the context window: instructions, tool definitions, conversation history, retrieved documents, and room for the answer. A larger window is not free: every token you send costs money and adds latency, so context engineering is about sending the right tokens, not the most.
See also: Token, Context engineering, Prompt caching
E
- Embedding
A list of numbers that represents the meaning of a piece of text, so that similar meanings end up close together.
An embedding model turns text into a vector with hundreds or thousands of dimensions. Measuring the distance between vectors (usually cosine similarity) finds passages that mean the same thing even when they share no keywords, which is the basis of semantic search and RAG.
See also: Vector database, RAG (retrieval-augmented generation), Hybrid search
- Eval
A repeatable test that scores an AI feature's outputs on a dataset of real examples.
Evals are the unit tests of AI engineering. Each case pairs an input with a way to grade the output: exact checks in code, schema validation, or an LLM judge with a rubric. Running the suite before every prompt, model, or retrieval change turns guesswork into measurable progress and catches regressions.
See also: LLM-as-judge, Observability
H
- Hallucination
A confident model output that is false or not supported by the provided sources.
Models generate plausible text, not verified facts. Hallucinations are reduced by grounding answers in retrieved sources, asking for citations, allowing the model to say it does not know, and checking outputs with evals, but they are never eliminated entirely.
See also: RAG (retrieval-augmented generation), Eval
- Hybrid search
Combining vector (semantic) search with keyword search and merging the results.
Vector search finds passages with similar meaning; keyword search (such as BM25 or Postgres full-text search) finds exact terms like error codes, product names, and IDs. Merging both result lists, often with reciprocal rank fusion, and then reranking gives better retrieval than either alone.
See also: Embedding, Reranking, RAG (retrieval-augmented generation)
L
- LLM (large language model)
A neural network trained on large amounts of text that generates output one token at a time by predicting what comes next.
LLMs such as Claude are reached through an API. They are stateless: each request must include all the context the model needs, and the response is generated token by token, which is why responses can be streamed.
See also: Token, Context window, Streaming
- LLM-as-judge
Using a model with a written rubric to grade another model's output when code checks are not enough.
Some qualities, such as helpfulness, tone, or faithfulness to sources, cannot be checked with string matching. A judge prompt with a clear rubric and a structured score can grade them at scale. Validate the judge against human labels before trusting it.
See also: Eval
M
- MCP (Model Context Protocol)
An open protocol for connecting AI applications to external tools and data through standard servers.
An MCP server exposes tools, resources, and prompts over a standard interface; an MCP client inside a host application (such as an IDE or chat app) connects to it. Build a capability once as an MCP server and any MCP-compatible application can use it.
See also: Tool use (function calling), Agent
O
- Observability
Recording traces of every model and tool call, with inputs, outputs, tokens, latency, and cost.
AI features fail in ways logs alone do not explain. A trace shows the full tree of calls behind one request so you can see which retrieved document misled the model or which tool call was slow. Traces also feed evals with real production cases.
See also: Eval, Agent loop
P
- Prompt caching
Reusing the processed prefix of a prompt across requests to cut cost and latency.
When many requests share the same beginning (system prompt, tool definitions, a long document), the provider can cache that prefix. Cached input tokens are billed at a fraction of the normal price and start faster. Caching is a prefix match, so stable content must come first and changing content last.
See also: Context window, Token
- Prompt injection
An attack where text in user input or retrieved content tries to override your instructions.
Any text the model reads, including web pages, emails, documents, and tool results, can contain instructions like "ignore previous instructions". Defenses are layered: least-privilege tools, human approval for risky actions, separating trusted instructions from untrusted data, and output validation. No prompt alone fully prevents it.
See also: Tool use (function calling), Agent
R
- RAG (retrieval-augmented generation)
Retrieving relevant passages from your own data and giving them to the model so it answers from those sources.
RAG has two paths: indexing (chunk documents, embed them, store vectors) and querying (embed the question, retrieve similar chunks, rerank, and generate an answer with citations). It keeps answers current and grounded without retraining the model.
See also: Embedding, Chunking, Vector database, Reranking
- Reranking
Re-scoring retrieved candidates with a more precise model and keeping only the best few.
Vector search is fast but approximate. A reranker reads the question and each candidate passage together and scores relevance more accurately. A common setup retrieves 20 to 50 candidates and keeps the top 3 to 5 for the prompt.
See also: RAG (retrieval-augmented generation), Hybrid search
S
- Stop reason
The field in a model response that says why generation ended, such as end_turn, max_tokens, or tool_use.
Always check stop_reason before using a response. end_turn means the model finished; max_tokens means the output was cut off; tool_use means the model is waiting for you to run a tool; refusal means it declined. Each needs different handling in your code.
See also: Tool use (function calling), Agent loop
- Streaming
Sending the response to the client token by token as it is generated instead of waiting for the full answer.
Streaming makes long answers feel fast because the first words appear within a second or two. In web apps the server usually relays model events to the browser with Server-Sent Events (SSE), and the UI appends text as chunks arrive.
See also: LLM (large language model), Token
- Structured output
Constraining the model to return data that matches a schema, such as JSON validated with Zod.
Free-form text is hard for code to consume. With structured outputs you describe the expected shape with a JSON Schema and the response is guaranteed to parse, so your app can store, display, or act on it reliably. Still validate business rules in code.
See also: Tool use (function calling)
- System prompt
Instructions sent separately from the conversation that set the model's role, rules, and output format.
The system prompt is where you define who the model is acting as, what it must and must not do, and how to format answers. Keep it stable across requests so it can be cached, and put user-provided data in messages rather than in the system prompt.
See also: Context engineering, Prompt caching
T
- Token
The unit of text a model reads and writes: a word, part of a word, or punctuation, roughly 3 to 4 characters of English on average.
Models process text as tokens, and you are billed per input and output token. Context windows, output limits, rate limits, and latency are all measured in tokens, so estimating token counts is a core skill for cost and performance work.
See also: Context window, LLM (large language model)
- Tool use (function calling)
Letting a model request that your code run a function, such as a database lookup, and use the result in its answer.
You describe each tool with a name, description, and input schema. The model replies with a tool_use block when it wants one; your code validates the input, runs the function with the user's permissions, and returns a tool_result. The model never executes anything itself.
See also: Agent loop, MCP (Model Context Protocol), Stop reason
V
- Vector database
A database that stores embeddings and finds the nearest vectors to a query quickly.
Vector stores keep each chunk's text, metadata, and embedding, with an approximate nearest-neighbor index such as HNSW for fast similarity search. For many apps, Postgres with the pgvector extension is enough and keeps vectors next to the rest of your data.
See also: Embedding, RAG (retrieval-augmented generation)
W
- Workflow
An LLM system whose steps are fixed in code, such as a chain or router, as opposed to an agent that decides its own steps.
Workflows are predictable, cheaper, and easier to test than agents. Patterns include prompt chaining, routing, parallelization, orchestrator-workers, and evaluator-optimizer. Most production features should start as a workflow and only become agentic when the task demands it.
See also: Agent
Use the terms in your own docs#
Linking the first mention of each technical term in a README or design doc helps readers who are new to the field. This small function does it for any glossary you give it, skipping code and existing links:
export interface TermLink {
term: string; // as written in prose, such as "prompt caching"
href: string;
}
/** Link the first mention of each term in Markdown prose. Code spans, code blocks, and existing links are left alone. */
export function linkFirstMentions(markdown: string, terms: TermLink[]): string {
// Split into protected parts (fenced code, inline code, links) and prose.
const parts = markdown.split(/(`{3}[\s\S]*?`{3}|`[^`\n]+`|\[[^\]]*\]\([^)]*\))/g);
const linked = new Set<string>();
const sorted = [...terms].sort((a, b) => b.term.length - a.term.length); // "prompt caching" before "prompt"
return parts
.map((part, i) => {
if (i % 2 === 1) return part; // protected
let out = part;
for (const { term, href } of sorted) {
if (linked.has(term)) continue;
const re = new RegExp(`\\b(${term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})\\b`, "i");
if (re.test(out)) {
out = out.replace(re, `[$1](${href})`);
linked.add(term);
}
}
return out;
})
.join("");
}import { test } from "node:test";
import assert from "node:assert/strict";
import { linkFirstMentions } from "./lib/link-terms.ts";
const terms = [
{ term: "RAG", href: "/reference/glossary#rag" },
{ term: "prompt caching", href: "/reference/glossary#prompt-caching" },
];
test("links only the first mention, case-insensitively", () => {
const out = linkFirstMentions("We use rag here. RAG again, with Prompt caching.", terms);
assert.equal(out, "We use [rag](/reference/glossary#rag) here. RAG again, with [Prompt caching](/reference/glossary#prompt-caching).");
});
test("leaves code and existing links alone", () => {
const md = "Call `enableRAG()` and read [our RAG notes](https://example.com). Then RAG.";
assert.equal(linkFirstMentions(md, terms), "Call `enableRAG()` and read [our RAG notes](https://example.com). Then [RAG](/reference/glossary#rag).");
});Common mistakes#
- Calling every LLM feature an agent. If code decides the steps, it is a workflow.
- Calling any database lookup RAG. RAG means retrieving relevant passages to ground a model's answer.
- Using "hallucination" for every wrong answer. Many wrong answers are retrieval failures or missing context; name the cause.
- Confusing the context window with memory. The context window is per request; memory is something you build.
Try it
Explain it back
- Pick five terms you use often and write a one-sentence definition of each without looking.
- Compare with the entries above and note any differences.
- Run
linkFirstMentionson one of your project READMEs with links to the entries you used.
Check your understanding
Key takeaways
- Precise vocabulary leads to precise designs: workflow versus agent, retrieval versus memory, context window versus state.
- Hover any dotted term in the wiki for its definition, and return here for the details.
- Link terms the first time you use them in your own docs.
Next steps#
Finished this article? Track it to see your progress on the roadmap.
Related articles
- What Is an AI-Powered Full-Stack Engineer?What an AI-powered full-stack engineer does, the skills the role needs, how it differs from ML and prompt engineering, and what a real AI feature looks like in Node.js.
- How to Use This Wiki (with 3, 6, and 12-Month Study Plans)How the AI Full-Stack Engineer Wiki is organized, how to set up Node.js and an API key, and week-by-week 3, 6, and 12-month plans to become job-ready.