liveBook · Manning

Context window

As explained in Software Testing with Generative AI

The bounded amount of tokenized input and related context that a language model can process for a request.

A context window is the maximum number of tokens an LLM can process for a request. Tokenization converts text into smaller pieces and integer identifiers, so the limit applies to tokenized prompts and responses rather than simply counting words. Larger prompts can provide more relevant context, but they remain bounded by the model and its hardware. section 10.1.1 section 10.3

Treat the context window as a practical constraint:

  • Keep prompts within the limit. Excess tokens may be cut off, ignored, or cause an error, leaving a partially completed prompt. section 11.1 section 12.2.2
  • Select relevant material instead of attaching every user story, test script, code sample, or other development artifact. section 11.1
  • Manage token costs as well as capacity: sending more tokens can increase charges, even when the model accepts them. section 11.1

Testing ideas with retrieved context

A direct prompt such as “I want test ideas for deleting bookings” can be extended with relevant documents at a separate context point. Retrieving only the documents related to the query improves response accuracy and avoids filling the prompt with unnecessary data. This is the role of retrieval-augmented generation (RAG); fine-tuning offers another way to make responses more context-sensitive, but requires more tooling and preparation. section 10.3 section 11.1

List
 me
 five
 of
 the
 most
 populated
 cities
 in
 the
 world
.

A token listing makes the constraint concrete by showing how an ordinary sentence is divided before an LLM processes it. section 10.1.1

How Software Testing with Generative AI covers it

How deep it goes
Explains tokenization, truncation, errors, cost, and relevance strategies, but does not detail model-internal context handling.
Examples
Uses a city-list tokenization example, testing artifacts, a booking-deletion query, Llama-2 capacity, and gpt-4 turbo pricing.
What it assumes
Builds from natural-language prompts and teaches tokenization before applying context limits to retrieval and fine-tuning.
What you can do after
Evaluate prompt size, select relevant context, and avoid truncated inputs during LLM testing and fine-tuning.
How it connects
Connects tokenization, retrieval-augmented generation, fine-tuning, maximum sequence length, prompt design, and model costs.

Also explained in

Compare how 22 books explain context window →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.