Getting Started
Core Features
How-To Guides
Configuration
Troubleshooting
Integrations
Mem0 ("mem-zero") provides an intelligent memory layer designed to enhance AI assistants and agents. It allows your AI to remember past interactions, user preferences, and adapt its behavior over time. This means your AI can provide more personalized and consistent experiences, making it ideal for applications like customer support chatbots, personal AI assistants, and autonomous systems that need to learn from ongoing interactions.
This memory layer helps your AI maintain context across conversations and sessions, leading to more natural and effective interactions without needing to repeat information.
These different levels of memory ensure that your AI can recall the right information at the right time, whether it's a long-term user preference or a detail from the current conversation.
You can use Mem0 either through its hosted platform or by self-hosting the open-source package.
For quick setup with automatic updates, analytics, and enterprise security:
Once Mem0 is set up, you can integrate it into your AI application. Mem0 requires an external Large Language Model (LLM) to function, such as OpenAI's models.
Mem0 is designed to work with various LLMs. While gpt-4.1-nano-2025-04-14 from OpenAI is often used as a default in examples, you can configure it to use other supported LLMs.
Here's a step-by-step guide to using Mem0 to add memory to a simple chat application:
First, you need to initialize the Mem0 Memory object. This sets up the connection to your memory layer. You'll also need to set up your LLM client (e.g., OpenAI).
from openai import OpenAI
from mem0 import Memory
openai_client = OpenAI()
memory = Memory()Create a function that will handle user input, retrieve memories, generate a response, and then store new memories.
Mem0 can be used in various scenarios to make AI more intelligent and personalized:
def chat_with_memories(message: str, user_id: str = "default_user") -> str:
# ... (rest of the code below)Before generating a response, ask Mem0 to search for memories that are relevant to the current user's message. This helps the AI understand the context.
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"])query: The user's current message.user_id: Identifies the user, allowing Mem0 to retrieve personalized memories.limit: Specifies the maximum number of relevant memories to retrieve.Use the retrieved memories to inform your LLM's response. The memories are typically included in the system prompt to provide context.
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}]
response = openai_client.chat.completions.create(model="gpt-4.1-nano-2025-04-14", messages=messages)
assistant_response = response.choices[0].message.contentAfter the AI responds, add the entire conversation (user message and AI response) back to Mem0. This allows Mem0 to learn from the interaction and store new information for future use.
messages.append({"role": "assistant", "content": assistant_response})
memory.add(messages, user_id=user_id)messages: The list of messages in the current turn of the conversation.user_id: Associates these new memories with the specific user.Finally, set up a simple loop to continuously chat with your memory-enhanced AI.
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()