aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/vibe-coding.mdx
blob: bb5cd0e98563fdef1cae56b4fbb2b187ae4941a1 (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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
---
title: "Vibe Coding Setup"
description: "Automatic Supermemory integration using AI coding agents"
icon: "zap"
sidebarTitle: "Install with AI"
---

Get your AI coding agent to integrate Supermemory in minutes. Copy the prompt below, paste it into Claude/GPT/Cursor, and let it do the work.

## Quick Setup

<CardGroup cols={3}>
	<Card title="MCP (Claude/Cursor)" icon="plug" href="#mcp-server">
		Give your agent a way to reference and search through supermemory docs.
  </Card>

	<Card title="Copy Prompt" icon="copy" href="#the-prompt">
    Paste one prompt, answer questions, get working code
  </Card>

  <Card title="Claude Code Skill" icon="terminal" href="#claude-code-skill">
    Interactive guided setup
  </Card>
</CardGroup>

## MCP Server

Give your agent a way to reference and search through supermemory docs.

### Quick Install

```bash
npx -y install-mcp@latest https://supermemory.ai/docs/mcp --client claude-code --oauth=no -y
```

Replace `claude` with: `cursor`, `opencode`, or `vscode`


---

## The Prompt

<Note>
**Copy everything in the code block below** and paste it into your AI coding agent. It will ask you questions and generate complete integration code.
</Note>

After adding the MCP, paste this in your agent session:

<Accordion title="Copy prompt below." icon='copy'>
```
You are integrating Supermemory into my application. Supermemory provides user memory, semantic search, and automatic knowledge extraction for AI applications.

Note: You can always reference the documentation by using the **SearchSupermemoryDocs MCP** or running a web search tool for content on **supermemory.ai/docs**.

STEP 1: ASK ME THESE QUESTIONS

1. What are you building?
   - Personal chatbot/assistant
   - Team knowledge base
   - Customer support bot
   - Document Q&A
   - Other

2. How do you want to integrate?
   - Vercel AI SDK (@supermemory/tools)
   - OpenAI plugins
   - Direct SDK (supermemory npm/pip)
   - Direct API calls

3. Data model?
   - Individual users only → containerTag: userId
   - Organizations only → containerTag: orgId
   - Both users AND orgs → ask for strategy

4. Do you want USER PROFILES?
   User profiles are automatically-maintained facts about users (what they like, what they're working on, preferences).
   - Yes (RECOMMENDED) → Use client.profile() to get context
   - No → Just use search

5. How should I retrieve context?
   - OPTION A: One call with search included → profile({ containerTag, q: userMessage })
   - OPTION B: Separate calls → profile() for facts, search() for memories

STEP 2: INSTALL

# Get API key: https://console.supermemory.ai
npm install supermemory  # or: pip install supermemory
# For Vercel AI SDK: npm install @supermemory/tools
export SUPERMEMORY_API_KEY="sm_..."


STEP 3: CONFIGURE SETTINGS (DO THIS FIRST)

typescript
// PATCH https://api.supermemory.ai/v3/settings
fetch('https://api.supermemory.ai/v3/settings', {
  method: 'PATCH',
  headers: { 'x-supermemory-api-key': process.env.SUPERMEMORY_API_KEY },
  body: JSON.stringify({
    shouldLLMFilter: true,
    filterPrompt: `This is a [your app description]. containerTag is [userId/orgId]. We store [what data].`
  })
})

STEP 4: CONTAINER TAG STRATEGY

Based on their data model answer:

USER-ONLY APP:
typescript


ORG-ONLY APP:
typescript
containerTag: orgId  // Org members share memories


BOTH (ask which):
- Option A: `containerTag: \`\${userId}-\${orgId}\``
- Option B: `containerTag: orgId, metadata: { userId }`
- Option C: `containerTag: userId, metadata: { orgId }`

STEP 5: INTEGRATION CODE

Based on their integration choice:

--- VERCEL AI SDK ---

typescript
import { streamText } from 'ai'
import { anthropic } from '@ai-sdk/anthropic'
import { supermemoryTools } from '@supermemory/tools/ai-sdk'

// Option 1: Agent tools (recommended for agentic flows)
const result = await streamText({
  model: anthropic('claude-3-5-sonnet-20241022'),
  prompt: userMessage,
  tools: supermemoryTools(process.env.SUPERMEMORY_API_KEY, {
    containerTags: [userId]
  })
})
// Agent gets searchMemories, addMemory, fetchMemory tools

// Option 2: Profile middleware (automatic context injection)
import { withSupermemory } from '@supermemory/tools/ai-sdk'
const modelWithMemory = withSupermemory(anthropic('claude-3-5-sonnet-20241022'), userId)

const result = await generateText({
  model: modelWithMemory,
  messages: [{ role: 'user', content: userMessage }]
})
// Profile is automatically injected into context


--- DIRECT SDK (WITH PROFILES) ---

typescript
import Supermemory from 'supermemory'

const client = new Supermemory()

// Before each LLM call:
const { profile, searchResults } = await client.profile({
  containerTag: userId,
  q: userMessage  // Include this if they chose OPTION A (one call)
                  // Omit if they chose OPTION B (separate calls)
})

// Build context
const context = `
Static facts: ${profile.static.join('\n')}
Recent context: ${profile.dynamic.join('\n')}
${searchResults ? `Memories: ${searchResults.results.map(r => r.memory).join('\n')}` : ''}
`

// Send to LLM
const messages = [
  { role: 'system', content: `User context:\n${context}` },
  { role: 'user', content: userMessage }
]

// After LLM responds:
await client.add({
  content: `user: ${userMessage}\nassistant: ${response}`,
  containerTag: userId
})


--- DIRECT SDK (NO PROFILES) ---

```typescript
import Supermemory from 'supermemory'

const client = new Supermemory()

// Search for relevant memories
const results = await client.search({
  q: userMessage,
  containerTag: userId,
  searchMode: 'hybrid',  // Searches memories + document chunks
  limit: 5
})

// Build context
const context = results.results.map(r => r.memory || r.chunk).join('\n')

// Send to LLM with context
const messages = [
  { role: 'system', content: `Relevant context:\n${context}` },
  { role: 'user', content: userMessage }
]

// Store the conversation
await client.add({
  content: `user: ${userMessage}\nassistant: ${response}`,
  containerTag: userId
})

--- PYTHON VERSION ---
python
from supermemory import Supermemory

client = Supermemory()

# With profiles (if they want it)
profile_data = client.profile(
    container_tag=user_id,
    q=user_message  # Include if OPTION A, omit if OPTION B
)

context = f"""
Static: {chr(10).join(profile_data.profile.static)}
Dynamic: {chr(10).join(profile_data.profile.dynamic)}
"""

# Store conversation
client.add(content=f"user: {user_message}\\nassistant: {response}", container_tag=user_id)

--- DIRECT API ---

bash
# Add memory
curl -X POST https://api.supermemory.ai/v3/documents \
  -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
  -d '{"content": "conversation", "containerTag": "userId"}'

# Get profile
curl -X POST https://api.supermemory.ai/v4/profile \
  -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
  -d '{"containerTag": "userId", "q": "search query"}'

# Search
curl -X POST https://api.supermemory.ai/v4/search \
  -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
  -d '{"q": "query", "containerTag": "userId", "searchMode": "hybrid"}'

STEP 6: FILE UPLOADS (if they need it)

typescript
// Files are automatically extracted (PDFs, images with OCR, videos with transcription)
const formData = new FormData()
formData.append('file', fileBlob)
formData.append('containerTag', userId)

await fetch('https://api.supermemory.ai/v3/documents/file', {
  method: 'POST',
  headers: { 'x-supermemory-api-key': process.env.SUPERMEMORY_API_KEY },
  body: formData
})

// Processing is async - check status before assuming searchable
// GET /v3/documents/{documentId}


STEP 7: SEARCH MODES

typescript
// HYBRID (recommended) - searches memories + document chunks
searchMode: 'hybrid'

// MEMORIES ONLY - just extracted memories, no original text
searchMode: 'memories'


STEP 8: METADATA FILTERS (if they need secondary filtering)

typescript
await client.search({
  q: query,
  containerTag: userId,
  filters: {
    AND: [
      { key: 'type', value: 'conversation', type: 'string_equal' },
      { key: 'timestamp', value: '2024', type: 'string_contains' }
    ]
  }
})

KEY POINTS:

1. Configure settings FIRST with filterPrompt
2. User profiles = automatic facts about users (profile.static + profile.dynamic)
3. profile({ containerTag, q }) combines profile + search in ONE call
4. Search modes: 'hybrid' (recommended) or 'memories'
5. File extraction is automatic - no config needed
6. Store conversations after each interaction
7. containerTag should match what you put in filterPrompt

TESTING:

bash
# 1. Configure settings
curl -X PATCH https://api.supermemory.ai/v3/settings \
  -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
  -d '{"shouldLLMFilter": true, "filterPrompt": "..."}'

# 2. Add test memory
curl -X POST https://api.supermemory.ai/v3/documents \
  -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
  -d '{"content": "Test", "containerTag": "test_user"}'

# 3. Get profile
curl -X POST https://api.supermemory.ai/v4/profile \
  -H "x-supermemory-api-key: $SUPERMEMORY_API_KEY" \
  -d '{"containerTag": "test_user"}'


NOW:
1. Ask me the 5 questions above
2. Generate complete working code based on my answers
3. Include installation, settings config, and full integration

DOCS: https://supermemory.ai/docs
```
</Accordion>



---

## Claude Code Skill

Interactive setup for Claude Code users.

### Install

```bash
# 1. Clone repo
git clone https://github.com/supermemoryai/supermemory.git

# 2. Copy skill
mkdir -p ~/.claude/skills
cp supermemory/.claude/skills/supermemory-integrate.md ~/.claude/skills/

# 3. Restart Claude Code
```

### Use

```bash
/supermemory-integrate
```

The skill asks questions interactively and generates code for your specific setup.

---

## Next Steps

<CardGroup cols={2}>
  <Card title="Quickstart" icon="rocket" href="/quickstart">
    Manual integration guide
  </Card>

  <Card title="User Profiles" icon="user" href="/concepts/user-profiles">
    Deep dive into profiles
  </Card>

  <Card title="Search API" icon="search" href="/search">
    Search modes and parameters
  </Card>

  <Card title="API Reference" icon="code" href="https://api.supermemory.ai/v3/openapi">
    Complete API docs
  </Card>
</CardGroup>