---
title: "Keep It Current — Context Infrastructure"
description: "Documents get ingested, edited, superseded and deleted."
canonical: "https://press.getalchemystai.com/books/context-infrastructure-build-ai-that-understands-your-business/keep-it-current"
last_updated: "2018-10-20"
book: "Context Infrastructure"
label: "Chapter 8"
---

# Keep It Current

Context is not written once. Documents get ingested, edited, superseded and deleted, and each of those steps changes what the arithmetic can see. Getting the lifecycle right is what keeps answers current.

## Ingest in bulk, not in loops

Adding context is a bulk operation. Sending 1,000 documents one call at a time takes around 30 seconds; sending them as one array takes around 3. For large or slow sources, use the queued endpoint and poll the job:

```ts
const { jobId } = await client.v1.context.addAsync.create({
  context_type: 'resource',
  scope: 'internal',
  source: 'policy-sync',
  documents, // an array, not a loop of calls
  metadata: { groupName: ['hr', 'policy'] },
});

const job = await client.v1.context.addAsync.status.retrieve(jobId);
console.log(job.status, job.failedReason);
```

Only jobs that are still waiting or delayed can be cancelled; a running job returns 409. Keep each request inside the documented limits (Appendix B: 50 MB per document, 100 documents per `add()` request), run at most three requests in parallel, and back off exponentially on 429. The SDKs already retry connection errors, 408, 409, 429 and 5xx twice by default.

## Updates: the deduplication rule

Alchemyst deduplicates on `metadata.fileName`. Adding a document whose `fileName` already exists returns **409 Conflict**, by design, so a silent duplicate never pollutes retrieval. Every update therefore needs a deliberate strategy.

**Pick an update strategy before you hit a 409.**

| Question | Yes | No |
| --- | --- | --- |
| Does it fully replace the old version? | **A · Delete, then add** — the document genuinely changed | Next question |
| Does the history matter? | **B · Versioned fileNames** — contracts, specs, legal records | Next question |
| Is it part of a conversation? | **C · Conversational updates** — support tickets, chats, ongoing projects | **B, plus a cleanup job** — keep recent versions, prune the rest |

*Figure 8.1 · Choosing an update strategy*

| Strategy | How it works | Use it for |
| --- | --- | --- |
| **A. Delete, then add** | Delete the old version, confirm the delete succeeded, then add the new one under the same `fileName` | Documentation that is edited in place |
| **B. Versioned fileNames** | Add each version under a new name (`q4-report-v2.pdf`) with `version`, `status` and `supersedes` metadata | Contracts, specs, legal records where history matters |
| **C. Conversational** | Append turns to a session instead of rewriting a document | Support tickets, chat logs, ongoing projects |

**Watch the race.** In concurrent systems, an add that starts before its delete has finished can conflict. Wait for the delete's success response (the docs suggest a 100 to 200 ms pause for propagation) before adding, and batch deletes and adds rather than interleaving them per document.

## Deletion

Context is deleted by `source`, either per document or per id, and memory is deleted per `memoryId`. Deletion is how you honour retention policies and user requests to forget (see Chapter 25), so build it into the pipeline from the start rather than as a clean-up script.

---

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