# The Wiki

The Wiki is a **continuously updated structured memory per tenant**. Not a vector store with documents in it. A graph of entities, relationships, narratives, and rolling summaries, linked back to Ledger and Raw.

{% hint style="info" %}
The Wiki is what makes Brain compound. The longer it runs for a tenant, the deeper the memory and the lower the marginal cost per query.
{% endhint %}

### What lives in the Wiki

| Element               | Examples                                                                  |
| --------------------- | ------------------------------------------------------------------------- |
| **Entities**          | Counterparties, accounts, products, contracts, employees                  |
| **Relationships**     | "Vendor X invoices Cost Center Y", "Account A funds Subsidiary B"         |
| **Narratives**        | "Q3 receivables held flat versus Q2 despite revenue growth, driven by..." |
| **Rolling summaries** | Week-over-week, month-over-month, quarter-over-quarter snapshots          |
| **Embeddings**        | pgvector embeddings indexed for semantic retrieval                        |

### What the Wiki answers

The Wiki is built to answer the kinds of questions only memory can answer.

| Example Question                            | Why Memory Is Required                 |
| ------------------------------------------- | -------------------------------------- |
| "Who is this counterparty?"                 | Requires accumulated entity knowledge  |
| "What is our normal monthly burn?"          | Requires rolling baselines             |
| "Have we paid this vendor before?"          | Requires historical lookups            |
| "What changed in receivables this quarter?" | Requires diff against prior periods    |
| "Is this subscription one we still use?"    | Requires usage and recurrence tracking |

### Citations on every answer

Every answer carries citations into the Ledger and Raw. Any claim is traceable back to source evidence.

```typescript
const answer = await brain.wiki.question({
  tenantId: "acme",
  question: "What did we spend on AWS last quarter, by environment?"
});

// answer.text         → fluent natural-language response
// answer.citations[]  → [{ ledger_id, raw_refs: [...] }, ...]
// answer.audit_event_id → the audit event under which this query was logged
```

{% hint style="success" %}
You never have to trust the Wiki blindly. Every claim links back to the Ledger records and Raw artifacts that produced it.
{% endhint %}

### How the Wiki updates

The Wiki updates **incrementally** as new Ledger records arrive.

| Trigger                   | Wiki Action                                                              |
| ------------------------- | ------------------------------------------------------------------------ |
| New transaction in Ledger | Update counterparty profile, refresh rolling balance, re-embed narrative |
| Counterparty merge        | Resolve duplicate entities, rewrite relationship edges                   |
| Invoice paid              | Close the matching obligation; update vendor history                     |
| Period boundary           | Generate rolling summary; index for retrieval                            |

### Why not just a vector store

Vector stores retrieve documents. The Wiki retrieves a graph of verified entities with citations.

| Vector store                        | Wiki                                    |
| ----------------------------------- | --------------------------------------- |
| Returns chunks of documents         | Returns entities and relationships      |
| No native citations to source       | Every node links to Ledger and Raw      |
| Updates by re-embedding             | Updates incrementally as Ledger changes |
| No notion of correction             | Supersession propagates from Ledger     |
| Reasoning hallucinated on retrieval | Reasoning bounded by structured facts   |

### Compounding effect

Brain's Wiki gets cheaper to query and richer to read the longer it runs.

| Time Horizon     | What Compounds                                                   |
| ---------------- | ---------------------------------------------------------------- |
| **First weeks**  | Entity resolution stabilizes; counterparty profiles emerge       |
| **First months** | Rolling baselines mature; anomaly detection becomes possible     |
| **First year**   | Year-over-year comparisons unlock; vendor history is deep        |
| **Multi-year**   | Cross-period narratives become durable; switching costs are high |

### What's next

<table data-view="cards"><thead><tr><th></th><th></th><th data-type="content-ref"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><strong>📥 Raw and Ledger</strong></td><td>The verified substrate underneath the Wiki.</td><td><a href="/pages/pPTXzUZ6cZ8LCgvMmMRO">/pages/pPTXzUZ6cZ8LCgvMmMRO</a></td><td></td></tr><tr><td><strong>📋 Policy</strong></td><td>How Wiki context informs policy decisions.</td><td><a href="/pages/GSe2ntE9CLqxoQAiQuzG">/pages/GSe2ntE9CLqxoQAiQuzG</a></td><td></td></tr><tr><td><strong>🛠️ Wiki SDK</strong></td><td>Programmatic queries.</td><td><a href="/pages/m25lyIz3DPEyKYuR5mU1">/pages/m25lyIz3DPEyKYuR5mU1</a></td><td></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.brain.fi/protocol/the-wiki.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
