Skip to content

Commit d634851

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into dev
2 parents f3c4f6c + 748ef3d commit d634851

32 files changed

+1391
-500
lines changed

README.md

Lines changed: 121 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
MemOS is an open-source **Agent Memory framework** that empowers AI agents with **long-term memory, personality consistency, and contextual recall**. It enables agents to **remember past interactions**, **learn over time**, and **build evolving identities** across sessions.
44

55
Designed for **AI companions, role-playing NPCs, and multi-agent systems**, MemOS provides a unified API for **memory representation, retrieval, and update** — making it the foundation for next-generation **memory-augmented AI agents**.
6-
7-
🆕 **MemOS 2.0** introduces **knowledge base system**, **multi-modal memory** (images & documents), **tool memory** for Agent optimization, **memory feedback mechanism** for precise control, and **enterprise-grade architecture** with Redis Streams scheduler and advanced DB optimizations.
86
<div align="center">
97
<a href="https://memos.openmem.net/">
108
<img src="https://statics.memtensor.com.cn/memos/memos-banner.gif" alt="MemOS Banner">
@@ -117,98 +115,8 @@ showcasing its capabilities in **information extraction**, **temporal and cross-
117115
- **Textual Memory**: For storing and retrieving unstructured or structured text knowledge.
118116
- **Activation Memory**: Caches key-value pairs (`KVCacheMemory`) to accelerate LLM inference and context reuse.
119117
- **Parametric Memory**: Stores model adaptation parameters (e.g., LoRA weights).
120-
- **Tool Memory** 🆕: Records Agent tool call trajectories and experiences to improve planning capabilities.
121-
- **📚 Knowledge Base System** 🆕: Build multi-dimensional knowledge bases with automatic document/URL parsing, splitting, and cross-project sharing capabilities.
122-
- **🔧 Memory Controllability** 🆕:
123-
- **Feedback Mechanism**: Use `add_feedback` API to correct, supplement, or replace existing memories with natural language.
124-
- **Precise Deletion**: Delete specific memories by User ID or Memory ID via API or MCP tools.
125-
- **👁️ Multi-Modal Support** 🆕: Support for image understanding and memory, including chart parsing in documents.
126-
- **⚡ Advanced Architecture**:
127-
- **DB Optimization**: Enhanced connection management and batch insertion for high-concurrency scenarios.
128-
- **Advanced Retrieval**: Custom tag and info field filtering with complex logical operations.
129-
- **Redis Streams Scheduler**: Multi-level queue architecture with intelligent orchestration for fair multi-tenant scheduling.
130-
- **Stream & Non-Stream Chat**: Ready-to-use streaming and non-streaming chat interfaces.
131118
- **🔌 Extensible**: Easily extend and customize memory modules, data sources, and LLM integrations.
132-
- **🏂 Lightweight Deployment** 🆕: Support for quick mode and complete mode deployment options.
133-
134-
## 🚀 Getting Started
135119

