diff --git a/.gitignore b/.gitignore index 77254bff..02e61e39 100644 --- a/.gitignore +++ b/.gitignore @@ -182,4 +182,5 @@ notebooks/*.yaml # local directories for testing eval/ -qdrant_storage/ \ No newline at end of file +qdrant_storage/ +.crossnote \ No newline at end of file diff --git a/README.md b/README.md index 0eec5639..db7dce34 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Mem0 provides a smart, self-improving memory layer for Large Language Models, enabling personalized AI experiences across applications. +> Note: The Mem0 repository now also includes the Embedchain project. We continue to maintain and support Embedchain ❤️. You can find the Embedchain codebase in the [embedchain](https://github.com/mem0ai/mem0/tree/main/embedchain) directory. ## 🚀 Quick Start ### Installation diff --git a/docs/examples/customer-support-agent.mdx b/docs/examples/customer-support-agent.mdx index 58ecf33a..16ff56d8 100644 --- a/docs/examples/customer-support-agent.mdx +++ b/docs/examples/customer-support-agent.mdx @@ -24,6 +24,9 @@ Below is the simplified code to create and interact with a Customer Support AI A from openai import OpenAI from mem0 import Memory +# Set the OpenAI API key +os.environ['OPENAI_API_KEY'] = 'sk-xxx' + class CustomerSupportAIAgent: def __init__(self): """ diff --git a/docs/examples/overview.mdx b/docs/examples/overview.mdx index 934720d3..b4c0a504 100644 --- a/docs/examples/overview.mdx +++ b/docs/examples/overview.mdx @@ -17,12 +17,16 @@ Here are some examples of how Mem0 can be integrated into various applications: ## Example Use Cases - + - Build a Personalized AI Tutor that adapts to student progress and learning preferences. This tutor can offer tailored lessons, remember past interactions, and provide a more effective and engaging educational experience. + Create a Personalized AI Tutor that adapts to student progress and learning preferences. - + + + Build a Personalized AI Travel Assistant that understands your travel preferences and past itineraries. + + - Develop a Personal AI Assistant that can remember user preferences, past interactions, and context to provide personalized and efficient assistance. This assistant can manage tasks, provide reminders, and adapt to individual user needs, enhancing productivity and user experience. + Develop a Personal AI Assistant that remembers user preferences, past interactions, and context to provide personalized and efficient assistance. \ No newline at end of file diff --git a/docs/examples/personal-ai-tutor.mdx b/docs/examples/personal-ai-tutor.mdx index 3ccb4dab..9df825dd 100644 --- a/docs/examples/personal-ai-tutor.mdx +++ b/docs/examples/personal-ai-tutor.mdx @@ -23,6 +23,9 @@ Below is the complete code to create and interact with a Personalized AI Tutor u 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() diff --git a/docs/examples/personal-travel-assistant.mdx b/docs/examples/personal-travel-assistant.mdx new file mode 100644 index 00000000..0b59193f --- /dev/null +++ b/docs/examples/personal-travel-assistant.mdx @@ -0,0 +1,101 @@ +--- +title: Personal AI Travel Assistant +--- +Create a personalized AI Travel Assistant using Mem0. This guide provides step-by-step instructions and the complete code to get you started. + +## Overview + +The Personalized AI Travel Assistant uses Mem0 to store and retrieve information across interactions, enabling a tailored travel planning experience. It integrates with OpenAI's GPT-4 model to provide detailed and context-aware responses to user queries. + +## Setup + +Install the required dependencies using pip: + +```bash +pip install openai mem0ai +``` + +## Full Code Example + +Here's the complete code to create and interact with a Personalized AI Travel Assistant using Mem0: + +```python +import os +from openai import OpenAI +from mem0 import Memory + +# Set the OpenAI API key +os.environ['OPENAI_API_KEY'] = 'sk-xxx' + +class PersonalTravelAssistant: + def __init__(self): + self.client = OpenAI() + self.memory = Memory() + self.messages = [{"role": "system", "content": "You are a personal AI Assistant."}] + + def ask_question(self, question, user_id): + # Fetch previous related memories + previous_memories = self.search_memories(question, user_id=user_id) + prompt = question + if previous_memories: + prompt = f"User input: {question}\n Previous memories: {previous_memories}" + self.messages.append({"role": "user", "content": prompt}) + + # Generate response using GPT-4o + response = self.client.chat.completions.create( + model="gpt-4o", + messages=self.messages + ) + answer = response.choices[0].message.content + self.messages.append({"role": "assistant", "content": answer}) + + # Store the question in memory + self.memory.add(question, user_id=user_id) + return answer + + def get_memories(self, user_id): + memories = self.memory.get_all(user_id=user_id) + return [m['text'] for m in memories] + + def search_memories(self, query, user_id): + memories = self.memory.search(query, user_id=user_id) + return [m['text'] for m in memories] + +# Usage example +user_id = "traveler_123" +ai_assistant = PersonalTravelAssistant() + +def main(): + while True: + question = input("Question: ") + if question.lower() in ['q', 'exit']: + print("Exiting...") + break + + answer = ai_assistant.ask_question(question, user_id=user_id) + print(f"Answer: {answer}") + memories = ai_assistant.get_memories(user_id=user_id) + print("Memories:") + for memory in memories: + print(f"- {memory}") + print("-----") + +if __name__ == "__main__": + main() +``` + +## Key Components + +- **Initialization**: The `PersonalTravelAssistant` class is initialized with the OpenAI client and Mem0 memory setup. +- **Asking Questions**: The `ask_question` method sends a question to the AI, incorporates previous memories, and stores new information. +- **Memory Management**: The `get_memories` and search_memories methods handle retrieval and searching of stored memories. + +## Usage + +1. Set your OpenAI API key in the environment variable. +2. Instantiate the `PersonalTravelAssistant`. +3. Use the `main()` function to interact with the assistant in a loop. + +## Conclusion + +This Personalized AI Travel Assistant leverages Mem0's memory capabilities to provide context-aware responses. As you interact with it, the assistant learns and improves, offering increasingly personalized travel advice and information. \ No newline at end of file diff --git a/docs/images/personal-travel-agent.png b/docs/images/personal-travel-agent.png new file mode 100644 index 00000000..290d205f Binary files /dev/null and b/docs/images/personal-travel-agent.png differ diff --git a/docs/llms.mdx b/docs/llms.mdx index 03367baf..0d0a75e2 100644 --- a/docs/llms.mdx +++ b/docs/llms.mdx @@ -1,5 +1,5 @@ --- -title: 🤖 Large language models (LLMs) +title: 🤖 LLMs --- ## Overview diff --git a/docs/mint.json b/docs/mint.json index 03ca08c1..5aa3f08f 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -54,7 +54,7 @@ ] }, { - "group": "LLMs", + "group": "Integrations", "pages": [ "llms" ] @@ -64,7 +64,8 @@ "pages": [ "examples/overview", "examples/personal-ai-tutor", - "examples/customer-support-agent" + "examples/customer-support-agent", + "examples/personal-travel-assistant" ] } ],