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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
|
---
title: "Search with Filters & Scoring"
description: "Semantic and hybrid search with metadata filters, scoring, and precise result control"
sidebarTitle : "Overview"
---
## Prerequisites
Before searching memories, you need to set up the Supermemory client:
- **Install the SDK** for your language
- **Get your API key** from [Supermemory Console](https://console.supermemory.ai)
- **Initialize the client** with your API key
<CodeGroup>
```bash npm
npm install supermemory
```
```bash pip
pip install supermemory
```
</CodeGroup>
<CodeGroup>
```typescript TypeScript
import Supermemory from 'supermemory';
const client = new Supermemory({
apiKey: process.env.SUPERMEMORY_API_KEY!
});
```
```python Python
from supermemory import Supermemory
import os
client = Supermemory(
api_key=os.environ.get("SUPERMEMORY_API_KEY")
)
```
</CodeGroup>
## Search Endpoints Overview
<CardGroup cols={2}>
<Card title="Documents Search - Fast, Advanced RAG" icon="settings" href="/search/examples/document-search">
**POST /v3/search**
Full-featured search with extensive control over ranking, filtering, thresholds, and result structure. Searches through and returns relevant documents. More flexibility.
</Card>
<Card title="Memories Search" icon="zap" href="/search/examples/memory-search">
**POST /v4/search**
Minimal-latency search optimized for chatbots and conversational AI. Searches through and returns memories. Simple parameters, fast responses, easy to use.
</Card>
</CardGroup>
## Documents vs Memories Search: What's the Difference?
The key difference between `/v3/search` and `/v4/search` is **documents vs memories**. `/v3/search` searches through the documents and returns matching chunks, whereas `/v4/search` searches through user's memories, preferences and history.
- **Documents:** Refer to the data you ingest like text, pdfs, videos, images, etc. They are sources of ground truth.
- **Memories:** They are automatically extracted from your documents by Supermemory. Smaller information chunks inferred from documents and related to each other.
Refer to the [ingestion guide](/memory-api/ingesting) to learn more about the difference between documents and memories.
### Documents Search (`/v3/search`)
**High quality documents search** - extensive parameters for fine-tuning search behavior:
- **Use cases**: Use this endpoint for use cases where "literal" document search is required.
- Looking through legal/finance documents
- Searching through items in google drive
- Chat with documentation
- With this endpoint, you get **Full Control** over
- Thresholds,
- Filtering
- Reranking
- Query rewriting
<Tabs>
<Tab title="TypeScript">
```typescript
// Documents search
const results = await client.search.documents({
q: "machine learning accuracy",
limit: 10,
documentThreshold: 0.7,
chunkThreshold: 0.8,
rerank: true,
rewriteQuery: true,
includeFullDocs: true,
includeSummary: true,
onlyMatchingChunks: false,
containerTags: ["research"],
filters: {
AND: [{ key: "category", value: "ai", negate: false }]
}
});
```
</Tab>
<Tab title="Python">
```python
# Documents search
results = client.search.documents(
q="machine learning accuracy",
limit=10,
document_threshold=0.7,
chunk_threshold=0.8,
rerank=True,
rewrite_query=True,
include_full_docs=True,
include_summary=True,
only_matching_chunks=False,
container_tags=["research"],
filters={
"AND": [{"key": "category", "value": "ai", "negate": False}]
}
)
```
</Tab>
<Tab title="cURL">
```bash
curl -X POST "https://api.supermemory.ai/v3/search" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "machine learning accuracy",
"limit": 10,
"documentThreshold": 0.7,
"chunkThreshold": 0.8,
"rerank": true,
"rewriteQuery": true,
"includeFullDocs": true,
"includeSummary": true,
"onlyMatchingChunks": false,
"containerTags": ["research"],
"filters": {
"AND": [{"key": "category", "value": "ai", "negate": false}]
}
}'
```
</Tab>
</Tabs>
```json Sample Response
{
"results": [
{
"documentId": "doc_abc123",
"title": "Machine Learning Fundamentals",
"type": "pdf",
"score": 0.89,
"chunks": [
{
"content": "Machine learning is a subset of artificial intelligence...",
"score": 0.95,
"isRelevant": true
}
],
"metadata": {
"category": "education",
"author": "Dr. Smith",
"difficulty": "beginner"
},
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-20T14:45:00Z"
}
],
"timing": 187,
"total": 1
}
```
The `/v3/search` endpoint returns the most relevant documents and chunks from those documents. Head over to the [response schema](/search/response-schema) page to understand more about the response structure.
### Memories Search (`/v4/search`)
**Search through user memories**:
- **Use cases**: Use this endpoint for use cases where understanding user context / preferences / memories is more important than literal document search.
- Personalized chatbots (AI Companions)
- Auto selecting based on what the user wants
- Setting the tone of the conversation
Companies like Composio [Rube.app](https://rube.app) use memories search for letting the MCP automate better based on the user prompts before.
<Info>
This endpoint works best for conversational AI use cases like chatbots.
</Info>
**Hybrid Search Mode:**
The `/v4/search` endpoint supports a `searchMode` parameter with two options:
- **`"memories"`** (default): Searches only memory entries. Returns results with a `memory` key containing the memory content.
- **`"hybrid"`**: Searches memories first, then falls back to document chunks if needed. Returns mixed results where each result object has either a `memory` key (for memory results) or a `chunk` key (for chunk results from documents).
<Note>
In hybrid mode, results are automatically merged by similarity score and deduplicated. Check for the presence of `memory` or `chunk` keys to distinguish result types.
</Note>
<Tabs>
<Tab title="TypeScript">
```typescript
// Memories search (default mode)
const results = await client.search.memories({
q: "machine learning accuracy",
limit: 5,
containerTag: "research",
threshold: 0.7,
rerank: true,
searchMode: "memories" // Default: only search memories
});
// Hybrid search (memories + chunks)
const hybridResults = await client.search.memories({
q: "machine learning accuracy",
limit: 5,
containerTag: "research",
threshold: 0.7,
searchMode: "hybrid" // Search memories + fallback to chunks
});
```
</Tab>
<Tab title="Python">
```python
# Memories search (default mode)
results = client.search.memories(
q="machine learning accuracy",
limit=5,
container_tag="research",
threshold=0.7,
rerank=True,
search_mode="memories" # Default: only search memories
)
# Hybrid search (memories + chunks)
hybrid_results = client.search.memories(
q="machine learning accuracy",
limit=5,
container_tag="research",
threshold=0.7,
search_mode="hybrid" # Search memories + fallback to chunks
)
```
</Tab>
<Tab title="cURL">
```bash
# Memories search (default mode)
curl -X POST "https://api.supermemory.ai/v4/search" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "machine learning accuracy",
"limit": 5,
"containerTag": "research",
"threshold": 0.7,
"rerank": true,
}'
# Hybrid search (memories + chunks)
curl -X POST "https://api.supermemory.ai/v4/search" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "machine learning accuracy",
"limit": 5,
"containerTag": "research",
"threshold": 0.7,
"rerank": true,
"searchMode": "hybrid"
}'
```
</Tab>
</Tabs>
```json Sample Response
{
"results": [
{
"id": "mem_xyz789",
"memory": "Complete memory content about quantum computing applications...",
"similarity": 0.87,
"metadata": {
"category": "research",
"topic": "quantum-computing"
},
"updatedAt": "2024-01-18T09:15:00Z",
"version": 3,
"context": {
"parents": [
{
"memory": "Earlier discussion about quantum theory basics...",
"relation": "extends",
"version": 2,
"updatedAt": "2024-01-17T16:30:00Z"
}
],
"children": [
{
"memory": "Follow-up questions about quantum algorithms...",
"relation": "derives",
"version": 4,
"updatedAt": "2024-01-19T11:20:00Z"
}
]
},
"documents": [
{
"id": "doc_quantum_paper",
"title": "Quantum Computing Applications",
"type": "pdf",
"createdAt": "2024-01-10T08:00:00Z"
}
]
}
],
"timing": 156,
"total": 1
}
```
The `/v4/search` endpoint searches through and returns memories. With `searchMode="hybrid"`, it can also return document chunks when memories aren't found, providing comprehensive search coverage.
## Direct Document Retrieval
If you don't need semantic search and just want to retrieve a specific document you've uploaded by its ID, use the GET document endpoint:
`GET /v3/documents/{id}`
This is useful when:
- You know the exact document ID
- You want to retrieve the full document content and metadata
- You need to check processing status or document details
<CodeGroup>
```typescript TypeScript
// Get a specific document by ID
const document = await client.documents.get("doc_abc123");
console.log(document.content); // Full document content
console.log(document.status); // Processing status
console.log(document.metadata); // Document metadata
console.log(document.summary); // AI-generated summary
```
```python Python
# Get a specific document by ID
document = client.documents.get("doc_abc123")
print(document.content) # Full document content
print(document.status) # Processing status
```
```bash cURL
curl -X GET "https://api.supermemory.ai/v3/documents/{YOUR-DOCUMENT-ID}" \
-H "Authorization: Bearer $SUPERMEMORY_API_KEY"
```
</CodeGroup>
<Note>
This endpoint returns the complete document with all fields including content, metadata, containerTags, summary, and processing status. For more details, see the API Reference tab.
</Note>
## Search Flow Architecture
### Document Search (`/v3/search`) Flow
```mermaid
graph TD
A[Query Input] --> B{Rewrite Query?}
B -->|Yes| C[Query Rewriting +400ms]
B -->|No| D[Generate Embeddings]
C --> E[Generate Rewritten Embeddings]
D --> F[Search Execution]
E --> F
F --> G[Apply Filtering<br/>metadata, categories, containerTags]
G --> H{Rerank?}
H -->|Yes| I[Apply Reranking]
H -->|No| J[Build Results with Chunks]
I --> J
J --> K[Return Documents + Chunks + Scores]
```
### Memory Search (`/v4/search`) Flow
```mermaid
graph TD
A[Query Input] --> B[Query Rewriting + Embedding]
B --> C[Parallel Search Execution]
C --> D[Apply Filtering]
D --> E[Merge Results]
E --> F[Deduplication]
F --> G{Rerank?}
G -->|Yes| H[Apply Reranking]
G -->|No| I[Return Memories + Similarity]
H --> I
```
## Key Concepts You Need to Understand
### 1. Thresholds (Sensitivity Control)
Thresholds control result quality vs quantity:
- **0.0** = Least sensitive (more results, lower quality)
- **1.0** = Most sensitive (fewer results, higher quality)
```typescript
// Different threshold strategies
const broadSearch = await client.search.documents({
q: "machine learning",
chunkThreshold: 0.2, // Return more chunks
documentThreshold: 0.1 // From more documents
});
const preciseSearch = await client.search.documents({
q: "machine learning",
chunkThreshold: 0.8, // Only highly relevant chunks
documentThreshold: 0.7 // From closely matching documents
});
```
### 2. Chunk Context vs Exact Matching
By default, Supermemory returns chunks **with context** (surrounding text):
```typescript
// Default: includes surrounding chunks for context
const contextualResults = await client.search.documents({
q: "neural networks",
onlyMatchingChunks: false // Default
});
// Precise: only the exact matching text
const exactResults = await client.search.documents({
q: "neural networks",
onlyMatchingChunks: true
});
```
### 3. Query Rewriting & Reranking
**Query Rewriting** (+400ms latency):
- Expands your query to find more relevant results
- "ML" becomes "machine learning artificial intelligence"
- Useful for abbreviations and domain-specific terms
**Reranking**:
- Re-scores results using a different algorithm
- More accurate but slower
- Recommended for critical searches
### 4. Container Tags vs Metadata Filters
Two different filtering mechanisms:
When to use container tags:
- The user understanding graph is built on top of container tags. **The graph is formed on top of container tags.**
- Container tags are used for organizational grouping and exact matching.
- They are useful for categorizing content and ensuring precise results.
When to use metadata filters:
- When you need flexible conditions beyond exact matches.
- Useful for filtering by attributes like date, author, or category.
```typescript
// Container tags: Organizational grouping (exact array matching)
const userContent = await client.search.documents({
q: "python tutorial",
containerTag "user_123" // Must match exactly
});
// Metadata filters: SQL-based queries (flexible conditions)
const filteredContent = await client.search.documents({
q: "python tutorial",
filters: JSON.stringify({
AND: [
{ key: "language", value: "python", negate: false },
{ key: "difficulty", value: "beginner", negate: false }
]
})
});
```
|