MSBA-110 · Lesson 3 of 12 · 20 min

Tokens, context and grounding

▶ Video coming soon A video version of this lesson is on the way.

Wendell Pike-Amari, Quillfield's compliance officer, came to the third session with a printed 46-page commercial package policy and a question. "If I paste this whole thing into Copilot and ask whether it covers spoilage of stock after a power failure, will it read every page?" Hamish said the honest answer was "probably, but it depends", and that the reasons for "it depends" were the subject of the day: tokens, the context window and grounding.

These three ideas explain most of the surprises people have with generative AI. Why does a long conversation seem to forget what was said at the start? Why does an answer get better when you attach the right file? Why do some AI services charge by usage? This lesson answers those questions and introduces retrieval-augmented generation, the technique behind Copilot's answers about your own work.

Tokens: the units a model reads and writes

Language models do not read letters or whole words. They read tokens, chunks of text produced by a tokenizer that splits text into common pieces. Frequent short words such as "the" or "policy" are usually one token. Longer or rarer words are split: "endorsement" might become two or three tokens, and an unusual surname several. Spaces, punctuation and numbers are tokens too. As a rule of thumb for English, a token averages about four characters, or roughly three quarters of a word, so 100 words is about 130 tokens.

Other languages often use more tokens for the same meaning, and dense material such as tables, code or long reference numbers uses more tokens than ordinary prose. Quillfield's policy numbers, such as CPP-2026-004417, might each take several tokens. These differences matter for two reasons: tokens determine how much fits in a single request, and tokens drive the cost of AI services that are billed by usage.

Rough token counts. Real counts depend on the model's tokenizer.
TextApproximate tokensWhy
A 150-word emailAbout 200Ordinary English prose
A 46-page policy of about 18,000 wordsAbout 24,000Long document, many defined terms
A spreadsheet table of 500 rowsMany thousandsNumbers, separators and labels each count
The same email in another languageOften more than 200Tokenizers are tuned mostly on English

The context window

Every model has a context window, the maximum number of tokens it can consider in one request, counting both what goes in and what comes out. Think of it as the model's desk: everything it uses to write a reply must fit on the desk at once. Modern models have large windows, often hundreds of thousands of tokens, but the window is never unlimited, and the product decides how to use it.

What goes into the window is more than your prompt. The product adds system instructions that tell the model how to behave, the earlier turns of your conversation, any grounding data retrieved from files, email or the web, and room for the response. In a long conversation the earlier turns take up more and more space, and the product may summarize or drop the oldest ones. That is why a chat that has gone on for an hour can seem to forget a detail from the beginning.

A wide horizontal bar representing the context window, divided into colored sections from left to right: system instructions, earlier conversation, grounding data from files or the web, your prompt, and space reserved for the response. A bracket over the whole bar is labeled everything must fit in the window.
What shares the context window in a single request.

Even when everything fits, models do not pay equal attention to every part. Research has found that some models use information at the beginning and end of a long input more reliably than information buried in the middle. In practice, if Wendell pastes a 46-page policy and asks a narrow question, the model may answer well, but it is safer to point it at the relevant section or ask it to quote the clause it relied on, so that he can check.

Worked problem

Will the policy fit?

A model has a context window of 128,000 tokens. The product reserves 4,000 tokens for system instructions and 8,000 for the response. Wendell's conversation so far uses 6,000 tokens. Can he add the 24,000-token policy?

Show solution
  1. Add what is already committed: 4,000 + 8,000 + 6,000 = 18,000 tokens.
  2. Add the policy: 18,000 + 24,000 = 42,000 tokens.
  3. Compare with the window: 42,000 is well under 128,000.

Answer: Yes, with about 86,000 tokens to spare. Fitting is not the same as being read carefully, so he should still ask for the exact clause and page.

Why the model needs grounding

A model's built-in knowledge comes only from its training data, which ended at a cutoff date and never included Quillfield's private files. Ask it about the Pemberton Bakery account and it knows nothing. Grounding means supplying the model, at the time of the request, with relevant, trustworthy information so that its answer is based on that information rather than only on patterns from training. Grounding is the single most important reason business AI tools give better answers than a general chatbot.

