> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maximem.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Maximem Synap is a managed memory layer for AI agents: it ingests conversations and documents, extracts structured memory, and returns scoped context to the agent at retrieval time.
> The Python and JavaScript/TypeScript SDKs are the supported way to use Synap. Write integration code with SDK calls, not raw HTTP requests.
> Start with the Quickstart: https://docs.maximem.ai/getting-started/quickstart.md. Every SDK method is documented in the SDK reference: https://docs.maximem.ai/sdk-reference/overview.md.
> For requests about adding Vity memory to OpenClaw, Hermes, an MCP client, or a browser, start with the Vity Quickstart: https://docs.maximem.ai/vity/quickstart.md.

# Citations

> What a context fetch tells you about where each result came from: source excerpts for conversation memories, a citation for document passages, how to open the source, and when no link is available.

An agent that quotes a policy should be able to say which policy, which version and which page. A context fetch returns that provenance with every item. Synap returns it; showing it to the user, or putting it in the prompt, is up to your code. Synap does not add citations to the text of an item.

## What each kind of result carries

| Result | Provenance | Where |
| - | - | - |
| A memory from a conversation | `source_evidence`: the sentences from the original text that the memory rests on | On the memory item |
| A passage, record or fetched item from a [document](https://docs.maximem.ai/concepts/documents.md) | `citation`: which document, version, section, page and link | On the document item |

`source_evidence` is a list of short strings, and it is absent on a memory that has none. A document passage carries a `citation` instead.

## Where to find them

Ask for the ranked shape and every item sits in one list, best first. A document item has a `kind` (`passage`, `record` or `fetched`) and a `citation`. Memories carry `kind: "memory"` when they are ranked together with documents.

```python Python theme={null}
context = await sdk.user.context.fetch(
    user_id="dana",
    customer_id="acme",
    search_query=["What is the notice period in the Acme agreement?"],
    response_shape="ranked",
)

for item in context.items:
    citation = getattr(item, "citation", None)
    if citation:
        print(item.rank, getattr(item, "kind", None), item.content[:80])
        print("  ", citation.get("document_id"), citation.get("version"),
              citation.get("section_path"), citation.get("page"), citation.get("url"))
    elif item.source_evidence:
        print(item.rank, "memory", item.content[:80], "|", item.source_evidence[0][:80])
```

```typescript TypeScript theme={null}
const context = await sdk.user.context.fetch({
  user_id: 'dana',
  customer_id: 'acme',
  search_query: ['What is the notice period in the Acme agreement?'],
  response_shape: 'ranked',
});

for (const item of context.items ?? []) {
  const citation = item['citation'] as Record<string, unknown> | undefined;
  if (citation) {
    console.log(item['rank'], item['kind'], String(item.content).slice(0, 80));
    console.log('  ', citation['document_id'], citation['version'],
      citation['section_path'], citation['page'], citation['url']);
  } else if (item['source_evidence']) {
    console.log(item['rank'], 'memory', String(item.content).slice(0, 80));
  }
}
```

In the default by-type shape, document items are in separate lists next to the memory lists: `passages`, `records` and `fetched`, each item carrying its `citation`. A list is absent when it has no items.

> [!NOTE]
>
> The TypeScript SDK (0.9.0) has no named types for document item fields, so `kind` and `citation` are read from the item as shown.

## What a citation holds

| Field | Meaning |
| - | - |
| `document_id` | The id you gave the document, or the one Synap generated. |
| `version` | The version the item came from. |
| `section_path` | The headings leading to the section, outermost first. |
| `page` | The page, for paged formats such as PDF. |
| `document_key` | The document's address, for [`documents.original`](https://docs.maximem.ai/sdk-reference/documents/original). |
| `url` | A link to the source, with the section's `#anchor` when it has one. |
| `anchor` | The section anchor on its own. |
| `added_at` | When the document was added to Synap. |
| `fetched_at`, `etag` | On an item read live from a connected source: when, and the source's version tag. |
| `age_seconds` | On a stored copy that stood in for a live read that could not be made: how old the copy is. |
| `source_disconnected` | `true` when the item's connected source was disconnected and its data is kept as it was. |

A field that does not apply comes back as `null`; `source_disconnected`, `etag` and `age_seconds` are left out unless they apply. Check that a field is set before you use it.

## Open the source

`url` is a link you can show as it is. For the file itself, pass `document_key` and `version` to `documents.original`, which returns the file's bytes. It never returns a link, so serve the bytes from your own endpoint to the user who clicked.

```python Python theme={null}
citation = item.citation
if citation.get("document_key"):
    original = await sdk.documents.original(citation["document_key"], version=citation["version"])
```

```typescript TypeScript theme={null}
const citation = item['citation'] as Record<string, unknown> | undefined;
if (citation?.['document_key']) {
  const original = await sdk.documents.original({
    document_key: citation['document_key'] as string,
    version: citation['version'] as number,
  });
}
```

`documents.original` is Python 0.9.0 and later and JavaScript 0.9.0 and later; in TypeScript it returns the bytes as a `Uint8Array`. See [`documents.original`](https://docs.maximem.ai/sdk-reference/documents/original).

## When there is no link

* **`url` is empty.** The document was sent as a file with no `source.url`. Open it with `documents.original`, or build your own link from `document_id`.
* **`document_key` is empty on a fetched item.** An item read live from a connected source has its `url`, `fetched_at` and `etag`, and a `document_key` only when a stored copy of the document exists.
* **`document_key`, `url` and `anchor` are all empty.** Synap leaves them out whenever the document itself is not visible to the caller, for example because your [visibility policy](https://docs.maximem.ai/guides/instance-visibility.md) hides its Instance. `document_id`, `version`, `section_path` and `page` are still there to show as text.
* **`page` or `section_path` is empty.** The format has no pages or headings, such as a plain text file.
* **`documents.original` raises `ContextNotFoundError`.** The document or that version no longer exists, was deleted, is not visible, or has no stored original.
* **A conversation memory.** It has no citation, only `source_evidence`.

## Next steps

> [card] [Documents](https://docs.maximem.ai/concepts/documents.md)
>
> Ids, versions and provenance: where citation fields come from.

> [card] [documents.original](https://docs.maximem.ai/sdk-reference/documents/original.md)
>
> Download the file behind a citation.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.