Search...
Ctrl KAsk AI
Search...
Navigation
Companion Playbooks
Personalized AI Tutor
Welcome Mem0 Platform Open Source Cookbooks Integrations API Reference Release Notes
Getting Started
Essentials
- Build a Companion with Mem0
- Partition Memories by Entity
- Control Memory Ingestion
- Set Memory Expiration
- Tag and Organize Memories
- Export Stored Memories
- Choose Vector vs Graph Memory
Companion Playbooks
- Interactive Memory Demo
- Build a Node.js Companion
- Personalized AI Tutor
- Smart Travel Assistant
- Research Assistant for YouTube
- Voice-First AI Companion
- Self-Hosted AI Companion
Ops & Automations
- Memory-Powered Support Agent
- Automated Email Intelligence
- Content Creation Workflow
- Multi-Session Research Agent
- Collaborative Task Assistant
Integrations & Platforms
- Memory-Powered Agent SDK
- Memory as OpenAI Tool
- Persistent Mastra Agents
- Healthcare Coach with ADK
- Bedrock with Persistent Memory
- Graph Memory on Neptune
- Search with Personal Context
Frameworks & Multimodal
- ReAct Agents with Memory
- Multi-Agent Collaboration
- Visual Memory Retrieval
- Persistent Eliza Characters
- Browser Extension Memory
- Gemini 3 with Mem0 MCP
- MiroFish Swarm Memory
On this page
You can create a personalized AI Tutor using Mem0. This guide will walk you through the necessary steps and provide the complete code to get you started.
Overview
The Personalized AI Tutor leverages Mem0 to retain information across interactions, enabling a tailored learning experience. By integrating with OpenAI’s GPT-4 model, the tutor can provide detailed and context-aware responses to user queries.
Setup
Before you begin, ensure you have the required dependencies installed. You can install the necessary packages using pip:
pip install openai mem0ai Full Code Example
Below is the complete code to create and interact with a Personalized AI Tutor using Mem0:
import os
from openai import OpenAI
from mem0 import Memory
# Set the OpenAI API key
os.environ['OPENAI_API_KEY'] = 'sk-xxx'
# Initialize the OpenAI client
client = OpenAI()
class PersonalAITutor:
def __init__(self):
"""
Initialize the PersonalAITutor with memory configuration and OpenAI client.
"""
config = {
"vector_store": {
"provider": "qdrant",
"config": {
"host": "localhost",
"port": 6333,
}
},
}
self.memory = Memory.from_config(config)
self.client = client
self.app_id = "app-1"
def ask(self, question, user_id=None):
"""
Ask a question to the AI and store the relevant facts in memory
:param question: The question to ask the AI.
:param user_id: Optional user ID to associate with the memory.
"""
# Start a streaming response request to the AI
response = self.client.responses.create(
model="gpt-4.1-nano-2025-04-14",
instructions="You are a personal AI Tutor.",
input=question,
stream=True
)
# Store the question in memory
self.memory.add(question, user_id=user_id, metadata={"app_id": self.app_id})
# Print the response from the AI in real-time
for event in response:
if event.type == "response.output_text.delta":
print(event.delta, end="")
def get_memories(self, user_id=None):
"""
Retrieve all memories associated with the given user ID.
:param user_id: Optional user ID to filter memories.
:return: List of memories.
"""
return self.memory.get_all(user_id=user_id)
# Instantiate the PersonalAITutor
ai_tutor = PersonalAITutor()
# Define a user ID
user_id = "john_doe"
# Ask a question
ai_tutor.ask("I am learning introduction to CS. What is queue? Briefly explain.", user_id=user_id) Fetching Memories
You can fetch all the memories at any point in time using the following code:
memories = ai_tutor.get_memories(user_id=user_id)
for m in memories['results']:
print(m['memory']) Key Points
- Initialization: The PersonalAITutor class is initialized with the necessary memory configuration and OpenAI client setup
- Asking Questions: The ask method sends a question to the AI and stores the relevant information in memory
- Retrieving Memories: The get_memories method fetches all stored memories associated with a user
Conclusion
As the conversation progresses, Mem0’s memory automatically updates based on the interactions, providing a continuously improving personalized learning experience. This setup ensures that the AI Tutor can offer contextually relevant and accurate responses, enhancing the overall educational process.
Was this page helpful?
YesNo
Build a Node.js Companion\ \ Previous Smart Travel Assistant\ \ Next
Ctrl+I
Assistant
Responses are generated using AI and may contain mistakes.
Suggestions
How do I set up the AI tutor?How do I ask questions to tutor?What memory storage does it use?
