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

# user.context.fetch

> Retrieve user-scoped context: facts, preferences, episodes, and temporal events about a specific end user.

```python theme={null}
await sdk.user.context.fetch(
    user_id,
    conversation_id=None,
    search_query=None,
    max_results=10,
    types=None,
    mode="fast",
    customer_id=None,
)
```

Fetch context scoped to a single end user. User-scoped memories capture personal facts, preferences, and history that the SDK has accumulated for this user across their conversations. Use this on the server before composing a prompt so the model can ground its response in what you already know about the person.

### Parameters

<ParamField path="user_id" type="string" required>
  The user identifier to fetch context for. Must match a `user_id` you've previously ingested or initialized a conversation for.
</ParamField>

<ParamField path="conversation_id" type="string">
  Optional conversation identifier. When provided, results are biased toward memories relevant to the active conversation and the SDK can inject periodic user summaries into the response. When supplied, it must be a valid UUID (e.g. `str(uuid.uuid4())`) [registered via `record_message`](/concepts/context-end-to-end#short-term-context).
</ParamField>

<ParamField path="search_query" type="string | string[]">
  One or more search queries to find relevant user memories. If omitted, returns the most recent and highest-confidence user-scoped memories.
</ParamField>

<ParamField path="max_results" type="integer">
  Maximum number of memory items to return. Defaults to `10`. Maximum `50`.
</ParamField>

<ParamField path="types" type="string[]">
  Filter results to specific memory types. If omitted, all types are included.

  | Value            | Description                                                  |
  | ---------------- | ------------------------------------------------------------ |
  | `fact`           | Factual information about the user                           |
  | `preference`     | Stated or inferred user preferences                          |
  | `episode`        | Notable events from the user's history                       |
  | `emotion`        | Sentiment and emotional context                              |
  | `temporal_event` | Time-bound events (deadlines, appointments, recurring dates) |
</ParamField>

<ParamField path="mode" type="string">
  Retrieval mode that controls the speed-quality tradeoff: the retrieval axis (`fast` vs `accurate`) of [Retrieval Modes](/concepts/retrieval-modes).

  | Value      | Description                                                       |
  | ---------- | ----------------------------------------------------------------- |
  | `fast`     | Vector search only. Lower latency. **Default.**                   |
  | `accurate` | Full vector + graph + re-ranking. Higher quality, higher latency. |

  For real per-mode latency on your instance, see **Dashboard → Usage**.
</ParamField>

<ParamField path="customer_id" type="string">
  Customer identifier the user belongs to. Required on B2B; auto-resolved on B2C. See [B2C vs B2B](/concepts/memory-scopes#b2c-vs-b2b-which-scopes-apply-to-you). **Required for B2B instances.** For B2C instances, this is auto-resolved from `user_id` and can be omitted.
</ParamField>

### Returns

A `ContextResponse` with the following fields:

<ResponseField name="facts" type="array">
  Array of fact memories relevant to the query. Each includes `content`, `confidence`, `entities`, `source`, and `relevance_score`.
</ResponseField>

<ResponseField name="preferences" type="array">
  Array of preference memories.
</ResponseField>

<ResponseField name="episodes" type="array">
  Array of episode memories.
</ResponseField>

<ResponseField name="emotions" type="array">
  Array of emotion memories.
</ResponseField>

<ResponseField name="temporal_events" type="array">
  Array of time-bound event memories.
</ResponseField>

<ResponseField name="metadata" type="object">
  Response metadata including `correlation_id`, `source` (`cache` | `cloud` | `anticipation`), `ttl_seconds`, and `retrieved_at`.
</ResponseField>

### Example

```python theme={null}
import uuid
from maximem_synap import MaximemSynapSDK

sdk = MaximemSynapSDK(api_key="synap_your_key_here")
await sdk.initialize()

context = await sdk.user.context.fetch(
    user_id="user_jane_doe",
    conversation_id=str(uuid.uuid4()),  # must be a valid UUID
    search_query=["dietary restrictions", "favorite restaurants"],
    max_results=5,
    types=["fact", "preference"],
    mode="accurate",
)

for fact in context.facts:
    print(f"[{fact.confidence:.2f}] {fact.content}")

for pref in context.preferences:
    print(f"prefers: {pref.content}")
```

### Raises

* `InvalidInputError`: when `mode` is not `"fast"` or `"accurate"`.
* `SDKNotInitializedError`: when called before `await sdk.initialize()`.
* `AuthenticationError`: when the API key is invalid or revoked.
* `ContextNotFoundError`: when `user_id` does not exist for this instance.

### See also

* [`sdk.customer.context.fetch`](/sdk-reference/context/customer-fetch): customer-scoped context
* [`sdk.client.context.fetch`](/sdk-reference/context/client-fetch): organizational (client) context
* [`sdk.context.fetch`](/sdk-reference/context/fetch): unified scope-chain fetch
