# Assemble context (/docs/api/context-assemble)
<EndpointLayout>
<EndpointHeader method="POST" path="/v1/context/assemble" />

Answers a question from an engine, recalls the related memories from a memory space, and saves the question and answer back to that space, all in one call. Use it to build an assistant turn without separate query, recall, and write requests.

<EndpointExamples>
<CodeTabs items={['cURL']}>
  <Tab value="cURL">
    ```bash
    curl https://api.docklee.com/v1/context/assemble \
      -H "Authorization: Bearer $DOCKLEE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "engine_id": "your-engine-id",
        "query": "Can I still get a refund for my order?",
        "memory_space_id": "your-memory-space-id",
        "user_ref": "user_8f2c"
      }'
    ```
  </Tab>
</CodeTabs>

<Tabs items={['200']}>
  <Tab value="200">
    ```json
    {
      "answer": "Customers can request a refund within 30 days of purchase.",
      "citations": [
        {
          "chunk_id": "c2a8f5e1-7b39-4d6c-a014-8e3f2b9d61c7",
          "page_number": 4,
          "section_title": "Refunds and returns"
        }
      ],
      "confidence": 0.93,
      "memory_context": [
        {
          "id": "4c9f1b27-8e63-4d0a-a5b4-1f2e7d9c3a80",
          "content": "Maya ordered an Atlas desk on 2 November.",
          "memory_type": "entity",
          "confidence_score": 0.82
        }
      ],
      "memory_written": true,
      "query_mode": "precise"
    }
    ```
  </Tab>
</Tabs>
</EndpointExamples>

## Body [#body]

<ApiFields>
  <ApiField name="engine_id" type="string<uuid>" required>
    The engine to answer from.
  </ApiField>
  <ApiField name="query" type="string" required>
    The question, up to 4,000 characters.
  </ApiField>
  <ApiField name="memory_space_id" type="string<uuid> | null">
    The memory space to recall from and save the turn to. Leave it out to get only the engine's answer.
  </ApiField>
  <ApiField name="user_ref" type="string | null">
    Your own reference for the person asking, stored with the saved turn.
  </ApiField>
  <ApiField name="top_k" type="integer" defaultValue="8">
    How many chunks the engine searches for, from 1 to 50.
  </ApiField>
  <ApiField name="query_mode" type="string" defaultValue="precise">
    The answer mode. See [Answer modes](/docs/knowledge/answers/answer-modes).
  </ApiField>
  <ApiField name="write_to_memory" type="boolean" defaultValue="true">
    Save the question and answer as a memory in `memory_space_id`.
  </ApiField>
</ApiFields>

Memory context comes from the space's space-level memory. To recall one person's memories in a multi-user space, call [Search memories](/docs/api/search) with an `end_user`.

## Response [#response]

<ApiFields>
  <ApiField name="answer" type="string" required>
    The engine's answer.
  </ApiField>
  <ApiField name="citations" type="object[]" required>
    The chunks the answer is based on.
  </ApiField>
  <ApiField name="confidence" type="number" required>
    How well the sources support the answer, from 0 to 1.
  </ApiField>
  <ApiField name="memory_context" type="object[]" required>
    Up to 5 related memories, each with `id`, `content`, `memory_type`, and `confidence_score`. Empty without a `memory_space_id`.
  </ApiField>
  <ApiField name="memory_written" type="boolean" required>
    Whether the turn was saved to memory.
  </ApiField>
  <ApiField name="query_mode" type="string" required>
    The answer mode that was used.
  </ApiField>
</ApiFields>

## Status codes [#status-codes]

| Status | Meaning |
| --- | --- |
| `200` | The engine answered, and memory was read and written as requested. |
| `400` | The question couldn't be answered as sent. |
| `401` | The key is missing, malformed, or revoked. |
| `403` | The key's capability or scope doesn't allow reading this engine or using this memory space. |
| `404` | The engine or memory space doesn't exist in the key's workspace. |
| `422` | A field is missing or invalid. |
</EndpointLayout>