There are two kinds of grounding in Microsoft's Copilot products. Web grounding uses a web search to find current public information and passes the results to the model, which then cites the pages it used. Work grounding uses your organization's data in Microsoft 365, such as emails, chats, meetings, files and calendar items, reached through Microsoft Graph, the service that connects Microsoft 365 data and respects each user's permissions. Copilot Chat on its own is grounded on the web; a Microsoft 365 Copilot license adds work grounding. Lessons 5 and 6 cover the details.

Retrieval-augmented generation

The general technique behind grounding is called retrieval-augmented generation, or RAG. The name describes the steps. First the system retrieves information relevant to the question from a source such as an index of documents. Then it augments the prompt by adding that information. Finally the model generates an answer based on the augmented prompt, ideally citing which retrieved passages it used.

A flow from left to right. A user question goes to a retrieval step that searches a source, shown as a stack of documents labeled files, email, web. The best passages are added to the question to form an augmented prompt. The augmented prompt goes to the language model, which produces an answer with citations back to the passages.
Retrieval-augmented generation: retrieve, augment, generate.

Retrieval usually relies on a search index. Many systems use semantic search, which finds passages by meaning rather than exact words, so a question about "spoilage after a blackout" can find a clause about "deterioration of stock following interruption of power supply". Microsoft 365 Copilot uses a semantic index of Microsoft 365 content for this purpose; in Microsoft's Foundry services, Azure AI Search plays a similar role for custom applications.

RAG has three practical consequences. Answers can include citations, so you can open the source and check. Answers can only be as good as the sources retrieved, so outdated, duplicated or wrong documents lead to wrong answers. And answers can only include what the user is allowed to see, because in Microsoft 365 retrieval runs with the user's own permissions. That last point is a strength and a risk at the same time, as lesson 6 explains under the heading of oversharing.

Data quality matters

The AB-731 study guide asks leaders to understand the impact of data on AI solutions, including data type, data quality and representative data sets. Grounded AI turns data problems into answer problems. If Quillfield's SharePoint has three versions of the same wording guide, the AI may quote the outdated one. If client notes are kept in personal files, the AI cannot find them for colleagues. If historical examples come mostly from one branch, an AI solution built on them may serve other branches poorly.

Common data problems and how they show up.
Data issueEffect on AI answersFix
Outdated or duplicate documentsThe AI cites the wrong versionArchive old versions; label the current one clearly
Information locked in personal storageColleagues' answers miss itStore shared work in shared sites with the right permissions
Scanned images without textRetrieval cannot read them wellUse searchable files or text recognition
Unrepresentative examplesAnswers work for some groups or cases and not othersCheck that examples cover all the cases that matter

Tokens and cost

Many AI services charge according to the number of tokens processed, often with different prices for input and output tokens, or they convert usage into credits. Microsoft offers both fixed per-user licenses, such as Microsoft 365 Copilot, and consumption billing for some experiences, such as agents used by people without a Copilot license, which are metered through Copilot Credits. In Microsoft's Foundry services, models are billed by tokens on a pay-as-you-go basis or through commitment plans. Lesson 11 and the AB-731 course MSBA-120 return to costs; for now the key idea is that longer inputs, longer outputs and more calls all cost more.

Worked problem

A rough usage estimate

An agent answers 2,000 questions a month. Each question uses about 3,000 input tokens, including grounding, and 500 output tokens. How many tokens is that per month?

Show solution
  1. Tokens per question: 3,000 + 500 = 3,500.
  2. Monthly total: 2,000 x 3,500 = 7,000,000 tokens.
  3. Most of the volume is input, because grounding data is large.

Answer: About 7 million tokens a month, six sevenths of them input. Trimming unnecessary grounding is often the easiest saving.

