> ## 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.

# Query and navigate documents as an agent

> When an agent should fetch, query or read: knowledge.describe, knowledge.query, documents.index and documents.read, what complete and coverage mean, and the matching MCP tools.

`context.fetch` returns a ranked, token-budgeted bundle. That is the right tool for most questions. It is the wrong one for "list every contract with Acme that expires before March", where a ranked top few hides what it left out, and for "check what section 4 of that contract says", where the agent needs the document itself.

Four more calls cover those two needs.

> [!WARNING]
>
> These calls are enabled per instance and need a Pro plan or above. Where a call is not enabled for your instance it raises `ContextNotFoundError`, the same error as for a document that does not exist, and the matching MCP tool is not listed. A plan without the feature raises `FeatureNotInPlanError`. Each successful call uses credits. They are in Python 0.9.0 and later and JavaScript 0.9.0 and later.

## Which call to use

| The agent needs | Call | Returns |
| - | - | - |
| To know what can be asked | [`knowledge.describe()`](https://docs.maximem.ai/sdk-reference/knowledge/describe) | Sources, document counts by type, and the entity and fact types with their properties and relations |
| Every match, a count, or counts per value | [`knowledge.query(...)`](https://docs.maximem.ai/sdk-reference/knowledge/query) | A complete filtered set, with citations, paged |
| The most relevant passages for a question | [`context.fetch`](https://docs.maximem.ai/sdk-reference/context/fetch) | The ranked bundle, unchanged |
| A document's outline | [`documents.index(key)`](https://docs.maximem.ai/sdk-reference/documents/document-index) | Title, summary and the section tree with page ranges and `section_key`s |
| One section or page range, to check a citation or read around it | [`documents.read(key, ...)`](https://docs.maximem.ai/sdk-reference/documents/read) | The text, with its citation |

## Orient, then query

```python Python theme={null}
schema = await sdk.knowledge.describe(customer_id="acme-corp")

page = await sdk.knowledge.query(
    target="Obligation",                        # a type from describe
    where={"due_at": {"before": "2027-03-01"}, "status": "open"},
    related={"COUNTERPARTY": {"type": "Organization", "name": "Acme"}},   # at most 2 hops
    customer_id="acme-corp",
)
```

```typescript TypeScript theme={null}
const schema = await sdk.knowledge.describe({ customer_id: 'acme-corp' });

const page = await sdk.knowledge.query({
  target: 'Obligation',                        // a type from describe
  where: { due_at: { before: '2027-03-01' }, status: 'open' },
  related: { COUNTERPARTY: { type: 'Organization', name: 'Acme' } },   // at most 2 hops
  customer_id: 'acme-corp',
});
```

You send a structured request, never question text; the agent turns the question into `target`, `where` and `related` using what `describe` returned. Every answer carries:

* **`total` and `complete`.** `total` is every match, not only this page; page on with `next_cursor`. `complete: False` means the set was larger than a query returns, so the matches you can page through are not all of them: narrow the query with a filter before the agent states a number.
* **`coverage`.** How many documents in scope could hold matches but are not processed yet (`unprocessed`), were only lightly read (`light_only`), or failed. An agent can then report "14 found; 3 contracts still processing" rather than claim a full answer. A query is complete over what Synap has extracted, and `coverage` says what that leaves out.

An aggregate is a count or counts grouped by a property: `aggregate={"count": True}` or `aggregate={"group_by": "status"}` (`aggregate: { count: true }` or `aggregate: { group_by: 'status' }` in TypeScript).

## Open a document, then read

```python Python theme={null}
tree = await sdk.documents.index(key, customer_id="acme-corp")
section = tree["sections"][3]["section_key"]

part = await sdk.documents.read(key, section_key=section, customer_id="acme-corp")
pages = await sdk.documents.read(key, pages="3-5", customer_id="acme-corp")
```

```typescript TypeScript theme={null}
const tree = await sdk.documents.index({ document_key: key, customer_id: 'acme-corp' });
const sections = tree['sections'] as Array<{ section_key: string }>;
const section = sections[3].section_key;

const part = await sdk.documents.read({ document_key: key, section_key: section, customer_id: 'acme-corp' });
const pages = await sdk.documents.read({ document_key: key, pages: '3-5', customer_id: 'acme-corp' });
```

`index` takes a `version` to open an older version's outline. `read` always reads the current version and returns a bounded amount of text per call (at most 20 pages); a larger request raises `InvalidInputError`, so the agent should ask for a smaller section or range. While a document is still being processed, `read` raises `ContextNotFoundError` with `code == "document_not_ready"` (`serverCode` in TypeScript) and `index` returns an empty section list; try again shortly. A page range with no text, such as one past the last page, raises `InvalidInputError` and is not charged. While part of a document has been removed by a forget request, `index` returns no document-level `summary`.

Pass the same `user_id`, `customer_id` and `scope` you read the document at with `context.fetch`, also when you hold a `document_key`. A document you cannot see, whether it is another customer's, another user's, outside your instance's visibility, or deleted, raises `ContextNotFoundError`, the same as one that does not exist.

## MCP tools

On deployments where document and knowledge features are enabled, the [Synap MCP server](https://docs.maximem.ai/integrations/mcp.md) adds four tools beside its memory tools: `synap_describe`, `synap_query`, `synap_document_index` and `synap_document_read`. They match the SDK calls above.

| Tool | Same as |
| - | - |
| `synap_describe` | `knowledge.describe` |
| `synap_query` | `knowledge.query` |
| `synap_document_index` | `documents.index` |
| `synap_document_read` | `documents.read` |

Their descriptions tell the agent to call `synap_describe` first and to report `coverage`. `recall_context` stays the search tool. A tool call that Synap refuses because the feature is off for the instance, or because the document is not visible, comes back as an `ERROR:` message the agent can act on.


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