Vercel AI SDK
The Mem0 AI SDK Provider is a library developed by Mem0 to integrate with the Vercel AI SDK. This library brings enhanced AI interaction capabilities to your applications by introducing persistent memory functionality.
🎉 Exciting news! Mem0 AI SDK now supports OpenAI, Anthropic, Cohere, and Groq providers.
Overview
In this guide, we’ll create a Travel Agent AI that:
- 🧠 Offers persistent memory storage for conversational AI
- 🔄 Enables smooth integration with the Vercel AI SDK
- 🚀 Ensures compatibility with multiple LLM providers
- 📝 Supports structured message formats for clarity
- ⚡ Facilitates streaming response capabilities
Setup and Configuration
Install the SDK provider using npm:
Getting Started
Setting Up Mem0
-
Get your Mem0 API Key from the Mem0 Dashboard.
-
Initialize the Mem0 Client in your application:
Note: The
openai
provider is set as default. Consider usingMEM0_API_KEY
andOPENAI_API_KEY
as environment variables for security. -
Add Memories to Enhance Context:
Standalone Features:
Note: For standalone features, such as
addMemories
andretrieveMemories
, you must either setMEM0_API_KEY
as an environment variable or pass it directly in the function call.
1. Basic Text Generation with Memory Context
2. Combining OpenAI Provider with Memory Utils
3. Structured Message Format with Memory
3. Streaming Responses with Memory Context
Key Features
createMem0()
: Initializes a new Mem0 provider instance.retrieveMemories()
: Retrieves memory context for prompts.addMemories()
: Adds user memories to enhance contextual responses.
Best Practices
-
User Identification: Use a unique
user_id
for consistent memory retrieval. -
Memory Cleanup: Regularly clean up unused memory data.
Note: We also have support for
agent_id
,app_id
, andrun_id
. Refer Docs.
Conclusion
Mem0’s Vercel AI SDK enables the creation of intelligent, context-aware applications with persistent memory and seamless integration.
Help
- For more details on Vercel AI SDK, visit the Vercel AI SDK documentation.
- For Mem0 documentation, refer to the Mem0 Platform.
- If you need further assistance, please feel free to reach out to us through following methods: