---
title: "Why reuse a close answer"
lesson_id: "01"
---

# Why reuse a close answer

- **Lesson ID:** 01
- **Goal:** Separate an app-owned semantic cache from a LanguageModelSession generate and from token KV cache.
- **Human lesson:** [01-why-reuse-answers.html](01-why-reuse-answers.html)

## Prerequisites

- Comfort with a simple SwiftUI app.
- The idea that a language model costs time and battery on the device.

## Inputs, outputs, and artifacts

- **Inputs:** Two user questions that mean the same thing, plus one that should miss.
- **Outputs:** A written rule for hit, miss, and stale.

## Agent build steps

1. Explain that repeat questions in different words still cost a full generate if you always call `respond`.
2. Name `usage.input.cachedTokenCount` as token KV cache, not semantic cache.
3. List three miss cases: time-sensitive answers, rewrite requests, and loose similarity.
4. Point to lesson 02 for on-device embeddings.
5. Use progressive `.flow` diagrams. No Mermaid.

## Constraints

iOS 27 and macOS 27 only. Friendly direct English. No em dashes, quizzes, or CUDA.

## Key concepts

- Repeat questions in different words should not always trigger a full generate.
- A semantic cache is your table of question vectors plus answer text.
- `usage.input.cachedTokenCount` is the model's KV cache inside a generate, not a semantic skip.
- Reuse fails when answers depend on time, files, rewrites, or a different intent.

## Takeaways

- Do not mix KV cache hits and semantic hits in logs.
- Treat reuse as a product choice, not a free speed win.
- Know when a close question is still a miss.

## Acceptance checks

- Semantic cache is described as app-owned.
- KV cache is named as a different thing.
- Miss cases are listed.
- Agent brief link is present.
