---
title: "Write Time — Context Infrastructure"
description: "Good retrieval is mostly decided at write time."
canonical: "https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business/write-time"
last_updated: "2018-10-20"
book: "Context Infrastructure"
label: "Chapter 7"
---

# Write Time

Good retrieval is mostly decided at write time. Three choices matter: how you tag documents, what you put in metadata versus content, and how big each document is.

## Tag in layers, like a file system

Flat tags break at scale: searches return either a thousand documents or none. Design `groupName` as a hierarchy, broad at the top and specific underneath.

| Layer | Examples | Purpose | Required? |
| --- | --- | --- | --- |
| 1. Organisation or domain | `engineering`, `marketing`, `support` | Top-level access boundary | Yes, on every document |
| 2. Category or time | `q4_2024`, `product_alpha`, `codebase`, `customer_tickets` | Logical grouping and time filtering | Recommended |
| 3. Specifics | `auth`, `api`, `campaign`, `billing` | Fine-grained filtering | Optional, use sparingly |

**Tags compose like folders: each level adds one tag.**

| Branch | groupName | Children |
| --- | --- | --- |
| All support content | `[support]` | Product documentation, FAQs, Support tickets |
| Product documentation | `[support, product]` | Authentication (+ `auth`), Features (+ `features`), Troubleshooting (+ `troubleshoot`) |
| FAQs | `[support, faq]` | Billing FAQ (+ `billing`), Technical FAQ (+ `technical`) |
| Support tickets | `[support, tickets]` | Resolved tickets (+ `resolved`), Open tickets (+ `open`) |

*Figure 7.1 · A support knowledge base as a groupName hierarchy*

Each level adds one tag to its parent's array, so a search for `[support]` sees everything, `[support, tickets]` sees only tickets, and `[support, product, auth]` lands on authentication docs alone.

**The 3-5-10 rule.** At most 3 `groupName` layers for 90% of queries, at most 5 tags in any one array, and at most 10 distinct tag combinations per query pattern. Past that, move the specifics into metadata:

```ts
// Too deep: queries become fragile
groupName: ['engineering', 'backend', 'api', 'v2', 'endpoints', 'user', 'auth', 'login']

// Better: three layers of scope, specifics as metadata
groupName: ['engineering', 'backend', 'api'],
metadata: { version: 'v2', category: 'auth', endpoint: 'login' }
```

## Metadata is for filtering; content is for meaning

| Put it in metadata when… | Put it in content when… |
| --- | --- |
| You filter or sort by it (`price`, `inStock`, `category`) | It is descriptive text (descriptions, features) |
| You need an exact match (`productId`, `sku`) | It is rarely filtered (dimensions, weight) |
| It drives access control (`department`, `classification`) | It only matters once the document is retrieved |
| It changes often and independently (stock, price) | It is part of the semantic meaning (reviews, specs) |

Start with at most five metadata fields (an id, a status, a last-modified date, an owner, optionally a priority) and add more only for a query that needs them. In one documented catalogue of 10,000 products, trimming metadata cut storage by 65%, average query time from 450 ms to 180 ms, and indexing time from 12 minutes to 4. Never duplicate content in metadata.

## Size documents by how they are retrieved

The target is **500 to 2,000 words per document**: one cohesive topic with enough context to answer from.

| Combine into one document when… | Split into separate documents when… |
| --- | --- |
| The parts are tightly coupled (an endpoint, its request, response and errors) | Access differs (public docs vs internal notes) |
| They are always retrieved together (overview, setup, first steps) | Update frequency differs (company history vs daily metrics) |
| A user question needs all of them to be answered | The document is so large that most of it is irrelevant to any one query |

**The paragraph test:** content under about 100 words is probably over-segmented. The exception is short, high-value structured facts such as a contact card. For long material, use the **chapter pattern**: one document per chapter, sharing metadata like `{ book: 'employee-handbook', chapter: 2 }`, so a question about health insurance retrieves chapter 2 alone.

**Namespaces** add a harder boundary above all of this: group and scope data per tenant or project, so multi-tenant workloads never share a search space.

---

- Previous: [Chapter 6: The Arithmetic](https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business/the-arithmetic.md)
- Contents: [Context Infrastructure](https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business.md)
- Next: [Chapter 8: Keep It Current](https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business/keep-it-current.md)
