diff options
| author | Dhravya Shah <[email protected]> | 2025-09-28 16:42:06 -0700 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2025-09-28 16:42:06 -0700 |
| commit | 2093b316d9ecb9cfa9c550f436caee08e12f5d11 (patch) | |
| tree | 07b87fbd48b0b38ef26b9d5f839ad8cd61d82331 /apps/docs/memory-api/searching | |
| parent | Merge branch 'main' of https://github.com/supermemoryai/supermemory (diff) | |
| download | archived-supermemory-2093b316d9ecb9cfa9c550f436caee08e12f5d11.tar.xz archived-supermemory-2093b316d9ecb9cfa9c550f436caee08e12f5d11.zip | |
migrate docs to public
Diffstat (limited to 'apps/docs/memory-api/searching')
| -rw-r--r-- | apps/docs/memory-api/searching/searching-memories.mdx | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/apps/docs/memory-api/searching/searching-memories.mdx b/apps/docs/memory-api/searching/searching-memories.mdx new file mode 100644 index 00000000..517b835d --- /dev/null +++ b/apps/docs/memory-api/searching/searching-memories.mdx @@ -0,0 +1,181 @@ +--- +title: "Searching Memories" +description: "Learn how to search for and retrieve content from supermemory" +--- + +<Accordion title="Best Practices" defaultOpen icon="sparkles"> +1. **Query Formulation**: + - Use natural language queries + - Include relevant keywords + - Be specific but not too verbose + +2. **Filtering**: + - Use metadata filters for precision + - Combine multiple filters when needed + - Use appropriate thresholds + +3. **Performance**: + - Set appropriate result limits + - Use specific document/chunk filters + - Consider response timing + +</Accordion> + +## Basic Search + +To search through your memories, send a POST request to `/search`: + +<CodeGroup> + +```bash cURL +curl https://api.supermemory.ai/v3/search?q=machine+learning+concepts&limit=10 \ + --request GET \ + --header 'Authorization: Bearer SUPERMEMORY_API_KEY' +``` + +```typescript Typescript +await client.search.execute({ + q: "machine learning concepts", + limit: 10, +}); +``` + +```python Python +client.search.execute( + q="machine learning concepts", + limit=10 +) +``` + +</CodeGroup> + +The API will return relevant matches with their similarity scores: + +```json +{ + "results": [ + { + "documentId": "doc_xyz789", + "chunks": [ + { + "content": "Machine learning is a subset of artificial intelligence...", + "isRelevant": true, + "score": 0.85 + } + ], + "score": 0.95, + "metadata": { + "source": "web", + "category": "technology" + }, + "title": "Introduction to Machine Learning" + } + ], + "total": 1, + "timing": 123.45 +} +``` + +## Search Parameters + +```json +{ + "q": "search query", // Required: Search query string + "limit": 10, // Optional: Max results (default: 10) + "threshold": 0.6, // Optional: Min similarity score (0-1, default: 0.6) + "containerTag": "user_123", // Optional: Filter by container tag + "rerank": false, // Optional: Rerank results for better relevance + "rewriteQuery": false, // Optional: Rewrite query for better matching + "include": { + "documents": false, // Optional: Include document metadata + "summaries": false, // Optional: Include document summaries + "relatedMemories": false, // Optional: Include related memory context + "forgottenMemories": false // Optional: Include forgotten memories in results + }, + "filters": { + // Optional: Metadata filters + "AND": [ + { + "key": "category", + "value": "technology" + } + ] + } +} +``` + +## Search Response + +The search response includes: + +```json +{ + "results": [ + { + "documentId": "string", // Document ID + "chunks": [ + { + // Matching chunks + "content": "string", // Chunk content + "isRelevant": true, // Is directly relevant + "score": 0.95 // Similarity score + } + ], + "score": 0.95, // Document score + "metadata": {}, // Document metadata + "title": "string", // Document title + "createdAt": "string", // Creation date + "updatedAt": "string" // Last update date + } + ], + "total": 1, // Total results + "timing": 123.45 // Search time (ms) +} +``` + +## Including Forgotten Memories + +By default, the search API excludes memories that have been marked as forgotten or have passed their expiration date. To include these in your search results, set `include.forgottenMemories` to `true`: + +<CodeGroup> + +```bash cURL +curl https://api.supermemory.ai/v4/search \ + --request POST \ + --header 'Authorization: Bearer SUPERMEMORY_API_KEY' \ + --header 'Content-Type: application/json' \ + --data '{ + "q": "old project notes", + "include": { + "forgottenMemories": true + } + }' +``` + +```typescript Typescript +await client.search.memories({ + q: "old project notes", + include: { + forgottenMemories: true + } +}); +``` + +```python Python +await client.search.memories( + q="old project notes", + include={ + "forgottenMemories": True + } +) +``` + +</CodeGroup> + +<Note> +Forgotten memories are memories that have been explicitly forgotten using the forget API or have passed their automatic expiration date (`forgetAfter`). Including them in search results can help recover information that may still be relevant. +</Note> + +## Next Steps + +Explore more advanced features in our [API Reference](/api-reference/search-memories/search-memories). |