[docs] OSS Features , Overview , Brushup (#3676)

This commit is contained in:
Parth Sharma
2025-10-27 12:31:40 -07:00
committed by GitHub
parent 80c9139c5b
commit ee8955d08b
37 changed files with 1856 additions and 1696 deletions
@@ -1,94 +1,147 @@
---
title: OpenAI Compatibility
description: 'Integrate Mem0 using OpenAI-compatible client APIs'
description: Use Mem0 with the same chat-completions flow you already built for OpenAI.
icon: "message-bot"
---
Mem0 can be easily integrated into chat applications to enhance conversational agents with structured memory. Mem0's APIs are designed to be compatible with OpenAI's, with the goal of making it easy to leverage Mem0 in applications you may have already built.
Mem0 mirrors the OpenAI client interface so you can plug memories into existing chat-completion code with minimal changes. Point your OpenAI-compatible client at Mem0, keep the same request shape, and gain persistent memory between calls.
If you have a Mem0 API key, you can use it to initialize the client. Alternatively, you can initialize Mem0 without an API key if you're using it locally.
<Info>
**You’ll use this when…**
- Your app already relies on OpenAI chat completions and you want Mem0 to feel familiar.
- You need to reuse existing middleware that expects OpenAI-compatible responses.
- You plan to switch between Mem0 Platform and the self-hosted client without rewriting code.
</Info>
Mem0 supports several language models (LLMs) through integration with various [providers](https://litellm.vercel.app/docs/providers).
## Feature
## Use Mem0 Platform
- **Drop-in client:** `client.chat.completions.create(...)` works the same as OpenAI’s method signatures.
- **Shared parameters:** Mem0 accepts `messages`, `model`, and optional memory-scoping fields (`user_id`, `agent_id`, `run_id`).
- **Memory-aware responses:** Each call saves relevant facts so future prompts automatically reflect past conversations.
- **OSS parity:** Use the same API surface whether you call the hosted proxy or the OSS configuration.
<Info icon="check">
Run one request with `user_id` set. If the next call references that ID and its reply uses the stored memory, compatibility is confirmed.
</Info>
---
## Configure it
### Call the managed Mem0 proxy
```python
from mem0.proxy.main import Mem0
client = Mem0(api_key="m0-xxx")
# First interaction: Storing user preferences
messages = [
{
"role": "user",
"content": "I love Indian food but I cannot eat pizza since I'm allergic to cheese."
},
]
user_id = "alice"
chat_completion = client.chat.completions.create(
messages=messages,
model="gpt-4.1-nano-2025-04-14",
user_id=user_id
)
# Memory saved after this will look like: "Loves Indian food. Allergic to cheese and cannot eat pizza."
# Second interaction: Leveraging stored memory
messages = [
{
"role": "user",
"content": "Suggest restaurants in San Francisco to eat.",
}
{"role": "user", "content": "I love Indian food but I cannot eat pizza since I'm allergic to cheese."}
]
chat_completion = client.chat.completions.create(
messages=messages,
model="gpt-4.1-nano-2025-04-14",
user_id=user_id
user_id="alice"
)
print(chat_completion.choices[0].message.content)
# Answer: You might enjoy Indian restaurants in San Francisco, such as Amber India, Dosa, or Curry Up Now, which offer delicious options without cheese.
```
In this example, you can see how the second response is tailored based on the information provided in the first interaction. Mem0 remembers the user's preference for Indian food and their cheese allergy, using this information to provide more relevant and personalized restaurant suggestions in San Francisco.
<Tip>
Reuse the same identifiers your OpenAI client already sends so you can switch between providers without branching logic.
</Tip>
## Use Mem0 OSS
### Use the OpenAI-compatible OSS client
```python
from mem0.proxy.main import Mem0
config = {
"vector_store": {
"provider": "qdrant",
"config": {
"host": "localhost",
"port": 6333,
"port": 6333
}
},
}
}
client = Mem0(config=config)
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "What's the capital of France?",
}
],
model="gpt-4.1-nano-2025-04-14",
messages=[{"role": "user", "content": "What's the capital of France?"}],
model="gpt-4.1-nano-2025-04-14"
)
```
## Mem0 Params for Chat Completion
## See it in action
- `user_id` (Optional[str]): Identifier for the user.
### Memory-aware restaurant recommendation
- `agent_id` (Optional[str]): Identifier for the agent.
```python
from mem0.proxy.main import Mem0
- `run_id` (Optional[str]): Identifier for the run.
client = Mem0(api_key="m0-xxx")
- `metadata` (Optional[dict]): Additional metadata to be stored with the memory.
# Store preferences
client.chat.completions.create(
messages=[{"role": "user", "content": "I love Indian food but I'm allergic to cheese."}],
model="gpt-4.1-nano-2025-04-14",
user_id="alice"
)
- `filters` (Optional[dict]): Filters to apply when searching for relevant memories.
# Later conversation reuses the memory
response = client.chat.completions.create(
messages=[{"role": "user", "content": "Suggest dinner options in San Francisco."}],
model="gpt-4.1-nano-2025-04-14",
user_id="alice"
)
- `limit` (Optional[int]): Maximum number of relevant memories to retrieve. Default is 10.
print(response.choices[0].message.content)
```
<Info icon="check">
The second response should call out Indian restaurants and avoid cheese, proving Mem0 recalled the stored preference.
</Info>
Other parameters are similar to OpenAI's API, making it easy to integrate Mem0 into your existing applications.
---
## Verify the feature is working
- Compare responses from Mem0 vs. OpenAI for identical prompts—both should return the same structure (`choices`, `usage`, etc.).
- Inspect stored memories after each request to confirm the fact extraction captured the right details.
- Test switching between hosted (`Mem0(api_key=...)`) and OSS configurations to ensure both respect the same request body.
---
## Best practices
1. **Scope context intentionally:** Pass identifiers only when you want conversations to persist; skip them for one-off calls.
2. **Log memory usage:** Inspect `response.metadata.memories` (if enabled) to see which facts the model recalled.
3. **Reuse middleware:** Point your existing OpenAI client wrappers to the Mem0 proxy URL to avoid code drift.
4. **Handle fallbacks:** Keep a code path for plain OpenAI calls in case Mem0 is unavailable, then resync memory later.
---
## Parameter reference
| Parameter | Type | Purpose |
| --- | --- | --- |
| `user_id` | `str` | Associates the conversation with a user so memories persist. |
| `agent_id` | `str` | Optional agent or bot identifier for multi-agent scenarios. |
| `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). |
Other request fields mirror OpenAI’s chat completion API.
---
<CardGroup cols={2}>
<Card title="Connect Vision Models" icon="circle-dot" href="/components/llms/models/openai">
Review LLM options that support OpenAI-compatible calls in Mem0.
</Card>
<Card title="Automate OpenAI Tool Calls" icon="plug" href="/cookbooks/integrations/openai-tool-calls">
See a full workflow that layers Mem0 memories on top of tool-calling agents.
</Card>
</CardGroup>