> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memobase.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

Ready to give your AI a memory boost? Here’s how to get started.

<CardGroup cols={2}>
  <Card title="Patch OpenAI" icon="webhook" href="practices/openai">
    Upgrade your existing OpenAI setup with Memobase memory.
  </Card>

  <Card title="Client-Side" icon="code-branch" href="#memobase-client">
    Use our SDKs or APIs to connect your app to a Memobase backend.
  </Card>

  <Card title="Server-Side" icon="chart-simple" href="#memobase-backend">
    Deploy your own Memobase backend. It's easier than assembling IKEA furniture.
  </Card>
</CardGroup>

## Memobase Client

### Step 1: Get Prepped

<AccordionGroup>
  <Accordion title="Install the SDK">
    <CodeGroup>
      ```bash pip theme={null}
      pip install memobase
      ```

      ```bash npm theme={null}
      npm install @memobase/memobase
      ```

      ```bash deno theme={null}
      deno add jsr:@memobase/memobase
      ```

      ```bash go theme={null}
      go get github.com/memodb-io/memobase/src/client/memobase-go@latest
      ```

      ```bash http theme={null}
      # Living on the edge with cURL? Skip to the next step.
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Find Your Project URL and Token">
    You'll get these when you set up your [backend](#memobase-backend). Keep them handy.
  </Accordion>
</AccordionGroup>

### Step 2: Connect to the Backend

<AccordionGroup>
  <Accordion title="Instantiate the Client">
    <CodeGroup>
      ```python Python theme={null}
      from memobase import MemoBaseClient

      client = MemoBaseClient(
          project_url=YOUR_PROJECT_URL,
          api_key=YOUR_API_KEY,
      )
      ```

      ```typescript Node theme={null}
      import { MemoBaseClient, Blob, BlobType } from '@memobase/memobase';

      const client = new MemoBaseClient(process.env['MEMOBASE_PROJECT_URL'], process.env['MEMOBASE_API_KEY'])
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Test the Connection (Ping!)">
    <CodeGroup>
      ```python Python theme={null}
      assert client.ping()
      ```

      ```typescript Node theme={null}
      const ping = await client.ping()
      ```

      ```bash cURL theme={null}
      curl -H "Authorization: Bearer $YOUR_API_KEY" "$YOUR_PROJECT_URL/api/v1/healthcheck"
      ```

      ```json Output theme={null}
      {"data":null,"errno":0,"errmsg":""}
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

### Step 3: User Management

Create, read, update, and delete users.

<AccordionGroup>
  <Accordion title="Create a User">
    <CodeGroup>
      ```python Python theme={null}
      uid = client.add_user({"name": "Gustavo"})
      ```

      ```typescript Node theme={null}
      const userId = await client.addUser({name: "Gustavo"})
      ```

      ```bash cURL theme={null}
      curl -X POST "$YOUR_PROJECT_URL/api/v1/users" \
           -H "Authorization: Bearer $YOUR_API_KEY" \
           -H "Content-Type: application/json" \
           -d '{"data": {"name": "Gustavo"}}'
      ```

      ```json Output theme={null}
      {"data":{"id":"some-unique-user-id"},"errno":0,"errmsg":""}
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Get a User">
    <CodeGroup>
      ```python Python theme={null}
      u = client.get_user(uid)
      ```

      ```typescript Node theme={null}
      const user = await client.getUser(userId)
      ```

      ```bash cURL theme={null}
      curl -X GET "$YOUR_PROJECT_URL/api/v1/users/{uid}" \
           -H "Authorization: Bearer $YOUR_API_KEY"
      ```

      ```json Output theme={null}
      {"data":{"data":{"name":"Gustavo", "status": "caffeinated"}, ... },"errno":0,"errmsg":""}
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

### Step 4: Insert Message

Now that you have a user, let's give them some memories.

<AccordionGroup>
  <Accordion title="Insert Data (e.g. Chats)">
    <CodeGroup>
      ```python Python theme={null}
      from memobase import ChatBlob
      b = ChatBlob(messages=[
          {"role": "user", "content": "Hi, I'm here again"},
          {"role": "assistant", "content": "Hi, Gus! How can I help you?"}
      ])
      u = client.get_user(uid)
      bid = u.insert(b)
      ```

      ```typescript Node theme={null}
      const blobId = await user.insert(Blob.parse({
          type: BlobType.Enum.chat,
          messages: [{
              role: 'user',
              content: 'Hello, how are you?'
          }]
      }))
      ```

      ```bash cURL theme={null}
      curl -X POST "$YOUR_PROJECT_URL/api/v1/blobs/insert/{uid}" \
           -H "Authorization: Bearer $YOUR_API_KEY" \
           -H "Content-Type: application/json" \
           -d '{ "blob_type": "chat", "blob_data": { "messages": [ {"role": "user","content": "Hi, Im here again"}, {"role": "assistant", "content": "Hi, Gus! How can I help you?"}] }}'
      ```

      ```json Output theme={null}
      {"data":{"id":"some-unique-blob-id"},"errno":0,"errmsg":""}
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

