aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/user-profiles.mdx
blob: ec9ff57d2bc682885c12de341eb73405c391ffe6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
---
title: "User Profiles"
sidebarTitle: "User Profiles"
description: "Fetch and use automatically maintained user context"
icon: "user"
---

User profiles are extremely short summaries of context about an entity (Usually a user, but can be anything) which includes both the *static* facts about them, as well as a few recent episodes.

> You can think of these as a dynamic compaction that's done by supermemory in real-time.

This profile should be injected into the agent context for truly personalized experiences. To read more, visit [User profiles - Concept](/concepts/user-profiles)

Get a user's profile — their static facts and dynamic context — with a single API call.

<Tip>
Profiles are built automatically as you [ingest content](/add-memories). No setup required.
</Tip>

## Quick Start

<Tabs>
  <Tab title="TypeScript">
    ```typescript
    import Supermemory from 'supermemory';

    const client = new Supermemory();

    const { profile } = await client.profile({
      containerTag: "user_123"
    });

    console.log(profile.static);   // Long-term facts
    console.log(profile.dynamic);  // Recent context
    ```
  </Tab>
  <Tab title="Python">
    ```python
    from supermemory import Supermemory

    client = Supermemory()

    result = client.profile(container_tag="user_123")

    print(result.profile.static)   # Long-term facts
    print(result.profile.dynamic)  # Recent context
    ```
  </Tab>
  <Tab title="cURL">
    ```bash
    curl -X POST "https://api.supermemory.ai/v4/profile" \
      -H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"containerTag": "user_123"}'
    ```
  </Tab>
</Tabs>

**Response:**
```json
{
  "profile": {
    "static": [
      "User is a software engineer",
      "User specializes in Python and React",
      "User prefers dark mode interfaces"
    ],
    "dynamic": [
      "User is working on Project Alpha",
      "User recently started learning Rust",
      "User is debugging authentication issues"
    ]
  }
}
```

---

## Profile + Search

Get profile and search results in one call by adding the `q` parameter:

<Tabs>
  <Tab title="TypeScript">
    ```typescript
    const result = await client.profile({
      containerTag: "user_123",
      q: "deployment errors"
    });

    // Profile data
    const { static: facts, dynamic: context } = result.profile;

    // Search results (only if q was provided)
    const memories = result.searchResults?.results || [];
    ```
  </Tab>
  <Tab title="Python">
    ```python
    result = client.profile(
        container_tag="user_123",
        q="deployment errors"
    )

    # Profile data
    facts = result.profile.static
    context = result.profile.dynamic

    # Search results
    memories = result.search_results.results if result.search_results else []
    ```
  </Tab>
</Tabs>

---

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `containerTag` | string | Yes | User/project identifier |
| `q` | string | No | Search query (includes search results in response) |
| `threshold` | 0-1 | No | Filter search results by relevance score |

---

## Building Prompts

The most common pattern — inject profile into your LLM's system prompt:

```typescript
async function chat(userId: string, message: string) {
  const { profile } = await client.profile({ containerTag: userId });

  const systemPrompt = `You are assisting a user.

ABOUT THE USER:
${profile.static?.join('\n') || 'No profile yet.'}

CURRENT CONTEXT:
${profile.dynamic?.join('\n') || 'No recent activity.'}

Personalize responses to their expertise and preferences.`;

  return llm.chat({
    messages: [
      { role: "system", content: systemPrompt },
      { role: "user", content: message }
    ]
  });
}
```

---

## Full Context Pattern

Get profile + query-specific memories in one call:

```typescript
async function getContext(userId: string, query: string) {
  const result = await client.profile({
    containerTag: userId,
    q: query,
    threshold: 0.6
  });

  return `
User Background:
${result.profile.static.join('\n')}

Current Context:
${result.profile.dynamic.join('\n')}

Relevant Memories:
${result.searchResults?.results.map(m => m.memory).join('\n') || 'None'}
  `;
}
```

---

## Framework Examples

<Accordion title="Express.js Middleware">
  ```typescript
  async function withProfile(req, res, next) {
    if (!req.user?.id) return next();

    try {
      const { profile } = await client.profile({
        containerTag: req.user.id
      });
      req.userProfile = profile;
    } catch (e) {
      req.userProfile = null;
    }
    next();
  }

  app.use(withProfile);

  app.post('/chat', (req, res) => {
    // req.userProfile available in all routes
  });
  ```
</Accordion>

<Accordion title="Next.js API Route">
  ```typescript
  // app/api/chat/route.ts
  export async function POST(req: NextRequest) {
    const { userId, message } = await req.json();

    const { profile } = await client.profile({
      containerTag: userId
    });

    const response = await generateResponse(message, profile);
    return NextResponse.json({ response });
  }
  ```
</Accordion>

<Accordion title="AI SDK Integration">
  ```typescript
  import { withSupermemory } from "@supermemory/tools/ai-sdk"
  import { openai } from "@ai-sdk/openai"

  // Profiles automatically injected
  const model = withSupermemory(openai("gpt-4"), "user-123")

  const result = await generateText({
    model,
    messages: [{ role: "user", content: "Help with my project" }]
  });
  ```

  See [AI SDK Integration](/integrations/ai-sdk) for details.
</Accordion>

---

## Response Schema

```typescript
interface ProfileResponse {
  profile: {
    static: string[];   // Long-term facts
    dynamic: string[];  // Recent context
  };
  searchResults?: {     // Only if q parameter provided
    results: SearchResult[];
    total: number;
    timing: number;
  };
}
```

---

## Next Steps

- [User Profiles Concept](/concepts/user-profiles) — Understand static vs dynamic
- [Ingesting Content](/add-memories) — Build profiles by adding content
- [AI SDK Integration](/integrations/ai-sdk) — Automatic profile injection