fix(sdk): removing deprecating param from our sdk and docs changes with it (#4740)
This commit is contained in:
@@ -240,7 +240,7 @@ async_openai_client = AsyncOpenAI()
|
||||
async_memory = AsyncMemory()
|
||||
|
||||
async def chat_with_memories(message: str, user_id: str = "default_user") -> str:
|
||||
search_result = await async_memory.search(query=message, user_id=user_id, limit=3)
|
||||
search_result = await async_memory.search(query=message, user_id=user_id, top_k=3)
|
||||
relevant_memories = search_result["results"]
|
||||
memories_str = "\n".join(f"- {entry['memory']}" for entry in relevant_memories)
|
||||
|
||||
@@ -326,7 +326,7 @@ async def add_memory(messages: list, user_id: str):
|
||||
@app.get("/memories/search")
|
||||
async def search_memories(query: str, user_id: str, limit: int = 10):
|
||||
try:
|
||||
result = await memory.search(query=query, user_id=user_id, limit=limit)
|
||||
result = await memory.search(query=query, user_id=user_id, top_k=limit)
|
||||
return {"status": "success", "data": result}
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=500, detail=str(exc))
|
||||
|
||||
+17
-13
@@ -1,13 +1,13 @@
|
||||
---
|
||||
title: Custom Fact Extraction Prompt
|
||||
title: Custom Instructions
|
||||
description: Tailor fact extraction so Mem0 stores only the details you care about.
|
||||
icon: "wand-magic-sparkles"
|
||||
---
|
||||
|
||||
Custom fact extraction prompts let you decide exactly which facts Mem0 records from a conversation. Define a focused prompt, give a few examples, and Mem0 will add only the memories that match your use case.
|
||||
Custom instructions let you decide exactly which facts Mem0 records from a conversation. Define a focused prompt, give a few examples, and Mem0 will add only the memories that match your use case.
|
||||
|
||||
<Info>
|
||||
**You’ll use this when…**
|
||||
**You'll use this when...**
|
||||
- A project needs domain-specific facts (order numbers, customer info) without storing casual chatter.
|
||||
- You already have a clear schema for memories and want the LLM to follow it.
|
||||
- You must prevent irrelevant details from entering long-term storage.
|
||||
@@ -17,6 +17,10 @@ Custom fact extraction prompts let you decide exactly which facts Mem0 records f
|
||||
Prompts that are too broad cause unrelated facts to slip through. Keep instructions tight and test them with real transcripts.
|
||||
</Warning>
|
||||
|
||||
<Note>
|
||||
The `custom_fact_extraction_prompt` parameter has been renamed to `custom_instructions`. If you are upgrading from an older version, update your configuration accordingly.
|
||||
</Note>
|
||||
|
||||
---
|
||||
|
||||
## Feature anatomy
|
||||
@@ -24,13 +28,13 @@ Custom fact extraction prompts let you decide exactly which facts Mem0 records f
|
||||
- **Prompt instructions:** Describe which entities or phrases to keep. Specific guidance keeps the extractor focused.
|
||||
- **Few-shot examples:** Show positive and negative cases so the model copies the right format.
|
||||
- **Structured output:** Responses return JSON with a `facts` array that Mem0 converts into individual memories.
|
||||
- **LLM configuration:** `custom_fact_extraction_prompt` (Python) or `customPrompt` (TypeScript) lives alongside your model settings.
|
||||
- **LLM configuration:** `custom_instructions` (Python) or `customInstructions` (TypeScript) lives alongside your model settings.
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Prompt blueprint">
|
||||
1. State the allowed fact types.
|
||||
2. Include short examples that mirror production messages.
|
||||
3. Show both empty (`[]`) and populated outputs.
|
||||
1. State the allowed fact types.
|
||||
2. Include short examples that mirror production messages.
|
||||
3. Show both empty (`[]`) and populated outputs.
|
||||
4. Remind the model to return JSON with a `facts` key only.
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
@@ -43,8 +47,8 @@ Custom fact extraction prompts let you decide exactly which facts Mem0 records f
|
||||
|
||||
<CodeGroup>
|
||||
```python Python
|
||||
custom_fact_extraction_prompt = """
|
||||
Please only extract entities containing customer support information, order details, and user information.
|
||||
custom_instructions = """
|
||||
Please only extract entities containing customer support information, order details, and user information.
|
||||
Here are some few shot examples:
|
||||
|
||||
Input: Hi.
|
||||
@@ -67,8 +71,8 @@ Return the facts and customer information in a json format as shown above.
|
||||
```
|
||||
|
||||
```ts TypeScript
|
||||
const customPrompt = `
|
||||
Please only extract entities containing customer support information, order details, and user information.
|
||||
const customInstructions = `
|
||||
Please only extract entities containing customer support information, order details, and user information.
|
||||
Here are some few shot examples:
|
||||
|
||||
Input: Hi.
|
||||
@@ -110,7 +114,7 @@ config = {
|
||||
"max_tokens": 2000,
|
||||
}
|
||||
},
|
||||
"custom_fact_extraction_prompt": custom_fact_extraction_prompt,
|
||||
"custom_instructions": custom_instructions,
|
||||
"version": "v1.1"
|
||||
}
|
||||
|
||||
@@ -131,7 +135,7 @@ const config = {
|
||||
maxTokens: 1500,
|
||||
},
|
||||
},
|
||||
customPrompt: customPrompt,
|
||||
customInstructions: customInstructions,
|
||||
};
|
||||
|
||||
const memory = new Memory(config);
|
||||
@@ -263,7 +263,7 @@ Please note to return the IDs in the output from the input IDs only and do not g
|
||||
- Log each decision so product teams can review why a change happened.
|
||||
|
||||
<Note>
|
||||
The prompt works alongside `custom_fact_extraction_prompt`—fact extraction identifies candidate facts, and the update prompt decides how to merge them into long-term storage.
|
||||
The prompt works alongside `custom_instructions`—fact extraction identifies candidate facts, and the update prompt decides how to merge them into long-term storage.
|
||||
</Note>
|
||||
|
||||
---
|
||||
@@ -288,7 +288,7 @@ Please note to return the IDs in the output from the input IDs only and do not g
|
||||
|
||||
## Compare prompts
|
||||
|
||||
| Feature | `custom_update_memory_prompt` | `custom_fact_extraction_prompt` |
|
||||
| Feature | `custom_update_memory_prompt` | `custom_instructions` |
|
||||
| --- | --- | --- |
|
||||
| Primary job | Decide memory actions (ADD/UPDATE/DELETE/NONE) | Pull facts from user and assistant messages |
|
||||
| Inputs | Retrieved facts + existing memory entries | Raw conversation turns |
|
||||
@@ -297,7 +297,7 @@ Please note to return the IDs in the output from the input IDs only and do not g
|
||||
---
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Design Fact Extraction" icon="sparkles" href="/open-source/features/custom-fact-extraction-prompt">
|
||||
<Card title="Design Fact Extraction" icon="sparkles" href="/open-source/features/custom-instructions">
|
||||
Coordinate both prompts so fact extraction feeds clean inputs into the update flow.
|
||||
</Card>
|
||||
<Card title="Build Email Automations" icon="inbox" href="/cookbooks/operations/email-automation">
|
||||
|
||||
@@ -94,7 +94,7 @@ memory.add(conversation, user_id="demo-user")
|
||||
results = memory.search(
|
||||
"Who did Alice meet at GraphConf?",
|
||||
user_id="demo-user",
|
||||
limit=3,
|
||||
top_k=3,
|
||||
rerank=True,
|
||||
)
|
||||
|
||||
@@ -146,7 +146,7 @@ await memory.add(conversation, { userId: "demo-user" });
|
||||
|
||||
const results = await memory.search(
|
||||
"Who did Alice meet at GraphConf?",
|
||||
{ userId: "demo-user", limit: 3, rerank: true }
|
||||
{ userId: "demo-user", topK: 3, rerank: true }
|
||||
);
|
||||
|
||||
results.results.forEach((hit) => {
|
||||
@@ -204,7 +204,7 @@ const config = {
|
||||
username: process.env.NEO4J_USERNAME!,
|
||||
password: process.env.NEO4J_PASSWORD!,
|
||||
},
|
||||
customPrompt: "Please only capture people, organisations, and project links.",
|
||||
customInstructions: "Please only capture people, organisations, and project links.",
|
||||
}
|
||||
};
|
||||
|
||||
@@ -265,7 +265,7 @@ Monitor graph growth, especially on free tiers, by periodically cleaning dormant
|
||||
## Decision Points
|
||||
|
||||
- Select the graph store that fits your deployment (managed Aura vs. self-hosted Neo4j vs. AWS Neptune vs. local Kuzu vs. Apache AGE on PostgreSQL).
|
||||
- Decide when to enable graph writes per request; routine conversations may stay vector-only to save latency.
|
||||
- Decide whether to include a graph store in your config; routine conversations may stay vector-only to save latency.
|
||||
- Set a policy for pruning stale relationships so your graph stays fast and affordable.
|
||||
|
||||
## Provider setup
|
||||
|
||||
@@ -131,7 +131,7 @@ print(response.choices[0].message.content)
|
||||
| `run_id` | `str` | Optional session/run identifier for short-lived flows. |
|
||||
| `metadata` | `dict` | Store extra fields alongside each memory entry. |
|
||||
| `filters` | `dict` | Restrict retrieval to specific memories while responding. |
|
||||
| `limit` | `int` | Cap how many memories Mem0 pulls into the context (default 10). |
|
||||
| `top_k` | `int` | Cap how many memories Mem0 pulls into the context (default 10). |
|
||||
|
||||
Other request fields mirror OpenAI’s chat completion API.
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Mem0 Open Source ships with capabilities that adapt memory behavior for producti
|
||||
<Card title="Multimodal Support" icon="image" href="/open-source/features/multimodal-support">
|
||||
Process images, audio, and video memories.
|
||||
</Card>
|
||||
<Card title="Custom Fact Extraction" icon="wand-magic-sparkles" href="/open-source/features/custom-fact-extraction-prompt">
|
||||
<Card title="Custom Instructions" icon="wand-magic-sparkles" href="/open-source/features/custom-instructions">
|
||||
Tailor how facts are extracted from text.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
@@ -321,7 +321,7 @@ results = m.search(
|
||||
]
|
||||
},
|
||||
rerank=True,
|
||||
limit=20
|
||||
top_k=20
|
||||
)
|
||||
```
|
||||
|
||||
@@ -366,7 +366,7 @@ results = m.search(
|
||||
user_id="reader123",
|
||||
filters={"content_type": "book_recommendation"},
|
||||
rerank=True,
|
||||
limit=10
|
||||
top_k=10
|
||||
)
|
||||
|
||||
for result in results["results"]:
|
||||
|
||||
@@ -230,7 +230,7 @@ Mem0 offers granular configuration across vector stores, LLMs, embedders, and hi
|
||||
| --- | --- | --- |
|
||||
| `historyDbPath` | Path to history database | `"{mem0_dir}/history.db"` |
|
||||
| `version` | API version | `"v1.0"` |
|
||||
| `customPrompt` | Custom processing prompt | `undefined` |
|
||||
| `customInstructions` | Custom processing prompt | `undefined` |
|
||||
</Accordion>
|
||||
<Accordion title="History store">
|
||||
| Parameter | Description | Default |
|
||||
@@ -273,7 +273,7 @@ const config = {
|
||||
}
|
||||
},
|
||||
disableHistory: false,
|
||||
customPrompt: "I'm a virtual assistant. I'm here to help you with your queries."
|
||||
customInstructions: "I'm a virtual assistant. I'm here to help you with your queries."
|
||||
};
|
||||
```
|
||||
</Accordion>
|
||||
|
||||
Reference in New Issue
Block a user