Context Window & Caching Questions with Answers

18 practice questions on Context Window & Caching (AI Engineering (LLM Apps)) with answers and step-by-step solutions. Try 10 samples below, then practise all 18 free in the AptiNest app.

Sample questions

Question 1Easy

Roughly how do providers bill text generation?

  1. Per minute that a browser tab is open
  2. Per token, with input and output often priced differently
  3. Per character typed by the end user
  4. Per HTTP request, regardless of how large the prompt or answer is

Answer: B. Per token, with input and output often priced differently

Explanation

Token-based billing is why prompt length and output length drive cost.

Step-by-step solution

  1. Text generation costs are based on tokens processed.
  2. Each token in input and output is counted separately.
  3. Input and output tokens often have different prices.
  4. Providers charge per token, not per minute or character.
  5. Final answer: Per token, with input and output often priced differently.

Why the other options are wrong

  • A. Browser tab time is not how LLM APIs charge; the bill is based on tokens processed.
  • C. End-user typing is not billed; providers count the tokens in the prompt and the generated output.
  • D. Per-request billing ignores size; providers charge by tokens, so long prompts and answers cost more.

Tip: Check pricing for input vs output tokens.

Question 2Easy

For a long chat, which history strategy keeps recent detail while bounding tokens?

  1. Keep the last few turns verbatim and summarise older ones
  2. Drop the system prompt after the first turn to make room for history
  3. Keep only the very first user message
  4. Send every past message in full forever

Answer: A. Keep the last few turns verbatim and summarise older ones

Explanation

A rolling summary plus a recent window preserves context without unbounded growth.

Step-by-step solution

  1. Verbatim history takes too much space.
  2. Summarising older messages keeps tokens low.
  3. Recent turns are kept as is for detail.
  4. Older parts are condensed to save space.
  5. This balances detail and token limits.

Why the other options are wrong

  • B. Dropping the system prompt loses the core instructions, so it is not a safe way to make room.
  • C. Keeping only the first message loses all recent detail and the current context of the chat.
  • D. Sending every message forever grows without bound and breaks the token limit.

Tip: Use summaries for older messages and keep recent ones verbatim to manage tokens.

Question 3Easy

Conversation memory stored as user facts in a database ("prefers vegetarian food") is an example of:

  1. The KV cache inside the model's GPU memory
  2. Fine-tuning the model on each user
  3. Long-term memory retrieved into context when relevant
  4. Prompt caching of the system prompt

Answer: C. Long-term memory retrieved into context when relevant

Explanation

External memory persists across sessions and is fetched like RAG when needed.

Step-by-step solution

  1. User facts are stored outside the model's temporary memory.
  2. These facts are accessed when needed, not during training.
  3. This matches long-term memory retrieval into context.
  4. Fine-tuning happens during training, not at inference.
  5. Final answer: Long-term memory retrieved into context when relevant.

Why the other options are wrong

  • A. The KV cache is temporary attention data inside a single generation, not stored user facts.
  • B. Fine-tuning changes model weights, while stored facts are looked up and added to the context.
  • D. Prompt caching reuses a repeated prefix for speed and cost; it does not store user facts.

Tip: Remember: External facts are part of long-term memory, not model caching.

Question 4Easy

Caching the answer to an exact repeated question (same normalised text) is safe when:

  1. The underlying data and prompt have not changed since caching
  2. The user asks in a different language
  3. The answer depends on today's date
  4. The answer includes personal account data for the logged-in user

Answer: A. The underlying data and prompt have not changed since caching

Explanation

Exact caches must be invalidated when sources, prompts or model change, and must respect per-user data.

Step-by-step solution

  1. Caching works if inputs stay the same.
  2. If data or prompt changes, cache is wrong.
  3. Cache is safe when nothing changes.
  4. Today's date changes so cache may be wrong.
  5. Personal data varies per user so cache is unsafe.

Why the other options are wrong

  • B. A different language gives different normalised text, so the cache match is not the same question.
  • C. Answers about today's date go stale each day, so caching them is unsafe even with the same wording.
  • D. Personal account data differs per user, so one user's cached answer must never be served to another.

Tip: Cache only when input and context are completely unchanged.

Question 5Medium

"Context compaction" in a long-running agent means:

  1. Converting the prompt into an image
  2. Encrypting the context before sending it
  3. Compressing the model's weights with zip so more context fits on the GPU
  4. Replacing older context with a shorter summary to free space

Answer: D. Replacing older context with a shorter summary to free space

Explanation

Agents summarise prior steps so they can continue beyond the context limit.

Step-by-step solution

  1. Long context fills up.
  2. Compaction summarises old context.
  3. Space is freed.

Why the other options are wrong

  • A. Images unrelated.
  • B. Encryption unrelated.
  • C. Weights unaffected.

Question 6Medium

