---
title: "First Memory"
description: "Mem0 (\"mem-zero\") provides an intelligent memory layer designed to enhance AI assistants and agents. It allows your AI applications to remember user preferences, adapt to individual needs, and cont..."
last_updated: "2026-05-07T04:49:20.297912+00:00"
canonical_url: "https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/guide/section-1/first-memory"
---

Mem0 ("mem-zero") provides an intelligent memory layer designed to enhance AI assistants and agents. It allows your AI applications to remember user preferences, adapt to individual needs, and continuously learn over time. This leads to more personalized and context-rich interactions, making AI systems more effective for tasks like customer support, personal assistants, and adaptive gaming environments.

This memory layer helps your AI maintain context across conversations and sessions, ensuring that interactions feel natural and informed by past exchanges. It manages different levels of memory, including user-specific information, session-specific details, and overall agent knowledge, to provide a seamless and personalized experience.

<Callout title="Key Concepts" variant="info">
*   **Memory Layer**: A system that stores and retrieves information for an AI, allowing it to remember past interactions, user preferences, and learned knowledge.
*   **Multi-Level Memory**: Mem0 organizes memory into different categories:
    *   **User Memory**: Information specific to an individual user, remembered across sessions.
    *   **Session Memory**: Context relevant to the current conversation or interaction.
    *   **Agent Memory**: General knowledge or learned behaviors of the AI agent itself.
</Callout>

## Quickstart Guide

You can get started with Mem0 either through its hosted platform for a managed experience or by self-hosting the open-source SDK.

<Steps>
<Step>
### Choose your setup method

Select whether you want to use the managed hosted platform or install the open-source SDK locally.

<Tabs items={["Hosted Platform", "Self-Hosted (Open Source)"]}>
<Tab value="Hosted Platform">
1.  **Sign up**: Visit the [Mem0 Platform](https://app.mem0.ai) and create an account.
2.  **Embed Memory**: Integrate the memory layer into your application using the provided SDKs or API keys. The hosted platform handles updates, analytics, and security automatically.
</Tab>
<Tab value="Self-Hosted (Open Source)">
Install the Mem0 SDK using your preferred package manager:

<Tabs items={["pip", "npm"]}>
<Tab value="pip">
```bash
pip install mem0ai
```
</Tab>
<Tab value="npm">
```bash
npm install mem0ai
```
</Tab>
</Tabs>
</Tab>
</Tabs>
</Step>

<Step>
### Instantiate Memory and Chat

This example demonstrates how to initialize Mem0 and integrate it into a simple chat application using Python. This setup allows your AI to retrieve relevant past memories and create new ones from ongoing conversations.

<Callout title="LLM Requirement" variant="warning">
Mem0 requires an underlying Large Language Model (LLM) to function. The default LLM is `gpt-4.1-nano-2025-04-14` from OpenAI. You can configure Mem0 to work with various other LLMs; refer to the official documentation for a list of [Supported LLMs](https://docs.mem0.ai/components/llms/overview).
</Callout>

```python
from openai import OpenAI
from mem0 import Memory

# Initialize your OpenAI client
openai_client = OpenAI()

# Instantiate the Mem0 Memory layer
memory = Memory()

def chat_with_memories(message: str, user_id: str = "default_user") -> str:
    # 1. Retrieve relevant memories for the current message and user
    relevant_memories = memory.search(query=message, user_id=user_id, limit=3)
    memories_str = "\n".join(f"- {entry['memory']}" for entry in relevant_memories["results"])

    # 2. Prepare the system prompt with retrieved memories
    system_prompt = f"You are a helpful AI. Answer the question based on query and memories.\nUser Memories:\n{memories_str}"
    messages = [{"role": "system", "content": system_prompt}, {"role": "user", "content": message}]

    # 3. Generate the AI's response using the LLM
    response = openai_client.chat.completions.create(model="gpt-4.1-nano-2025-04-14", messages=messages)
    assistant_response = response.choices[0].message.content

    # 4. Create new memories from the conversation turn
    messages.append({"role": "assistant", "content": assistant_response})
    memory.add(messages, user_id=user_id)

    return assistant_response

def main():
    print("Chat with AI (type 'exit' to quit)")
    while True:
        user_input = input("You: ").strip()
        if user_input.lower() == 'exit':
            print("Goodbye!")
            break
        print(f"AI: {chat_with_memories(user_input)}")

if __name__ == "__main__":
    main()
```

<Callout title="Understanding `user_id`" variant="info">
The `user_id` parameter is crucial for personalizing interactions. It allows Mem0 to associate memories with a specific user, ensuring that each user receives tailored responses based on their unique history. In the example, `"default_user"` is used, but in a real application, you would replace this with a unique identifier for each of your users.
</Callout>
</Step>

<Step>
### Run the chat application

To run the example above:

1.  Save the code as a Python file (e.g., `chat_app.py`).
2.  Ensure you have your OpenAI API key configured in your environment or passed to the `OpenAI()` client.
3.  Open your terminal or command prompt.
4.  Navigate to the directory where you saved the file.
5.  Run the command:
    ```bash
    python chat_app.py
    ```
6.  You can now chat with your AI. Type your messages and press Enter. Type `exit` to quit.
</Step>
</Steps>

## Integrations

Mem0 can be integrated with various tools and frameworks to enhance your AI applications:

*   **ChatGPT with Memory**: Experience personalized chat by integrating Mem0. You can see a [Live Demo](https://mem0.dev/demo).
*   **Browser Extension**: Store and retrieve memories across popular AI chat interfaces like ChatGPT, Perplexity, and Claude using the [Chrome Extension](https://chromewebstore.google.com/detail/onihkkbipkfeijkadecaafbgagkhglop?utm_source=item-share-cb).
*   **Langgraph Support**: Build sophisticated customer bots with long-term memory using Langgraph and Mem0. Refer to the [integration guide](https://docs.mem0.ai/integrations/langgraph).
*   **CrewAI Integration**: Tailor the outputs of your CrewAI agents with Mem0's memory capabilities. An [example](https://docs.mem0.ai/integrations/crewai) is available.

## Documentation & Support

For more detailed information, advanced configurations, and troubleshooting, refer to the official resources:

*   **Full Documentation**: [https://docs.mem0.ai](https://docs.mem0.ai)
*   **Community Support**: Join the [Discord server](https://mem0.dev/DiG) or follow on [Twitter](https://x.com/mem0ai).
*   **Contact**: For direct inquiries, you can reach out to founders@mem0.ai.

## Sitemap

See the full [sitemap](https://www.doc0.dev/docs/faa36707-7c28-4f69-a18f-700ff61c704e/llms.txt) for all pages in this wiki.
