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

# Memory Graph

> GET /v1/memories/{id}/graph — Traverse the memory knowledge graph.

<Snippet file="snippets/wallet-auth-callout.mdx" />

**Price:** FREE

Traverse the knowledge graph of related memories. Returns connected memories up to N hops away, with relationship edges.

This endpoint helps visualize and explore how memories relate to each other through the relations API.

## Path Parameters

<ParamField path="id" type="string" required>
  UUID of the starting memory.
</ParamField>

## Query Parameters

<ParamField query="depth" type="number">
  Maximum hops to traverse. Default: `2`. Max: `5`.
</ParamField>

<ParamField query="limit" type="number">
  Maximum total memories to return. Default: `50`. Max: `200`.
</ParamField>

<ParamField query="relation_types" type="string">
  Comma-separated list of relation types to include: `related_to`, `derived_from`, `contradicts`, `supersedes`, `supports`.
</ParamField>

## Response (200 OK)

<ResponseField name="root" type="object">
  The starting memory.

  <Expandable title="Memory object">
    <ResponseField name="id" type="string">
      UUID of the memory.
    </ResponseField>

    <ResponseField name="content" type="string">
      Memory text content.
    </ResponseField>

    <ResponseField name="importance" type="number">
      Importance score.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="nodes" type="array">
  All memories discovered in the graph traversal.
</ResponseField>

<ResponseField name="edges" type="array">
  Relationships between memories.

  <Expandable title="Edge object">
    <ResponseField name="source_id" type="string">
      UUID of the source memory.
    </ResponseField>

    <ResponseField name="target_id" type="string">
      UUID of the target memory.
    </ResponseField>

    <ResponseField name="relation_type" type="string">
      Type of relationship.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="depth" type="number">
  Actual depth traversed.
</ResponseField>

## Example

<CodeGroup>
  ```bash curl theme={null}
  curl "https://api.memoclaw.com/v1/memories/550e8400-e29b-41d4-a716-446655440000/graph?depth=2" \
    -H "x-wallet-auth: 0xYourWallet:1699900000:0xSignature..."
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    "https://api.memoclaw.com/v1/memories/550e8400-e29b-41d4-a716-446655440000/graph?depth=2",
    { headers: { "x-wallet-auth": await getAuthHeader() } }
  );
  const data = await response.json();
  ```

  ```python Python theme={null}
  from memoclaw import MemoClaw

  client = MemoClaw()

  result = client.get_memory_graph(
      "550e8400-e29b-41d4-a716-446655440000",
      depth=2,
  )
  print(f"Found {len(result.nodes)} nodes and {len(result.edges)} edges")
  ```

  ```typescript TypeScript theme={null}

  import { MemoClawClient } from "memoclaw";

  const client = new MemoClawClient();

  const result = await client.getMemoryGraph(
    "550e8400-e29b-41d4-a716-446655440000",
    { depth: 2 }
  );
  console.log(`Found ${result.nodes.length} nodes and ${result.edges.length} edges`);
  ```
</CodeGroup>

```json Response theme={null}
{
  "root": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "content": "User prefers dark mode",
    "importance": 0.8
  },
  "nodes": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "content": "User prefers dark mode",
      "importance": 0.8
    },
    {
      "id": "660e8400-e29b-41d4-a716-446655440001",
      "content": "Dark mode saves battery",
      "importance": 0.5
    },
    {
      "id": "770e8400-e29b-41d4-a716-446655440002",
      "content": "User uses vim keybindings",
      "importance": 0.7
    }
  ],
  "edges": [
    {
      "source_id": "550e8400-e29b-41d4-a716-446655440000",
      "target_id": "660e8400-e29b-41d4-a716-446655440001",
      "relation_type": "supports"
    },
    {
      "source_id": "550e8400-e29b-41d4-a716-446655440000",
      "target_id": "770e8400-e29b-41d4-a716-446655440002",
      "relation_type": "related_to"
    }
  ],
  "depth": 2
}
```