A semantic cache returns a stored answer when a new query's embedding is close to a past query. What is its main risk?

  1. Similar-looking questions with different meanings get the wrong answer
  2. It cannot store any answers that are longer than about 100 tokens in its index
  3. It increases the cost of every query
  4. It always misses exact repeats of a query

Answer: A. Similar-looking questions with different meanings get the wrong answer

Explanation

"Cancel my order" and "Don't cancel my order" can embed close together; thresholds and scoping matter.

Step-by-step solution

  1. A semantic cache matches by embedding similarity.
  2. Two similar-looking queries can mean different things.
  3. The cache then returns a wrong answer.

Why the other options are wrong

  • B. Cache stores answers of any length.
  • C. It reduces cost.
  • D. Exact repeats are near-identical, so hit.

Question 7Medium

Which content should usually be the first part of a cache-friendly prompt?

  1. Current stock prices
  2. Tool definitions and fixed instructions
  3. The user's latest message
  4. A random request ID

Answer: B. Tool definitions and fixed instructions

Explanation

Stable content first maximises the shared prefix across requests.

Step-by-step solution

  1. Tool definitions are stable and reused across requests.
  2. Fixed instructions don't change with each query.
  3. Stable content first helps in sharing prefixes.
  4. Shared prefixes improve cache efficiency.
  5. Cache-friendly prompts start with tool definitions and fixed instructions.

Why the other options are wrong

  • A. Stock prices change often, so putting them first would break the shared prefix.
  • C. The user's latest message changes each request, so putting it first breaks the reusable prefix.
  • D. A random request ID changes on every call and stops any prefix from matching.

Tip: Always place stable, repeated content at the beginning of prompts for better caching.

Question 8Medium

Provider-side prompt caching (prefix caching) gives the biggest saving when:

  1. Many requests share a long, identical prompt prefix
  2. Responses are long but prompts are short
  3. The changing user text is placed first and the fixed text after it
  4. Every request has a unique system prompt

Answer: A. Many requests share a long, identical prompt prefix

Explanation

Caches match from the start of the prompt, so static content (instructions, tools, documents) should come first.

Step-by-step solution

  1. Caching works best when prompts are reused.
  2. Long identical prefixes save most tokens.
  3. Shared prefixes reduce computation.
  4. Unique prompts waste cache space.
  5. So saving is highest with shared long prefixes.

Why the other options are wrong

  • B. Prefix caching helps the input prompt, so long responses with short prompts gain little from it.
  • C. Changing text must come after the cached prefix; placing it first breaks the shared prefix.
  • D. A unique system prompt per request gives no shared prefix, so the cache has nothing to reuse.

Tip: Cache static, repeated parts first for maximum savings.

Question 9Hard

A batch of 8 concurrent requests each holds a 4,000-token context. The KV cache costs 0.5 MB per token. How much KV-cache memory does the batch need?

  1. 16 GB
  2. 4 GB
  3. 32 GB
  4. 2 GB

Answer: A. 16 GB

Explanation

8 × 4,000 × 0.5 MB = 16,000 MB = 16 GB.

Step-by-step solution

  1. Each request uses 4,000 tokens.
  2. One token costs 0.5 MB, so one request needs 4,000 × 0.5 = 2,000 MB.
  3. 8 requests need 8 × 2,000 = 16,000 MB.
  4. Convert MB to GB: 16,000 ÷ 1024 ≈ 16 GB.
  5. Final answer: 16 GB.

Why the other options are wrong

  • B. 4 GB is too small; 8 requests of 4,000 tokens at 0.5 MB per token need about 16 GB.
  • C. 32 GB would double the answer; the batch is 8 x 4,000 x 0.5 MB, about 16 GB.
  • D. 2 GB is the size of one request's context, not the batch; the batch of 8 needs about 16 GB.

Tip: Use formula: Total memory = requests × tokens × cost per token ÷ 1024.

Question 10Hard

A RAG system caches final answers for 24 hours. A policy document is updated at noon. What is the correct fix to avoid stale answers?

  1. Cache only the questions, never answers
  2. Lower the LLM temperature to zero
  3. Invalidate cache entries derived from that document when it changes
  4. Increase the cache lifetime to one week so fewer entries need refreshing

Answer: C. Invalidate cache entries derived from that document when it changes

Explanation

Linking cache entries to source versions allows targeted invalidation instead of serving outdated answers.

Step-by-step solution

  1. Cache entries are linked to the policy document version.
  2. When the document changes, those entries become stale.
  3. Invalidating only affected cache entries stops stale answers.
  4. This ensures new answers use updated policies.
  5. Final answer: Invalidate cache entries derived from that document when it changes.

Why the other options are wrong

  • A. Caching only questions still serves old answers, so the stale risk comes from cached answers themselves.
  • B. Temperature zero changes randomness, not whether cached answers reflect the updated policy.
  • D. A one-week lifetime keeps stale answers around longer, so it makes the problem worse.

Tip: Targeted invalidation is better than full cache refresh for dynamic content.

Practise all 18 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all AI Engineering (LLM Apps) topics · All topics