aboutsummaryrefslogtreecommitdiff
path: root/apps/docs/essentials/distinguishing-users.mdx
blob: 28c7167f492b2c5242a6b108461b167389e92f39 (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
---
title: "Managing Multi-User Search Results"
description: "Learn how to handle search results for different users in Supermemory"
icon: "users"
---

When building multi-user applications with Supermemory, you'll often need to manage data for different users accessing the same account. Here's everything you need to know about handling multi-user scenarios:

## What are Spaces?

Spaces are Supermemory's way of organizing and separating data for different users or groups. They help you:

- Keep each user's data separate and organized
- Group related content together
- Manage access control efficiently
- Scale your application to multiple users

## How to Use Spaces

**Creating Spaces**

- Spaces are automatically provisioned when you use the `spaces` parameter
- No separate setup or initialization needed
- Example API call:

```bash
curl -X POST https://api.supermemory.ai/v1/add \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content": "This is the content of my first memory.", "spaces": ["user1", "user2"]}'
```

## Manually Creating Spaces

You can also manually create spaces by using the `/spaces/create` endpoint.

```bash
curl -X POST https://api.supermemory.ai/v1/spaces/create \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"spaceName": "user1", "isPublic": false}'
```

Creating a public space will make it globally accessible to all users. By default, spaces are private.

## Retrieving Spaces

You can retrieve all spaces for a user by using the `/spaces` endpoint.

```bash
curl -X GET https://api.supermemory.ai/v1/spaces/list \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Moving a content to a Specific Space

You can move a memory to a specific space by using the `space/addContent` endpoint and specifying the space id and the document id.

```bash
curl -X POST https://api.supermemory.ai/v1/space/addContent \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"spaceId": "123", "documentId": "456"}'
```

## Retrieving Content from a Specific Space

You can retrieve content from a specific space by using the `/memories` endpoint and specifying the space id.

```bash
curl -X GET https://api.supermemory.ai/v1/memories \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"spaceId": "123"}'
```

This also means that you can augment multiple spaces together to create a more complex search.

```bash
curl -X GET https://api.supermemory.ai/v1/search \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"spaces": ["person", "project", "team"], "query": "my query"}'
```

This will filter only for memories that are in all three spaces - `person`, `project`, and `team`.