### Step 5: Memory Operations

This is where the magic happens. Memobase extracts and stores memories for each user.

1. **`flush`**: User data is held in a buffer. If the buffer gets too large or remains idle, it gets processed. You can also trigger this manually.

<Accordion title="Flush (e.g., after a chat session ends)">
  <CodeGroup>
    ```python Python theme={null}
    u.flush() # async
    u.flush(sync=True) # sync
    ```

    ```typescript Node theme={null}
    await user.flush(BlobType.Enum.chat)
    ```

    ```bash cURL theme={null}
    curl -X POST "$YOUR_PROJECT_URL/api/v1/users/buffer/{uid}/chat" \
         -H "Authorization: Bearer $YOUR_API_KEY"
    ```

    ```json Output theme={null}
    {"data":null,"errno":0,"errmsg":""}
    ```
  </CodeGroup>
</Accordion>

{/* <Accordion title="Get User Profile">
<CodeGroup>

```python Python
u.profile()
```

```typescript Node
const profiles = await user.profile()
```

```go Go
profiles, err := user.Profile(nil)
```

```bash cURL
curl -X GET "$YOUR_PROJECT_URL/api/v1/users/profile/{uid}" \
   -H "Authorization: Bearer $YOUR_API_KEY"
```

```json Output
{"data":{"profiles":[ {"content":"Gus", "attributes":{}}, ... ]},"errno":0,"errmsg":""}
```
</CodeGroup>
</Accordion> */}

2. Get Personalized Context:

<Accordion title="context API">
  <CodeGroup>
    ```python Python theme={null}
    u.context()
    ```

    ```typescript Node theme={null}
    const context = await user.context();
    ```

    ```bash cURL theme={null}
    curl -X GET "$YOUR_PROJECT_URL/api/v1/users/context/{uid}" \
         -H "Authorization: Bearer $YOUR_API_KEY"
    ```

    ```txt Output theme={null}
    # Memory
    Unless the user has relevant queries, do not actively mention those memories in the conversation.
    ## User Background:
    - basic_info:name: Gus
    - basic_info:location: San Francisco
    ...

    ## Latest Events:
    - Gus went to the gym [mentioned on 2024-01-02]
    - Gus had a coffee with his friend [mentioned on 2024-01-01]
    ...
    ```
  </CodeGroup>
</Accordion>

3. Pack the context into your system prompt:

<Accordion title="Insert personalized contex">
  <CodeGroup>
    ```python Python theme={null}
    from openai import OpenAI

    client = OpenAI(api_key=YOUR_API_KEY)

    SYSTEM_PROMPT = f"""You're a helpful assistant.
    Your job is to ...

    Below is the user's memory:
    {context}"""


    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": "Who'am I?s"}
        ]
    )

    print(response.choices[0].message.content)
    ```

    ```txt Output theme={null}
    You're Gus! How can I help you today?
    ```
  </CodeGroup>
</Accordion>

## Memobase Backend

We offer an [open-source solution](https://github.com/memodb-io/memobase) with a Docker backend to launch your own instance.
You can use `docker-compose` to launch the backend [in one command](https://github.com/memodb-io/memobase/blob/main/src/server/readme.md#get-started).

## Memobase Cloud

We also offer a [hosted cloud service](https://www.memobase.io/), with free tier and nice dashboard.

<Frame caption="Memobase Cloud Dashboard">
  <video autoPlay muted loop playsInline src="https://github.com/user-attachments/assets/eb2eea30-48bc-4714-9706-e417ae1931df" />
</Frame>