136-
### ⭐️ MemOS online API
137-
The easiest way to use MemOS. Equip your agent with memory **in minutes**!
138-
139-
Sign up and get started on[`MemOS dashboard`](https://memos-dashboard.openmem.net/cn/quickstart/?source=landing).
140-
141-
142-
### Self-Hosted Server
143-
1. Get the repository.
144-
```bash
145-
git clone https://github.com/MemTensor/MemOS.git
146-
cd MemOS
147-
pip install -r ./docker/requirements.txt
148-
```
149-
150-
2. Configure `docker/.env.example` and copy to `MemOS/.env`
151-
3. Start the service.
152-
```bash
153-
uvicorn memos.api.server_api:app --host 0.0.0.0 --port 8001 --workers 8
154-
```
155-
156-
### Local SDK
157-
Here's a quick example of how to create a **`MemCube`**, load it from a directory, access its memories, and save it.
158-
159-
```python
160-
from memos.mem_cube.general import GeneralMemCube
161-
162-
# Initialize a MemCube from a local directory
163-
mem_cube = GeneralMemCube.init_from_dir("examples/data/mem_cube_2")
164-
165-
# Access and print all memories
166-
print("--- Textual Memories ---")
167-
for item in mem_cube.text_mem.get_all():
168-
print(item)
169-
170-
print("\n--- Activation Memories ---")
171-
for item in mem_cube.act_mem.get_all():
172-
print(item)
173-
174-
# Save the MemCube to a new directory
175-
mem_cube.dump("tmp/mem_cube")
176-
```
177-
178-
**`MOS`** (Memory Operating System) is a higher-level orchestration layer that manages multiple MemCubes and provides a unified API for memory operations. Here's a quick example of how to use MOS:
179-
180-
```python
181-
from memos.configs.mem_os import MOSConfig
182-
from memos.mem_os.main import MOS
183-
184-
185-
# init MOS
186-
mos_config = MOSConfig.from_json_file("examples/data/config/simple_memos_config.json")
187-
memory = MOS(mos_config)
188-
189-
# create user
190-
user_id = "b41a34d5-5cae-4b46-8c49-d03794d206f5"
191-
memory.create_user(user_id=user_id)
192-
193-
# register cube for user
194-
memory.register_mem_cube("examples/data/mem_cube_2", user_id=user_id)
195-
196-
# add memory for user
197-
memory.add(
198-
messages=[
199-
{"role": "user", "content": "I like playing football."},
200-
{"role": "assistant", "content": "I like playing football too."},
201-
],
202-
user_id=user_id,
203-
)
204-
205-
# Later, when you want to retrieve memory for user
206-
retrieved_memories = memory.search(query="What do you like?", user_id=user_id)
207-
# output text_memories: I like playing football, act_memories, para_memories
208-
print(f"text_memories: {retrieved_memories['text_mem']}")
209-
```
210-
211-
For more detailed examples, please check out the [`examples`](./examples) directory.
212120

213121
## 📦 Installation
214122

@@ -259,6 +167,127 @@ To download example code, data and configurations, run the following command:
259167
memos download_examples
260168
```
261169

170+
171+
## 🚀 Getting Started
172+
173+
### ⭐️ MemOS online API
174+
The easiest way to use MemOS. Equip your agent with memory **in minutes**!
175+
176+
Sign up and get started on[`MemOS dashboard`](https://memos-dashboard.openmem.net/cn/quickstart/?source=landing).
177+
178+
179+
### Self-Hosted Server
180+
1. Get the repository.
181+
```bash
182+
git clone https://github.com/MemTensor/MemOS.git
183+
cd MemOS
184+
pip install -r ./docker/requirements.txt
185+
```
186+
187+
2. Configure `docker/.env.example` and copy to `MemOS/.env`
188+
3. Start the service.
189+
```bash
190+
uvicorn memos.api.server_api:app --host 0.0.0.0 --port 8001 --workers 8
191+
```
192+
193+
### Interface SDK
194+
#### Here is a quick example showing how to create all interface SDK
195+
196+
This interface is used to add messages, supporting multiple types of content and batch additions. MemOS will automatically parse the messages and handle memory for reference in subsequent conversations.
197+
```python
198+
# Please make sure MemoS is installed (pip install MemoryOS -U)
199+
from memos.api.client import MemOSClient
200+
201+
# Initialize the client using the API Key
202+
client = MemOSClient(api_key="YOUR_API_KEY")
203+
204+
messages = [
205+
{"role": "user", "content": "I have planned to travel to Guangzhou during the summer vacation. What chain hotels are available for accommodation?"},
206+
{"role": "assistant", "content": "You can consider [7 Days, All Seasons, Hilton], and so on."},
207+
{"role": "user", "content": "I'll choose 7 Days"},
208+
{"role": "assistant", "content": "Okay, ask me if you have any other questions."}
209+
]
210+
user_id = "memos_user_123"
211+
conversation_id = "0610"
212+
res = client.add_message(messages=messages, user_id=user_id, conversation_id=conversation_id)
213+
214+
print(f"result: {res}")
215+
```
216+
217+
This interface is used to retrieve the memories of a specified user, returning the memory fragments most relevant to the input query for Agent use. The recalled memory fragments include 'factual memory', 'preference memory', and 'tool memory'.
218+
```python
219+
# Please make sure MemoS is installed (pip install MemoryOS -U)
220+
from memos.api.client import MemOSClient
221+
222+
# Initialize the client using the API Key
223+
client = MemOSClient(api_key="YOUR_API_KEY")
224+
225+
query = "I want to go out to play during National Day. Can you recommend a city I haven't been to and a hotel brand I haven't stayed at?"
226+
user_id = "memos_user_123"
227+
conversation_id = "0928"
228+
res = client.search_memory(query=query, user_id=user_id, conversation_id=conversation_id)
229+
230+
print(f"result: {res}")
231+
```
232+
233+
This interface is used to delete the memory of specified users and supports batch deletion.
234+
```python
235+
# Please make sure MemoS is installed (pip install MemoryOS -U)
236+
from memos.api.client import MemOSClient
237+
238+
# Initialize the client using the API Key
239+
client = MemOSClient(api_key="YOUR_API_KEY")
240+
241+
user_ids = ["memos_user_123"]
242+
# Replace with the memory ID
243+
memory_ids = ["6b23b583-f4c4-4a8f-b345-58d0c48fea04"]
244+
res = client.delete_memory(user_ids=user_ids, memory_ids=memory_ids)
245+
246+
print(f"result: {res}")
247+
```
248+
249+
This interface is used to add feedback to messages in the current session, allowing MemOS to correct its memory based on user feedback.
250+
```python
251+
# Please make sure MemoS is installed (pip install MemoryOS -U)
252+
from memos.api.client import MemOSClient
253+
254+
# Initialize the client using the API Key
255+
client = MemOSClient(api_key="YOUR_API_KEY")
256+
257+
user_id = "memos_user_123"
258+
conversation_id = "memos_feedback_conv"
259+
feedback_content = "No, let's change it now to a meal allowance of 150 yuan per day and a lodging subsidy of 700 yuan per day for first-tier cities; for second- and third-tier cities, it remains the same as before."
260+
# Replace with the knowledgebase ID
261+
allow_knowledgebase_ids = ["basee5ec9050-c964-484f-abf1-ce3e8e2aa5b7"]
262+
263+
res = client.add_feedback(
264+
user_id=user_id,
265+
conversation_id=conversation_id,
266+
feedback_content=feedback_content,
267+
allow_knowledgebase_ids=allow_knowledgebase_ids
268+
)
269+
270+
print(f"result: {res}")
271+
```
272+
273+
This interface is used to create a knowledgebase associated with a project
274+
```python
275+
# Please make sure MemoS is installed (pip install MemoryOS -U)
276+
from memos.api.client import MemOSClient
277+
278+
# Initialize the client using the API Key
279+
client = MemOSClient(api_key="YOUR_API_KEY")
280+
281+
knowledgebase_name = "Financial Reimbursement Knowledge Base"
282+
knowledgebase_description = "A compilation of all knowledge related to the company's financial reimbursements."
283+
284+
res = client.create_knowledgebase(
285+
knowledgebase_name=knowledgebase_name,
286+
knowledgebase_description=knowledgebase_description
287+
)
288+
print(f"result: {res}")
289+
```
290+
262291
## 💬 Community & Support
263292

264293
Join our community to ask questions, share your projects, and connect with other developers.

docker/.env.example

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ MOS_TOP_K=50
2020
## Chat LLM (main dialogue)
2121
MOS_CHAT_MODEL=gpt-4o-mini
2222
MOS_CHAT_TEMPERATURE=0.8
23-
MOS_MAX_TOKENS=8000
23+
MOS_MAX_TOKENS=2048
2424
MOS_TOP_P=0.9
2525
MOS_CHAT_MODEL_PROVIDER=openai # openai | huggingface | vllm
2626
MOS_MODEL_SCHEMA=memos.configs.llm.VLLMLLMConfig # vllm only: config class path; keep default unless you extend it
@@ -51,9 +51,18 @@ MOS_RERANKER_HEADERS_EXTRA= # extra headers, JSON string, e.g. {"A
5151
MOS_RERANKER_STRATEGY=single_turn
5252
MOS_RERANK_SOURCE= # optional rerank scope, e.g., history/stream/custom
5353

54+
55+
# External Services (for evaluation scripts)
56+
ZEP_API_KEY=your_zep_api_key_here
57+
MEM0_API_KEY=your_mem0_api_key_here
58+
MODEL=gpt-4o-mini
59+
EMBEDDING_MODEL=nomic-embed-text:latest
60+
5461
## Internet search & preference memory
5562
ENABLE_INTERNET=false
5663
BOCHA_API_KEY= # required if ENABLE_INTERNET=true
64+
XINYU_API_KEY=
65+
XINYU_SEARCH_ENGINE_ID=
5766
SEARCH_MODE=fast # fast | fine | mixture
5867
FAST_GRAPH=false
5968
BM25_CALL=false
@@ -90,7 +99,9 @@ NEO4J_URI=bolt://localhost:7687 # required when backend=neo4j*
9099
NEO4J_USER=neo4j # required when backend=neo4j*
91100
NEO4J_PASSWORD=12345678 # required when backend=neo4j*
92101
NEO4J_DB_NAME=neo4j # required for shared-db mode
93-
MOS_NEO4J_SHARED_DB=false
102+
MOS_NEO4J_SHARED_DB=true # if true, all users share one DB; if false, each user gets their own DB
103+
NEO4J_AUTO_CREATE=false # [IMPORTANT] set to false for Neo4j Community Edition
104+
NEO4J_USE_MULTI_DB=false # alternative to MOS_NEO4J_SHARED_DB (logic is inverse)
94105
QDRANT_HOST=localhost
95106
QDRANT_PORT=6333
96107
# For Qdrant Cloud / remote endpoint (takes priority if set):
@@ -121,6 +132,7 @@ POLAR_DB_USER=root
121132
POLAR_DB_PASSWORD=123456
122133
POLAR_DB_DB_NAME=shared_memos_db
123134
POLAR_DB_USE_MULTI_DB=false
135+
POLARDB_POOL_MAX_CONN=100
124136

125137
## Redis (scheduler queue) — fill only if you want scheduler queues in Redis; otherwise in-memory queue is used
126138
REDIS_HOST=localhost # global Redis endpoint (preferred over MEMSCHEDULER_*)
@@ -170,3 +182,11 @@ OSS_PUBLIC_BASE_URL=
170182
## SDK / external client
171183
MEMOS_API_KEY=
172184
MEMOS_BASE_URL=https://memos.memtensor.cn/api/openmem/v1
185+
186+
CHAT_MODEL_LIST='[{
187+
"backend": "deepseek",
188+
"api_base": "http://localhost:1234",
189+
"api_key": "your-api-key",
190+
"model_name_or_path": "deepseek-r1",
191+
"support_models": ["deepseek-r1"]
192+
}]'

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ ENV PYTHONPATH=/app/src
3232
EXPOSE 8000
3333

3434
# Start the docker
35-
CMD ["uvicorn", "memos.api.product_api:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
35+
CMD ["uvicorn", "memos.api.server_api:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]

0 commit comments

Comments
 (0)