docs: new algorithm migration guides + memory evaluation (#4811)

Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
Co-authored-by: Saket Aryan <saketaryan2002@gmail.com>
This commit is contained in:
Chaithanya Kumar
2026-04-16 17:13:13 +05:30
committed by GitHub
parent 50db9e428d
commit 30469aec17
69 changed files with 2054 additions and 2066 deletions
+3 -3
View File
@@ -50,7 +50,7 @@ local_config = {
"llm": {
"provider": "openai",
"config": {
"model": "gpt-4.1-nano-2025-04-14",
"model": "gpt-5-mini",
"temperature": 0.1,
"max_tokens": 2000,
},
@@ -103,7 +103,7 @@ def demonstrate_sync_memory(local_config, sample_messages, sample_preferences, u
]
for query in search_queries:
results = memory.search(query, user_id=user_id)
results = memory.search(query, filters={"user_id": user_id})
if results and "results" in results:
for j, result in enumerate(results['results']):
@@ -111,7 +111,7 @@ def demonstrate_sync_memory(local_config, sample_messages, sample_preferences, u
else:
print("No results found")
all_memories = memory.get_all(user_id=user_id)
all_memories = memory.get_all(filters={"user_id": user_id})
if all_memories and "results" in all_memories:
print(f"Total memories: {len(all_memories['results'])}")
+2 -2
View File
@@ -37,7 +37,7 @@ from agno.tools.mem0 import Mem0Tools
agent = Agent(
name="Memory Agent",
model=OpenAIChat(id="gpt-4.1-nano-2025-04-14"),
model=OpenAIChat(id="gpt-5-mini"),
tools=[Mem0Tools()],
description="An assistant that remembers and personalizes using Mem0 memory."
)
@@ -126,7 +126,7 @@ def chat_user(
if user_input:
# Search for relevant memories
memories = client.search(user_input, user_id=user_id)
memories = client.search(user_input, filters={"user_id": user_id})
memory_context = "\n".join(f"- {m['memory']}" for m in memories['results'])
# Construct the prompt
+2 -2
View File
@@ -72,7 +72,7 @@ Create a function to get context-aware responses based on user's question and pr
```python
def get_context_aware_response(question):
relevant_memories = memory_client.search(question, user_id=USER_ID)
relevant_memories = memory_client.search(question, filters={"user_id": USER_ID})
context = "\n".join([m["memory"] for m in relevant_memories.get('results', [])])
prompt = f"""Answer the user question considering the previous interactions:
@@ -104,7 +104,7 @@ manager = ConversableAgent(
)
def escalate_to_manager(question):
relevant_memories = memory_client.search(question, user_id=USER_ID)
relevant_memories = memory_client.search(question, filters={"user_id": USER_ID})
context = "\n".join([m["memory"] for m in relevant_memories.get('results', [])])
prompt = f"""
+2 -5
View File
@@ -107,10 +107,10 @@ messages = [
m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"})
# Search for memory
relevant = m.search("What kind of movies does Alice like?", user_id="alice")
relevant = m.search("What kind of movies does Alice like?", filters={"user_id": "alice"})
# Retrieve all user memories
all_memories = m.get_all(user_id="alice")
all_memories = m.get_all(filters={"user_id": "alice"})
```
## Key Features
@@ -125,8 +125,5 @@ all_memories = m.get_all(user_id="alice")
<Card title="AWS Bedrock Cookbook" icon="aws" href="/cookbooks/integrations/aws-bedrock">
Complete guide to using Bedrock with Mem0
</Card>
<Card title="Neptune Analytics Cookbook" icon="database" href="/cookbooks/integrations/neptune-analytics">
Build graph memory with AWS Neptune
</Card>
</CardGroup>
+1 -1
View File
@@ -56,7 +56,7 @@ config = {
"llm": {
"provider": "openai",
"config": {
"model": "gpt-4.1-nano-2025-04-14",
"model": "gpt-5-mini",
"temperature": 0.0,
"api_key": keywordsai_api_key,
"openai_base_url": base_url,
+2 -2
View File
@@ -40,7 +40,7 @@ load_dotenv()
# os.environ["MEM0_API_KEY"] = "your-mem0-api-key"
# Initialize LangChain and Mem0
llm = ChatOpenAI(model="gpt-4.1-nano-2025-04-14")
llm = ChatOpenAI(model="gpt-5-mini")
mem0 = MemoryClient()
```
@@ -66,7 +66,7 @@ Create functions to handle context retrieval, response generation, and addition
def retrieve_context(query: str, user_id: str) -> List[Dict]:
"""Retrieve relevant context from Mem0"""
try:
memories = mem0.search(query, user_id=user_id)
memories = mem0.search(query, filters={"user_id": user_id})
memory_list = memories['results']
serialized_memories = ' '.join([mem["memory"] for mem in memory_list])
+1 -1
View File
@@ -68,7 +68,7 @@ def chatbot(state: State):
try:
# Retrieve relevant memories
memories = mem0.search(messages[-1].content, user_id=user_id)
memories = mem0.search(messages[-1].content, filters={"user_id": user_id})
# Handle dict response format
memory_list = memories['results']
+1 -1
View File
@@ -148,7 +148,7 @@ async def entrypoint(ctx: JobContext):
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(model="gpt-4.1-nano-2025-04-14"),
llm=openai.LLM(model="gpt-5-mini"),
tts=openai.TTS(voice="ash",),
turn_detection=EnglishModel(),
vad=silero.VAD.load(),
+2 -2
View File
@@ -83,7 +83,7 @@ config = {
"llm": {
"provider": "openai",
"config": {
"model": "gpt-4.1-nano-2025-04-14",
"model": "gpt-5-mini",
"temperature": 0.2,
"max_tokens": 2000,
},
@@ -116,7 +116,7 @@ from dotenv import load_dotenv
load_dotenv()
# os.environ["OPENAI_API_KEY"] = "<your-openai-api-key>"
llm = OpenAI(model="gpt-4.1-nano-2025-04-14")
llm = OpenAI(model="gpt-5-mini")
```
### SimpleChatEngine
+5 -5
View File
@@ -45,7 +45,7 @@ mem0 = MemoryClient()
@function_tool
def search_memory(query: str, user_id: str) -> str:
"""Search through past conversations and memories"""
memories = mem0.search(query, user_id=user_id, top_k=3)
memories = mem0.search(query, filters={"user_id": user_id}, top_k=3)
if memories and memories.get('results'):
return "\n".join([f"- {mem['memory']}" for mem in memories['results']])
return "No relevant memories found."
@@ -64,7 +64,7 @@ agent = Agent(
Use the save_memory tool to store important information about the user.
Always personalize your responses based on available memory.""",
tools=[search_memory, save_memory],
model="gpt-4.1-nano-2025-04-14"
model="gpt-5-mini"
)
def chat_with_agent(user_input: str, user_id: str) -> str:
@@ -115,7 +115,7 @@ travel_agent = Agent(
understand the user's travel preferences and history before making recommendations.
After providing your response, use store_conversation to save important details.""",
tools=[search_memory, save_memory],
model="gpt-4.1-nano-2025-04-14"
model="gpt-5-mini"
)
health_agent = Agent(
@@ -124,7 +124,7 @@ health_agent = Agent(
understand the user's health goals and dietary preferences.
After providing advice, use store_conversation to save relevant information.""",
tools=[search_memory, save_memory],
model="gpt-4.1-nano-2025-04-14"
model="gpt-5-mini"
)
# Triage agent with handoffs
@@ -135,7 +135,7 @@ triage_agent = Agent(
For health-related questions (fitness, diet, wellness, exercise), hand off to the Health Advisor.
For general questions, handle them directly using available tools.""",
handoffs=[travel_agent, health_agent],
model="gpt-4.1-nano-2025-04-14"
model="gpt-5-mini"
)
def chat_with_handoffs(user_input: str, user_id: str) -> str:
-1
View File
@@ -147,7 +147,6 @@ openclaw mem0 stats
| `apiKey` | `string` | — | **Required.** Mem0 API key (supports `${MEM0_API_KEY}`) |
| `orgId` | `string` | — | Organization ID |
| `projectId` | `string` | — | Project ID |
| `enableGraph` | `boolean` | `false` | Entity graph for relationships |
| `customInstructions` | `string` | *(built-in)* | Extraction rules — what to store, how to format |
| `customCategories` | `object` | *(12 defaults)* | Category name → description map for tagging |
+1 -19
View File
@@ -78,7 +78,7 @@ npm install @mem0/vercel-ai-provider
> `getMemories` will return raw memories in the form of an array of objects, while `retrieveMemories` will return a response in string format with a system prompt ingested with the retrieved memories.
> `getMemories` is an object with two keys: `results` and `relations` if `enable_graph` is enabled. Otherwise, it will return an array of objects.
> `getMemories` returns an array of memory objects.
### 1. Basic Text Generation with Memory Context
@@ -270,24 +270,6 @@ main();
> **Note**: File support is available with providers that support multimodal capabilities like Google's Gemini models. The example shows how to process PDF files, but you can also work with images, text files, and other supported formats.
## Graph Memory
Mem0 AI SDK now supports Graph Memory. You can enable it by setting `enable_graph` to `true` in the `mem0Config` object.
```typescript
const mem0 = createMem0({
mem0Config: { enable_graph: true },
});
```
You can also pass `enable_graph` in the standalone functions. This includes `getMemories`, `retrieveMemories`, and `addMemories`.
```typescript
const memories = await getMemories(prompt, { user_id: "borat", mem0ApiKey: "m0-xxx", enable_graph: true });
```
The `getMemories` function will return an object with two keys: `results` and `relations`, if `enable_graph` is set to `true`. Otherwise, it will return an array of objects.
## Supported LLM Providers
| Provider | Configuration Value |