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

# Memory vs Context

> Learn to manage conversation state by combining Memory and Context for each use case.

Choosing between `$memory` and `$context` comes down to one simple question: **do you need this data after the conversation ends?**

## Use \$context when

Use `$context` when the data is only needed during the current conversation.

**Use cases:**

* **Checking product availability:** The user asks about a product, you query your inventory and save the available stock in `$context.stock` to display it and validate the quantity they want to buy in the following nodes
* **Validating a discount code:** The user enters a coupon, you validate it with your API and save the percentage in `$context.discount` to apply it when calculating the total
* **Temporary authentication:** You get a token from your API and save it in `$context.token` to use in subsequent calls within the same flow
* **Intermediate calculations:** The user selects products, you keep adding up the subtotal in `$context.subtotal` to display it before confirming the purchase

**Example:**

```txt theme={null}
1. User asks: "Do you have the blue shirt in size M?"
2. API node → Queries inventory and saves $context.stock = 5
3. Message node → "We have {{$context.stock}} units available"
4. User purchases → You validate the quantity does not exceed $context.stock
```

## Use \$memory when

Use `$memory` when the data must persist between conversations. You can configure the time-to-live (TTL) for each variable.

**Use cases:**

* Remembering the user's name to greet them personally
* Saving the last shipping address to offer it as a default
* Storing preferences that improve the experience in future interactions
* Remembering that the user completed a verification step

**Example:**

```txt theme={null}
Conversation 1: User says "My name is Maria"
→ You save $memory.name = "Maria"

Conversation 2 (same day):
→ You use {{$memory.name}} to greet: "Hello Maria"
```

<Note>
  For details on data types, TTL, files, and available methods, see the [complete Memory guide](/guides/variables/memory).
</Note>

## Quick decision criteria

<Steps>
  <Step title="Do you need the data in future conversations?">
    **No** → Use `$context`

    **Yes** → Use `$memory`
  </Step>
</Steps>

## Summary

| Aspect       | \$context                          | \$memory                                                 |
| ------------ | ---------------------------------- | -------------------------------------------------------- |
| **Duration** | Only during the conversation       | Configurable (TTL): up to 1 day (JSON) or 1 week (files) |
| **Types**    | Any JavaScript value               | Primitives, JSON (15 KB), Files (10 MB)                  |
| **Use**      | Temporary conversation data        | Improve experience between conversations                 |
| **Security** | Ideal for temporary sensitive data | Do not use for sensitive data                            |