Wendell left the session with a different plan for his policy question. Instead of pasting all 46 pages, he would store the policy in the client's SharePoint folder, ask Microsoft 365 Copilot the question with a reference to that file, and require it to quote the clause and give the page. "So the trick," he said, "is to give it the right paper and make it show its work." Hamish said that was the best one-sentence summary of grounding he had heard.

Grounding a request yourself

Even without automatic work grounding, you can ground a request by supplying the material yourself. In Copilot Chat you can upload a file or paste a short passage and ask the model to answer only from it. In Microsoft 365 Copilot you can reference specific files, emails or meetings in your prompt, often by typing a slash or using a file picker, so that Copilot focuses on exactly those sources instead of searching everything. Pointing to the right source is usually more effective than hoping retrieval finds it.

It also helps to tell the model how to use the source. Instructions such as "answer only from the attached policy", "quote the clause you rely on", "say if the document does not answer the question" and "give the page number" make answers easier to check and reduce the chance that the model fills gaps with general patterns. Wendell added a variation for compliance work: "list anything in my question that the document does not address". That single line exposed several assumptions in questions colleagues brought him.

Instructions that make grounded answers more reliable.
InstructionWhy it helps
Answer only from the attached documentKeeps the model from mixing in general patterns
Quote the clause or sentence you rely onLets you check the answer quickly
Give the page or section numberSpeeds up verification in long documents
Say if the document does not answer the questionGives the model permission not to guess
List any part of my question the document does not addressReveals gaps and hidden assumptions

Long conversations and starting fresh

Because earlier turns share the context window, very long conversations can drift. The model may lose track of an instruction given at the start, carry an early misunderstanding forward, or mix details from two different clients discussed in the same chat. A simple habit avoids this: start a new conversation for each new task or client, and restate the key facts when you return to a task after a break. If a conversation has gone wrong, it is often faster to start again with a better first prompt than to correct the model turn by turn.

Mixing clients in one conversation is also a privacy habit worth avoiding. Even though everything stays within Quillfield's protected environment, a summary for one client that accidentally includes another client's detail is still an error that could reach the wrong person. Dolores adopted the rule "one client, one chat" after Copilot blended two bakeries' renewal dates in a long session.

Common mistakes

  • MistakeAssuming the model reads every word of a very long input with equal care.

    InsteadPoint it at the relevant part and ask for quotes or page references.

  • MistakeExpecting a long chat to remember everything.

    InsteadEarlier turns may be summarized or dropped; restate key facts or start a fresh chat.

  • MistakeBlaming the model for answers based on bad documents.

    InsteadGrounded answers inherit the quality of the sources; fix the data.

  • MistakeIgnoring tokens when estimating cost.

    InsteadInput, grounding and output tokens all count in usage-based services.

Summary and key terms

  • Tokens are the chunks of text a model reads and writes; in English 100 words is roughly 130 tokens.
  • The context window holds instructions, conversation history, grounding data, the prompt and the response.
  • Grounding supplies trusted information at request time; Copilot uses web grounding and, with a Microsoft 365 Copilot license, work grounding through Microsoft Graph.
  • Retrieval-augmented generation retrieves relevant passages, adds them to the prompt and generates a cited answer.
  • Answer quality depends on data quality, and usage-based costs depend on tokens.
Token
A chunk of text, often a short word or part of a word, that a model processes.
Context window
The maximum number of tokens a model can consider in one request, input and output together.
Grounding
Supplying relevant, trusted information with a request so the answer is based on it.
Retrieval-augmented generation (RAG)
Retrieving relevant passages, adding them to the prompt and generating an answer from them.
Microsoft Graph
The service that connects Microsoft 365 data and enforces each user's permissions.
Semantic index
An index that lets Copilot find Microsoft 365 content by meaning rather than exact words.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. About how many tokens are 600 English words?

    Show answer

    About 780, using roughly 1.3 tokens a word.

  2. Name the three steps of retrieval-augmented generation.

    Show answer

    Retrieve relevant information, augment the prompt with it, and generate an answer.

  3. Why might Copilot quote an outdated wording guide?

    Show answer

    Because an outdated version was stored where retrieval could find it.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz