---
title: "The Arithmetic — Context Infrastructure"
description: "Every retrieval is a small calculation."
canonical: "https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business/the-arithmetic"
last_updated: "2018-10-20"
book: "Context Infrastructure"
label: "Chapter 6"
---

# The Arithmetic

Every retrieval is a small calculation. Knowing which API lever drives which operation is the difference between retrieval that feels magical and retrieval no prompt can rescue.

```text
Window = top_K( rank( (S ∩ G ∩ M) \ D ) )
```

Here *S* is the set of semantic matches, *G* the documents inside the `groupName` scope, *M* those passing metadata filters, and *D* the deduplicated, superseded or out-of-scope content.

| Operation | Improves | Your levers |
| --- | --- | --- |
| **Union (S)** | Recall: nothing relevant is missed | The query itself; a lower `minimum_similarity_threshold` widens the net |
| **Intersection (G, M)** | Precision: nothing irrelevant gets in | `groupName` tags at write time, `body_metadata` filters at search time |
| **Subtraction (D)** | Correctness: nothing stale or forbidden gets in | `fileName` deduplication, delete-then-add updates, versioned files, `scope` |
| **Ranking (top K)** | Answer quality, latency and token cost | Similarity, recency and metadata signals; keeping documents cohesive |

## Arithmetic vs prompt stuffing

| Prompt stuffing | Context arithmetic |
| --- | --- |
| Static: the same blob every time | Dynamic: computed per query |
| Manual curation | Computed from scope and relevance |
| Token-heavy | Precision-first |
| Fragile when documents change | Composable as documents change |
| Hard to scale past one use case | Designed for many agents and teams |

> Prompt stuffing assumes more tokens make better answers. Context arithmetic assumes only the right tokens matter. The design rule for the next chapters follows from it: **structure your context so that correct answers fall out of the arithmetic, not out of clever prompts.**

---

- Previous: [Chapter 5: Ten Minutes](https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business/ten-minutes.md)
- Contents: [Context Infrastructure](https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business.md)
- Next: [Chapter 7: Write Time](https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business/write-time.md)
