Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d6b7c1d67 | |||
| b44ce4dcc3 | |||
| e9c930c430 | |||
| 4b39d01ccb | |||
| 49061718bd |
@@ -7,6 +7,21 @@ mode: "wide"
|
||||
<Tabs>
|
||||
<Tab title="Python">
|
||||
|
||||
<Update label="2026-06-27" description="v2.0.10">
|
||||
|
||||
**New Features:**
|
||||
- **Client:** Expose `expiration_date` on `MemoryClient.update()` and `AsyncMemoryClient.update()` — callers can now set or clear a memory's expiration date; `None` is preserved and forwarded to the API ([#5874](https://github.com/mem0ai/mem0/pull/5874))
|
||||
|
||||
**Bug Fixes:**
|
||||
- **Memory (OSS):** Apply `remove_code_blocks()` to the LangChain path in async `_create_procedural_memory` so code fences are stripped consistently ([#5711](https://github.com/mem0ai/mem0/pull/5711))
|
||||
- **Rerankers:** Score HuggingFace cross-encoder results with per-document sigmoid instead of set-relative min-max, preventing a single low-score document from collapsing all relevance scores to zero ([#5715](https://github.com/mem0ai/mem0/pull/5715))
|
||||
- **Core:** Validate and trim entity IDs (`user_id`, `agent_id`, `run_id`) in `delete_all()` for both sync and async `Memory` ([#5735](https://github.com/mem0ai/mem0/pull/5735))
|
||||
- **Vector Stores:** Use `.get()` for `hash` and `created_at` in the Redis `insert()` and `update()` paths so entity payloads that omit those fields no longer raise `KeyError` ([#5709](https://github.com/mem0ai/mem0/pull/5709))
|
||||
- **Memory:** Fix scale-threshold notices not firing for Redis and search-engine backends by resolving `col_info()` signature differences and adding `num_docs` to the count-extraction lookup ([#5687](https://github.com/mem0ai/mem0/pull/5687))
|
||||
- **Vector Stores:** Escape special characters in Valkey FT.SEARCH tag filter values to prevent wildcard and operator injection through tenant-isolation filters ([#5750](https://github.com/mem0ai/mem0/pull/5750))
|
||||
|
||||
</Update>
|
||||
|
||||
<Update label="2026-06-24" description="v2.0.9">
|
||||
|
||||
**Bug Fixes:**
|
||||
@@ -1070,6 +1085,23 @@ See the [OSS v2 to v3 migration guide](https://docs.mem0.ai/migration/oss-v2-to-
|
||||
|
||||
<Tab title="TypeScript">
|
||||
|
||||
<Update label="2026-06-27" description="v3.0.12">
|
||||
|
||||
**New Features:**
|
||||
- **Client:** Add `expirationDate` to `AddMemoryOptions`, `update()`, and the `Memory` interface; add `showExpired` to `SearchMemoryOptions` and `GetAllMemoryOptions` ([#5874](https://github.com/mem0ai/mem0/pull/5874))
|
||||
- **LLMs:** Add `MiniMaxLLM` provider backed by the OpenAI-compatible MiniMax API (`api.minimax.io/v1`, default model `MiniMax-M2.7`) ([#5858](https://github.com/mem0ai/mem0/pull/5858))
|
||||
- **LLMs:** Add `LiteLLM` provider for routing requests through a local or hosted LiteLLM proxy ([#5830](https://github.com/mem0ai/mem0/pull/5830))
|
||||
- **Vector Stores:** Add `connectionString` and `ssl` options to the PGVector config, allowing connection via URI instead of individual host/user/password/port fields ([#5789](https://github.com/mem0ai/mem0/pull/5789))
|
||||
|
||||
**Bug Fixes:**
|
||||
- **Memory (OSS):** Validate and trim entity IDs (`userId`, `agentId`, `runId`) in `deleteAll()` via `validateAndTrimEntityId` ([#5735](https://github.com/mem0ai/mem0/pull/5735))
|
||||
- **Vector Stores:** Use nullish coalescing for `hash` and timestamps in the Redis `insert()` and `update()` paths so entity payloads that omit those fields no longer crash ([#5860](https://github.com/mem0ai/mem0/pull/5860))
|
||||
|
||||
**Security:**
|
||||
- **Dependencies:** Bump `undici` to `>=6.27.0` via pnpm override to remediate CVE-2026-12151 ([#5861](https://github.com/mem0ai/mem0/pull/5861))
|
||||
|
||||
</Update>
|
||||
|
||||
<Update label="2026-06-24" description="v3.0.11">
|
||||
|
||||
**Bug Fixes:**
|
||||
|
||||
@@ -59,5 +59,9 @@ Here are the parameters available for configuring AWS Bedrock embedder:
|
||||
| Parameter | Description | Default Value |
|
||||
| --- | --- | --- |
|
||||
| `model` | The name of the embedding model to use | `amazon.titan-embed-text-v1` |
|
||||
| `aws_region` | AWS region for the Bedrock client | `us-west-2` |
|
||||
| `aws_access_key_id` | AWS access key ID for authentication | `None` |
|
||||
| `aws_secret_access_key` | AWS secret access key for authentication | `None` |
|
||||
| `aws_session_token` | AWS session token for temporary credentials | `None` |
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
@@ -67,14 +67,15 @@ Here are the parameters available for configuring Gemini embedder:
|
||||
| Parameter | Description | Default Value |
|
||||
| ---------------- | ------------------------------------ | ----------------------- |
|
||||
| `model` | The name of the embedding model to use| `models/gemini-embedding-001` |
|
||||
| `embedding_dims` | Dimensions of the embedding model | `1536` |
|
||||
| `embedding_dims` | Dimensions of the embedding model | `768` |
|
||||
| `api_key` | The Google API key | `None` |
|
||||
| `output_dimensionality` | Output dimensionality for the embedding model (Gemini-specific; used when `embedding_dims` is not set) | `None` |
|
||||
</Tab>
|
||||
<Tab title="TypeScript">
|
||||
| Parameter | Description | Default Value |
|
||||
| ----------------- | --------------------------------------------- | -------------------------- |
|
||||
| `model` | The name of the embedding model to use | `gemini-embedding-001` |
|
||||
| `embeddingDims` | Dimensions of the embedding model | `1536` |
|
||||
| `embeddingDims` | Dimensions of the embedding model. When not set, uses the model's native output dimensionality (3072 for `gemini-embedding-001`; MRL truncation to 768, 1536, or 3072 is supported) | `None` |
|
||||
| `apiKey` | Google API key | `None` |
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
@@ -16,7 +16,7 @@ config = {
|
||||
"embedder": {
|
||||
"provider": "lmstudio",
|
||||
"config": {
|
||||
"model": "nomic-embed-text-v1.5-GGUF/nomic-embed-text-v1.5.f16.gguf"
|
||||
"model": "nomic-ai/nomic-embed-text-v1.5-GGUF"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,6 @@ Here are the parameters available for configuring LM Studio embedder:
|
||||
|
||||
| Parameter | Description | Default Value |
|
||||
| --- | --- | --- |
|
||||
| `model` | The name of the LM Studio model to use | `nomic-embed-text-v1.5-GGUF/nomic-embed-text-v1.5.f16.gguf` |
|
||||
| `model` | The name of the LM Studio model to use | `nomic-ai/nomic-embed-text-v1.5-GGUF` |
|
||||
| `embedding_dims` | Dimensions of the embedding model | `1536` |
|
||||
| `lmstudio_base_url` | Base URL for LM Studio connection | `http://localhost:1234/v1` |
|
||||
@@ -10,7 +10,7 @@ Mem0 offers support for various embedding models, allowing users to choose the o
|
||||
See the list of supported embedders below.
|
||||
|
||||
<Note>
|
||||
The following embedders are supported in the Python implementation. The TypeScript implementation currently only supports OpenAI.
|
||||
All embedders listed below are supported in the Python implementation. The TypeScript implementation supports: **OpenAI**, **Azure OpenAI**, **Google AI**, **Langchain**, **LM Studio**, and **Ollama**.
|
||||
</Note>
|
||||
|
||||
<CardGroup cols={4}>
|
||||
@@ -24,6 +24,7 @@ See the list of supported embedders below.
|
||||
<Card title="LM Studio" href="/components/embedders/models/lmstudio"></Card>
|
||||
<Card title="Langchain" href="/components/embedders/models/langchain"></Card>
|
||||
<Card title="AWS Bedrock" href="/components/embedders/models/aws_bedrock"></Card>
|
||||
<Card title="FastEmbed" href="/components/embedders/models/fastembed"></Card>
|
||||
</CardGroup>
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -98,7 +98,7 @@ Here's a comprehensive list of all parameters that can be used across different
|
||||
| `max_tokens` | Tokens to generate | All |
|
||||
| `top_p` | Probability threshold for nucleus sampling | All |
|
||||
| `top_k` | Number of highest probability tokens to keep | All |
|
||||
| `http_client_proxies`| Allow proxy server settings | AzureOpenAI |
|
||||
| `http_client_proxies`| Allow proxy server settings | All |
|
||||
| `models` | List of models | Openrouter |
|
||||
| `route` | Routing strategy | Openrouter |
|
||||
| `openrouter_base_url`| Base URL for Openrouter API | Openrouter |
|
||||
@@ -110,7 +110,7 @@ Here's a comprehensive list of all parameters that can be used across different
|
||||
| `deepseek_base_url` | Base URL for DeepSeek API | DeepSeek |
|
||||
| `xai_base_url` | Base URL for XAI API | XAI |
|
||||
| `sarvam_base_url` | Base URL for Sarvam API | Sarvam |
|
||||
| `reasoning_effort` | Reasoning level (low, medium, high) | Sarvam |
|
||||
| `reasoning_effort` | Reasoning level (low, medium, high) | All |
|
||||
| `frequency_penalty` | Penalize frequent tokens (-2.0 to 2.0) | Sarvam |
|
||||
| `presence_penalty` | Penalize existing tokens (-2.0 to 2.0) | Sarvam |
|
||||
| `seed` | Seed for deterministic sampling | Sarvam |
|
||||
|
||||
@@ -20,7 +20,7 @@ config = {
|
||||
"llm": {
|
||||
"provider": "anthropic",
|
||||
"config": {
|
||||
"model": "claude-sonnet-4-20250514",
|
||||
"model": "claude-sonnet-4-6",
|
||||
"temperature": 0.1,
|
||||
"max_tokens": 2000,
|
||||
}
|
||||
@@ -45,7 +45,7 @@ const config = {
|
||||
provider: 'anthropic',
|
||||
config: {
|
||||
apiKey: process.env.ANTHROPIC_API_KEY || '',
|
||||
model: 'claude-sonnet-4-20250514',
|
||||
model: 'claude-sonnet-4-6',
|
||||
temperature: 0.1,
|
||||
maxTokens: 2000,
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ description: "Configure AWS Bedrock as an LLM provider in Mem0 with IAM authenti
|
||||
### Setup
|
||||
- Before using the AWS Bedrock LLM, make sure you have the appropriate model access from [Bedrock Console](https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess).
|
||||
- You will also need to authenticate the `boto3` client by using a method in the [AWS documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#configuring-credentials)
|
||||
- You will have to export `AWS_REGION`, `AWS_ACCESS_KEY`, and `AWS_SECRET_ACCESS_KEY` to set environment variables.
|
||||
- You will have to export `AWS_REGION`, `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY` to set environment variables.
|
||||
|
||||
### Usage
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ config = {
|
||||
"llm": {
|
||||
"provider": "groq",
|
||||
"config": {
|
||||
"model": "mixtral-8x7b-32768",
|
||||
"model": "llama-3.3-70b-versatile",
|
||||
"temperature": 0.1,
|
||||
"max_tokens": 2000,
|
||||
}
|
||||
@@ -46,7 +46,7 @@ const config = {
|
||||
provider: 'groq',
|
||||
config: {
|
||||
apiKey: process.env.GROQ_API_KEY || '',
|
||||
model: 'mixtral-8x7b-32768',
|
||||
model: 'llama3-70b-8192',
|
||||
temperature: 0.1,
|
||||
maxTokens: 1000,
|
||||
},
|
||||
|
||||
@@ -20,7 +20,7 @@ config = {
|
||||
"llm": {
|
||||
"provider": "xai",
|
||||
"config": {
|
||||
"model": "grok-3-beta",
|
||||
"model": "grok-4.3",
|
||||
"temperature": 0.1,
|
||||
"max_tokens": 2000,
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ For a comprehensive list of available parameters for llm configuration, please r
|
||||
See the list of supported LLMs below.
|
||||
|
||||
<Note>
|
||||
All LLMs are supported in Python. The following LLMs are also supported in TypeScript: **OpenAI**, **Anthropic**, and **Groq**.
|
||||
All LLMs are supported in Python. The following LLMs are also supported in TypeScript: **OpenAI**, **Anthropic**, **Groq**, **Azure OpenAI**, **DeepSeek**, **Google AI**, **Langchain**, **LM Studio**, **Mistral AI**, and **Ollama**.
|
||||
</Note>
|
||||
|
||||
<CardGroup cols={4}>
|
||||
|
||||
@@ -31,7 +31,7 @@ const openaiClient = new OpenAI();
|
||||
const memory = new Memory();
|
||||
|
||||
async function chatWithMemories(message, userId = "default_user") {
|
||||
const relevantMemories = await memory.search(message, { userId: userId });
|
||||
const relevantMemories = await memory.search(message, { filters: { user_id: userId } });
|
||||
|
||||
const memoriesStr = relevantMemories.results
|
||||
.map(entry => `- ${entry.memory}`)
|
||||
|
||||
@@ -289,8 +289,7 @@ print([m["memory"] for m in constraints["results"]])
|
||||
```python
|
||||
constraints = memory.search(
|
||||
query="injury concerns",
|
||||
user_id="max",
|
||||
filters={"memory_bucket": {"in": ["constraints"]}},
|
||||
filters={"user_id": "max", "memory_bucket": {"in": ["constraints"]}},
|
||||
threshold=0.0 # optional: widen recall for short phrases
|
||||
)
|
||||
print([m["memory"] for m in constraints["results"]])
|
||||
@@ -736,8 +735,7 @@ mem0_client.add(messages, user_id="max", run_id="nyc-2025")
|
||||
# Retrieve only Boston memories
|
||||
boston_memories = mem0_client.search(
|
||||
"training plan",
|
||||
user_id="max",
|
||||
run_id="boston-2025"
|
||||
filters={"user_id": "max", "run_id": "boston-2025"}
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
@@ -749,8 +747,7 @@ memory.add(messages, user_id="max", run_id="nyc-2025")
|
||||
# Retrieve only Boston memories
|
||||
boston_memories = memory.search(
|
||||
"training plan",
|
||||
user_id="max",
|
||||
run_id="boston-2025",
|
||||
filters={"user_id": "max", "run_id": "boston-2025"},
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
@@ -846,8 +843,7 @@ Prioritize recent training over old data:
|
||||
```python
|
||||
recent = mem0_client.search(
|
||||
"training progress",
|
||||
user_id="max",
|
||||
filters={"created_at": {"gte": "2025-10-01"}}
|
||||
filters={"user_id": "max", "created_at": {"gte": "2025-10-01"}}
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
@@ -866,8 +862,7 @@ memory.add(
|
||||
cutoff = int(datetime(2025, 10, 1).timestamp())
|
||||
recent = memory.search(
|
||||
"training progress",
|
||||
user_id="max",
|
||||
filters={"logged_epoch": {"gte": cutoff}},
|
||||
filters={"user_id": "max", "logged_epoch": {"gte": cutoff}},
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
@@ -889,8 +884,7 @@ mem0_client.add(
|
||||
# Later, find all speed workouts
|
||||
speed_sessions = mem0_client.search(
|
||||
"speed work",
|
||||
user_id="max",
|
||||
filters={"metadata": {"workout_type": "speed"}}
|
||||
filters={"user_id": "max", "metadata": {"workout_type": "speed"}}
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
@@ -905,8 +899,7 @@ memory.add(
|
||||
# Later, find all speed workouts
|
||||
speed_sessions = memory.search(
|
||||
"speed work",
|
||||
user_id="max",
|
||||
filters={"workout_type": "speed"},
|
||||
filters={"user_id": "max", "workout_type": "speed"},
|
||||
)
|
||||
```
|
||||
</Tab>
|
||||
|
||||
@@ -58,6 +58,7 @@ Use `get_all()` with filters to retrieve everything for a specific user:
|
||||
```python
|
||||
dev_memories = client.get_all(
|
||||
filters={"user_id": "dev"},
|
||||
page=1,
|
||||
page_size=50
|
||||
)
|
||||
|
||||
|
||||
@@ -211,8 +211,8 @@ class MultiAgentLearningSystem:
|
||||
try:
|
||||
# Search memory for learning patterns
|
||||
memories = self.memory.search(
|
||||
user_id=self.student_id,
|
||||
query="learning machine learning"
|
||||
query="learning machine learning",
|
||||
filters={"user_id": self.student_id}
|
||||
)
|
||||
|
||||
if memories and memories.get('results'):
|
||||
|
||||
@@ -50,7 +50,7 @@ load_dotenv()
|
||||
USER_ID = "Alex"
|
||||
|
||||
# Initialize Mem0 client
|
||||
mem0 = MemoryClient()
|
||||
mem0_client = MemoryClient()
|
||||
```
|
||||
|
||||
## Define Memory Tools
|
||||
@@ -76,7 +76,7 @@ def retrieve_patient_info(query: str) -> dict:
|
||||
# Search Mem0
|
||||
results = mem0_client.search(
|
||||
query,
|
||||
user_id=USER_ID,
|
||||
filters={"user_id": USER_ID},
|
||||
top_k=5,
|
||||
threshold=0.7 # Higher threshold for more relevant results
|
||||
)
|
||||
|
||||
@@ -53,34 +53,12 @@ async function addUserPreferences() {
|
||||
await addUserPreferences();
|
||||
```
|
||||
|
||||
```json Output (Memories)
|
||||
[
|
||||
{
|
||||
"id": "ff9f3367-9e83-415d-b9c5-dc8befd9a4b4",
|
||||
"data": { "memory": "Loves BMW, Audi, and Porsche" },
|
||||
"event": "ADD"
|
||||
},
|
||||
{
|
||||
"id": "04172ce6-3d7b-45a3-b4a1-ee9798593cb4",
|
||||
"data": { "memory": "Hates Mercedes" },
|
||||
"event": "ADD"
|
||||
},
|
||||
{
|
||||
"id": "db363a5d-d258-4953-9e4c-777c120de34d",
|
||||
"data": { "memory": "Loves red cars and maroon cars" },
|
||||
"event": "ADD"
|
||||
},
|
||||
{
|
||||
"id": "5519aaad-a2ac-4c0d-81d7-0d55c6ecdba8",
|
||||
"data": { "memory": "Has a budget of 120K to 150K USD" },
|
||||
"event": "ADD"
|
||||
},
|
||||
{
|
||||
"id": "523b7693-7344-4563-922f-5db08edc8634",
|
||||
"data": { "memory": "Likes Audi the most" },
|
||||
"event": "ADD"
|
||||
}
|
||||
]
|
||||
```json Output
|
||||
{
|
||||
"message": "Memory processing has been queued for background execution",
|
||||
"status": "PENDING",
|
||||
"event_id": "9f8c2b1a-4e7d-4c3a-9b21-1a2b3c4d5e6f"
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
## Retrieving Memories
|
||||
@@ -88,7 +66,7 @@ await addUserPreferences();
|
||||
Search for relevant memories based on the current user input:
|
||||
|
||||
```javascript
|
||||
const relevantMemories = await mem0Client.search(userInput, { userId: USER_ID });
|
||||
const relevantMemories = await mem0Client.search(userInput, { filters: { user_id: USER_ID } });
|
||||
```
|
||||
|
||||
## Structured Responses with Zod
|
||||
@@ -194,7 +172,7 @@ async function main(memory = false) {
|
||||
// Search for relevant memories
|
||||
let relevantMemories = []
|
||||
if (memory) {
|
||||
relevantMemories = await mem0Client.search(input, { userId: USER_ID });
|
||||
relevantMemories = await mem0Client.search(input, { filters: { user_id: USER_ID } });
|
||||
}
|
||||
|
||||
const response = await openAIClient.responses.create({
|
||||
|
||||
@@ -4,8 +4,6 @@ description: "Blend Tavily's realtime results with personal context stored in Me
|
||||
---
|
||||
|
||||
|
||||
<Snippet file="security-compliance.mdx" />
|
||||
|
||||
Imagine asking a search assistant for "coffee shops nearby" and instead of generic results, it shows remote-work-friendly cafes with great WiFi in your city because it remembers you mentioned working remotely before. Or when you search for "lunchbox ideas for kids" it knows you have a 7-year-old daughter and recommends peanut-free options that align with her allergy.
|
||||
|
||||
That's what we are going to build today, a Personalized Search Assistant powered by Mem0 for memory and [Tavily](https://tavily.com) for real-time search.
|
||||
|
||||
@@ -217,8 +217,7 @@ def apply_writing_style(original_content):
|
||||
|
||||
results = memory.search(
|
||||
query="What are my writing style preferences?",
|
||||
user_id=USER_ID,
|
||||
run_id=RUN_ID,
|
||||
filters={"user_id": USER_ID, "run_id": RUN_ID},
|
||||
)
|
||||
|
||||
if not results:
|
||||
|
||||
@@ -314,18 +314,16 @@ class EmailProcessor:
|
||||
user_id (str): User identifier
|
||||
sender (str, optional): Filter by sender email address
|
||||
"""
|
||||
# In OSS, user_id is an explicit parameter (not inside filters)
|
||||
if not sender:
|
||||
results = self.memory.search(
|
||||
query=query,
|
||||
user_id=user_id,
|
||||
filters={"memory_category": "email"},
|
||||
filters={"user_id": user_id, "memory_category": "email"},
|
||||
)
|
||||
else:
|
||||
results = self.memory.search(
|
||||
query=query,
|
||||
user_id=user_id,
|
||||
filters={
|
||||
"user_id": user_id,
|
||||
"AND": [
|
||||
{"memory_category": "email"},
|
||||
{"sender": sender},
|
||||
@@ -343,10 +341,9 @@ class EmailProcessor:
|
||||
subject (str): Email subject to match
|
||||
user_id (str): User identifier
|
||||
"""
|
||||
# In OSS, user_id is an explicit parameter
|
||||
thread = self.memory.get_all(
|
||||
user_id=user_id,
|
||||
filters={
|
||||
"user_id": user_id,
|
||||
"AND": [
|
||||
{"memory_category": "email"},
|
||||
{"subject": {"icontains": subject}},
|
||||
|
||||
@@ -57,7 +57,7 @@ class CustomerSupportAIAgent:
|
||||
"""
|
||||
# Start a streaming chat completion request to the AI
|
||||
stream = self.client.chat.completions.create(
|
||||
model="gpt-4",
|
||||
model="gpt-5-mini",
|
||||
stream=True,
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a customer support AI agent."},
|
||||
|
||||
@@ -238,11 +238,11 @@ client.search("preferences", filters={
|
||||
- **Use natural language**: Mem0 understands intent, so describe what you're looking for naturally
|
||||
- **Scope with user ID**: Always provide `user_id` to scope search to relevant memories
|
||||
- **Platform API**: Use `filters={"user_id": "alice"}`
|
||||
- **OSS**: Use `user_id="alice"` as parameter
|
||||
- **OSS**: Use `filters={"user_id": "alice"}` (passing `user_id` as a top-level kwarg raises `ValueError` in v3)
|
||||
- **Combine filters**: Use AND/OR logic to create precise queries (Platform)
|
||||
- **Consider wildcard filters**: Use wildcard filters (e.g., `run_id: "*"`) for broader matches
|
||||
- **Tune parameters**: Adjust `top_k` for result count, `threshold` for relevance cutoff
|
||||
- **Enable reranking**: Use `rerank=True` (default) when you have a reranker configured
|
||||
- **Enable reranking**: Use `rerank=True` (default is `False`) when you have a reranker configured
|
||||
|
||||
<Callout type="tip" icon="plug">
|
||||
**MCP Alternative**: With <Link href="/platform/mem0-mcp">Mem0 MCP</Link>, AI agents can search their own memories proactively when needed.
|
||||
|
||||
@@ -60,7 +60,7 @@ import os
|
||||
|
||||
from mem0 import Memory
|
||||
|
||||
memory = Memory(api_key=os.environ["MEM0_API_KEY"])
|
||||
memory = Memory()
|
||||
|
||||
# Sticky note: conversation memory
|
||||
memory.add(
|
||||
@@ -72,8 +72,7 @@ memory.add(
|
||||
# Later in the session, pull long-term + session context
|
||||
results = memory.search(
|
||||
"Any hotel preferences?",
|
||||
user_id="alex",
|
||||
run_id="trip-planning-2025",
|
||||
filters={"user_id": "alex", "run_id": "trip-planning-2025"},
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ description: "Run richer add/search/update/delete flows on the managed platform
|
||||
**Prerequisites**
|
||||
- Platform workspace with API key
|
||||
- Python 3.10+ and Node.js 18+
|
||||
- Async memories enabled in your dashboard (Settings → Memory Options)
|
||||
</Info>
|
||||
|
||||
<Tip>
|
||||
@@ -21,9 +20,9 @@ description: "Run richer add/search/update/delete flows on the managed platform
|
||||
<Tabs>
|
||||
<Tab title="Python">
|
||||
<Steps>
|
||||
<Step title="Install the SDK with async extras">
|
||||
<Step title="Install the SDK">
|
||||
```bash
|
||||
pip install "mem0ai[async]"
|
||||
pip install mem0ai
|
||||
```
|
||||
</Step>
|
||||
<Step title="Export your API key">
|
||||
@@ -55,9 +54,9 @@ export MEM0_API_KEY="sk-platform-..."
|
||||
</Step>
|
||||
<Step title="Instantiate the client">
|
||||
```typescript
|
||||
import { Memory } from "mem0ai";
|
||||
import MemoryClient from 'mem0ai';
|
||||
|
||||
const memory = new Memory({ apiKey: process.env.MEM0_API_KEY!, async: true });
|
||||
const memory = new MemoryClient({ apiKey: process.env.MEM0_API_KEY! });
|
||||
```
|
||||
</Step>
|
||||
</Steps>
|
||||
@@ -121,10 +120,8 @@ const result = await memory.add(conversation, {
|
||||
```python
|
||||
matches = await memory.search(
|
||||
"Any food alerts?",
|
||||
user_id="traveler-42",
|
||||
filters={"metadata.trip": "japan-2025"},
|
||||
filters={"user_id": "traveler-42", "metadata.trip": "japan-2025"},
|
||||
rerank=True,
|
||||
include_vectors=False,
|
||||
)
|
||||
```
|
||||
</Step>
|
||||
@@ -132,7 +129,7 @@ matches = await memory.search(
|
||||
```python
|
||||
await memory.update(
|
||||
memory_id=matches["results"][0]["id"],
|
||||
content="Morgan avoids shellfish and prefers boutique hotels in central Tokyo.",
|
||||
data="Morgan avoids shellfish and prefers boutique hotels in central Tokyo.",
|
||||
)
|
||||
```
|
||||
</Step>
|
||||
@@ -143,17 +140,15 @@ await memory.update(
|
||||
<Step title="Search with metadata filters">
|
||||
```typescript
|
||||
const matches = await memory.search("Any food alerts?", {
|
||||
userId: "traveler-42",
|
||||
filters: { "metadata.trip": "japan-2025" },
|
||||
filters: { user_id: "traveler-42", "metadata.trip": "japan-2025" },
|
||||
rerank: true,
|
||||
includeVectors: false,
|
||||
});
|
||||
```
|
||||
</Step>
|
||||
<Step title="Apply an update">
|
||||
```typescript
|
||||
await memory.update(matches.results[0].id, {
|
||||
content: "Morgan avoids shellfish and prefers boutique hotels in central Tokyo.",
|
||||
text: "Morgan avoids shellfish and prefers boutique hotels in central Tokyo.",
|
||||
});
|
||||
```
|
||||
</Step>
|
||||
|
||||
@@ -26,7 +26,7 @@ Reorders results using deep semantic understanding to put the most relevant memo
|
||||
results = client.search(
|
||||
query="What are my upcoming travel plans?",
|
||||
rerank=True,
|
||||
user_id="user123"
|
||||
filters={"user_id": "user123"},
|
||||
)
|
||||
|
||||
# Before reranking: After reranking:
|
||||
@@ -52,7 +52,7 @@ results = client.search(
|
||||
results = client.search(
|
||||
query="How do I like my bedroom temperature?",
|
||||
rerank=True, # Get most recent preferences first
|
||||
user_id="user123"
|
||||
filters={"user_id": "user123"},
|
||||
)
|
||||
|
||||
# Finds: "Keep bedroom at 68°F", "Too cold last night at 65°F", etc.
|
||||
@@ -63,7 +63,7 @@ results = client.search(
|
||||
# Find specific product issues with high precision
|
||||
results = client.search(
|
||||
query="Problems with premium subscription billing",
|
||||
user_id="customer456"
|
||||
filters={"user_id": "customer456"},
|
||||
)
|
||||
|
||||
# Returns only relevant billing problems, not general questions
|
||||
@@ -75,7 +75,7 @@ results = client.search(
|
||||
results = client.search(
|
||||
query="Patient allergies and contraindications",
|
||||
rerank=True, # Most important info first
|
||||
user_id="patient789"
|
||||
filters={"user_id": "patient789"},
|
||||
)
|
||||
|
||||
# Ensures critical allergy info appears first
|
||||
@@ -87,7 +87,7 @@ results = client.search(
|
||||
results = client.search(
|
||||
query="Python programming progress and difficulties",
|
||||
rerank=True, # Recent progress first
|
||||
user_id="student123"
|
||||
filters={"user_id": "student123"},
|
||||
)
|
||||
|
||||
# Gets comprehensive view of Python learning journey
|
||||
@@ -105,7 +105,7 @@ results = client.search(
|
||||
def quick_search(query, user_id):
|
||||
return client.search(
|
||||
query=query,
|
||||
user_id=user_id
|
||||
filters={"user_id": user_id},
|
||||
)
|
||||
|
||||
# Reranked search - good for most applications
|
||||
@@ -113,7 +113,7 @@ def standard_search(query, user_id):
|
||||
return client.search(
|
||||
query=query,
|
||||
rerank=True,
|
||||
user_id=user_id
|
||||
filters={"user_id": user_id},
|
||||
)
|
||||
|
||||
# Reranked search - good for critical applications
|
||||
@@ -121,7 +121,7 @@ def precise_search(query, user_id):
|
||||
return client.search(
|
||||
query=query,
|
||||
rerank=True,
|
||||
user_id=user_id
|
||||
filters={"user_id": user_id},
|
||||
)
|
||||
```
|
||||
|
||||
@@ -129,23 +129,23 @@ def precise_search(query, user_id):
|
||||
// Basic search - good for exploration
|
||||
function quickSearch(query, userId) {
|
||||
return client.search(query, {
|
||||
user_id: userId
|
||||
filters: { user_id: userId },
|
||||
});
|
||||
}
|
||||
|
||||
// Reranked search - good for most applications
|
||||
function standardSearch(query, userId) {
|
||||
return client.search(query, {
|
||||
user_id: userId,
|
||||
rerank: true
|
||||
filters: { user_id: userId },
|
||||
rerank: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Reranked search - good for critical applications
|
||||
function preciseSearch(query, userId) {
|
||||
return client.search(query, {
|
||||
user_id: userId,
|
||||
rerank: true
|
||||
filters: { user_id: userId },
|
||||
rerank: true,
|
||||
});
|
||||
}
|
||||
```
|
||||
@@ -178,7 +178,7 @@ start_time = time.time()
|
||||
results = client.search(
|
||||
query="user preferences",
|
||||
rerank=True, # +150ms
|
||||
user_id="user123"
|
||||
filters={"user_id": "user123"},
|
||||
)
|
||||
latency = time.time() - start_time
|
||||
print(f"Search completed in {latency:.2f}s")
|
||||
|
||||
@@ -25,7 +25,7 @@ const messages = [
|
||||
{"role": "assistant", "content": "Great! I'll remember your preference for Italian cuisine."}
|
||||
];
|
||||
|
||||
await client.add(messages, { userId: "user123", version: "v2" });
|
||||
await client.add(messages, { userId: "user123" });
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
@@ -65,14 +65,14 @@ const messages1 = [
|
||||
{"role": "user", "content": "Hi, I'm Sarah from New York"},
|
||||
{"role": "assistant", "content": "Hello Sarah! Nice to meet you."}
|
||||
];
|
||||
await client.add(messages1, { userId: "sarah", version: "v2" });
|
||||
await client.add(messages1, { userId: "sarah" });
|
||||
|
||||
// Later interaction - just send new messages
|
||||
const messages2 = [
|
||||
{"role": "user", "content": "I'm planning a trip to Italy next month"},
|
||||
{"role": "assistant", "content": "How exciting! Italy is beautiful this time of year."}
|
||||
];
|
||||
await client.add(messages2, { userId: "sarah", version: "v2" });
|
||||
await client.add(messages2, { userId: "sarah" });
|
||||
// Mem0 automatically knows Sarah is from New York and can use this context
|
||||
```
|
||||
</CodeGroup>
|
||||
@@ -104,7 +104,7 @@ const messages = [
|
||||
{"role": "assistant", "content": "I've noted your allergies for future reference."}
|
||||
];
|
||||
|
||||
await client.add(messages, { userId: "user123", version: "v2" });
|
||||
await client.add(messages, { userId: "user123" });
|
||||
// This allergy info will be available in ALL future interactions
|
||||
```
|
||||
</CodeGroup>
|
||||
@@ -143,21 +143,21 @@ const messages1 = [
|
||||
{"role": "user", "content": "I want to plan a 5-day trip to Tokyo"},
|
||||
{"role": "assistant", "content": "Perfect! Let's plan your Tokyo adventure."}
|
||||
];
|
||||
await client.add(messages1, { userId: "user123", runId: "tokyo-trip-2024", version: "v2" });
|
||||
await client.add(messages1, { userId: "user123", runId: "tokyo-trip-2024" });
|
||||
|
||||
// Later in the same trip planning session
|
||||
const messages2 = [
|
||||
{"role": "user", "content": "I prefer staying near Shibuya"},
|
||||
{"role": "assistant", "content": "Great choice! Shibuya is very convenient."}
|
||||
];
|
||||
await client.add(messages2, { userId: "user123", runId: "tokyo-trip-2024", version: "v2" });
|
||||
await client.add(messages2, { userId: "user123", runId: "tokyo-trip-2024" });
|
||||
|
||||
// Different session for work project (separate context)
|
||||
const workMessages = [
|
||||
{"role": "user", "content": "Let's discuss the Q4 marketing strategy"},
|
||||
{"role": "assistant", "content": "Sure! What are your main goals for Q4?"}
|
||||
];
|
||||
await client.add(workMessages, { userId: "user123", runId: "q4-marketing", version: "v2" });
|
||||
await client.add(workMessages, { userId: "user123", runId: "q4-marketing" });
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ If no criteria are defined for a project, search behaves normally based on seman
|
||||
This lets you prioritize memories that align with your agent's goals and not just those that look similar to the query.
|
||||
|
||||
<Note>
|
||||
Criteria retrieval is automatically enabled when criteria are defined in your project. Use `use_criteria=False` in search to temporarily disable it for a specific query.
|
||||
Criteria retrieval is automatically enabled when criteria are defined in your project. Use `use_criteria=False` in search to temporarily disable it for a specific query. `use_criteria` is a server-side parameter passed through to the Platform API — it is not a typed option in the SDK's `SearchMemoryOptions` interface, but the server accepts and processes it when included in the request body.
|
||||
</Note>
|
||||
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ Handle potential errors when submitting feedback:
|
||||
|
||||
```python Python
|
||||
from mem0 import MemoryClient
|
||||
from mem0.exceptions import MemoryNotFoundError, APIError
|
||||
from mem0.exceptions import MemoryNotFoundError, NetworkError
|
||||
|
||||
client = MemoryClient(api_key="your_api_key")
|
||||
|
||||
@@ -163,8 +163,8 @@ try:
|
||||
print("Feedback submitted successfully")
|
||||
except MemoryNotFoundError:
|
||||
print("Memory not found")
|
||||
except APIError as e:
|
||||
print(f"API error: {e}")
|
||||
except NetworkError as e:
|
||||
print(f"Network error: {e}")
|
||||
except Exception as e:
|
||||
print(f"Unexpected error: {e}")
|
||||
```
|
||||
|
||||
@@ -111,32 +111,37 @@ print(all_memories)
|
||||
```
|
||||
|
||||
```json Output
|
||||
[
|
||||
{
|
||||
"id": "147559a8-c5f7-44d0-9418-91f53f7a89a4",
|
||||
"memory": "suggests considering Angular because it has great enterprise support",
|
||||
"user_id": "charlie",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:11.007223-07:00",
|
||||
"updated_at": "2025-06-21T05:51:11.626562-07:00"
|
||||
},
|
||||
{
|
||||
"id": "1d8b8f39-7b17-4d18-8632-ab1c64fa35b9",
|
||||
"memory": "prefers Vue.js for our use case",
|
||||
"user_id": "bob",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:08.675301-07:00",
|
||||
"updated_at": "2025-06-21T05:51:09.319269-07:00",
|
||||
},
|
||||
{
|
||||
"id": "4d82478a-8d50-47e6-9324-1f65efff5829",
|
||||
"memory": "prefers using React for the frontend",
|
||||
"user_id": "alice",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:05.943223-07:00",
|
||||
"updated_at": "2025-06-21T05:51:06.982539-07:00",
|
||||
}
|
||||
]
|
||||
{
|
||||
"count": 3,
|
||||
"next": null,
|
||||
"previous": null,
|
||||
"results": [
|
||||
{
|
||||
"id": "147559a8-c5f7-44d0-9418-91f53f7a89a4",
|
||||
"memory": "suggests considering Angular because it has great enterprise support",
|
||||
"user_id": "charlie",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:11.007223-07:00",
|
||||
"updated_at": "2025-06-21T05:51:11.626562-07:00"
|
||||
},
|
||||
{
|
||||
"id": "1d8b8f39-7b17-4d18-8632-ab1c64fa35b9",
|
||||
"memory": "prefers Vue.js for our use case",
|
||||
"user_id": "bob",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:08.675301-07:00",
|
||||
"updated_at": "2025-06-21T05:51:09.319269-07:00"
|
||||
},
|
||||
{
|
||||
"id": "4d82478a-8d50-47e6-9324-1f65efff5829",
|
||||
"memory": "prefers using React for the frontend",
|
||||
"user_id": "alice",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:05.943223-07:00",
|
||||
"updated_at": "2025-06-21T05:51:06.982539-07:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
@@ -161,17 +166,21 @@ print(charlie_memories)
|
||||
```
|
||||
|
||||
```json Output
|
||||
[
|
||||
{
|
||||
"id": "147559a8-c5f7-44d0-9418-91f53f7a89a4",
|
||||
"memory": "suggests considering Angular because it has great enterprise support",
|
||||
"user_id": "charlie",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:11.007223-07:00",
|
||||
"updated_at": "2025-06-21T05:51:11.626562-07:00",
|
||||
|
||||
}
|
||||
]
|
||||
{
|
||||
"count": 1,
|
||||
"next": null,
|
||||
"previous": null,
|
||||
"results": [
|
||||
{
|
||||
"id": "147559a8-c5f7-44d0-9418-91f53f7a89a4",
|
||||
"memory": "suggests considering Angular because it has great enterprise support",
|
||||
"user_id": "charlie",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:11.007223-07:00",
|
||||
"updated_at": "2025-06-21T05:51:11.626562-07:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
@@ -199,16 +208,18 @@ print(search_response)
|
||||
```
|
||||
|
||||
```json Output
|
||||
[
|
||||
{
|
||||
"id": "147559a8-c5f7-44d0-9418-91f53f7a89a4",
|
||||
"memory": "suggests considering Angular because it has great enterprise support",
|
||||
"user_id": "charlie",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:11.007223-07:00",
|
||||
"updated_at": "2025-06-21T05:51:11.626562-07:00",
|
||||
}
|
||||
]
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "147559a8-c5f7-44d0-9418-91f53f7a89a4",
|
||||
"memory": "suggests considering Angular because it has great enterprise support",
|
||||
"user_id": "charlie",
|
||||
"run_id": "group_chat_1",
|
||||
"created_at": "2025-06-21T05:51:11.007223-07:00",
|
||||
"updated_at": "2025-06-21T05:51:11.626562-07:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
@@ -251,7 +251,6 @@ You can apply various filters to customize which memories are included in the ex
|
||||
- `user_id`: Filter memories by specific user
|
||||
- `agent_id`: Filter memories by specific agent
|
||||
- `run_id`: Filter memories by specific run
|
||||
- `session_id`: Filter memories by specific session
|
||||
- `created_at`: Filter memories by date
|
||||
|
||||
<Note>
|
||||
|
||||
@@ -9,7 +9,7 @@ estimatedTime: "~2 minutes"
|
||||
**Prerequisites**
|
||||
- Mem0 Platform account (<a href="https://app.mem0.ai?utm_source=oss&utm_medium=platform-mem0-mcp" rel="nofollow">Sign up here</a>)
|
||||
- API key (<a href="https://app.mem0.ai/settings/api-keys?utm_source=oss&utm_medium=platform-mem0-mcp" rel="nofollow">Get one from dashboard</a>)
|
||||
- Node.js 14+ (for npx)
|
||||
- Node.js 18+ (for npx)
|
||||
- An MCP-compatible client (Claude, Claude Code, Codex, Cursor, Windsurf, VS Code, OpenCode)
|
||||
</Info>
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ Get started with Mem0 Platform's hosted API in under 5 minutes. This guide shows
|
||||
|
||||
- Mem0 Platform account (<a href="https://app.mem0.ai?utm_source=oss&utm_medium=platform-quickstart" rel="nofollow">Sign up here</a>)
|
||||
- API key (<a href="https://app.mem0.ai/dashboard/settings?tab=api-keys&subtab=configuration" rel="nofollow">Get one from dashboard</a>)
|
||||
- Python 3.10+, Node.js 14+, or cURL
|
||||
- Python 3.10+, Node.js 18+, or cURL
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mem0ai",
|
||||
"version": "3.0.11",
|
||||
"version": "3.0.12",
|
||||
"description": "The Memory Layer For Your AI Apps",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "mem0ai"
|
||||
version = "2.0.9"
|
||||
version = "2.0.10"
|
||||
description = "Long-term memory for AI Agents"
|
||||
authors = [
|
||||
{ name = "Mem0", email = "support@mem0.ai" }
|
||||
|
||||
Reference in New Issue
Block a user