|
3 | 3 | 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. |
4 | 4 |
|
5 | 5 | 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. |
8 | 6 | <div align="center"> |
9 | 7 | <a href="https://memos.openmem.net/"> |
10 | 8 | <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- |
117 | 115 | - **Textual Memory**: For storing and retrieving unstructured or structured text knowledge. |
118 | 116 | - **Activation Memory**: Caches key-value pairs (`KVCacheMemory`) to accelerate LLM inference and context reuse. |
119 | 117 | - **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. |
131 | 118 | - **🔌 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 |
135 | 119 |
|
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. |
212 | 120 |
|
213 | 121 | ## 📦 Installation |
214 | 122 |
|
@@ -259,6 +167,127 @@ To download example code, data and configurations, run the following command: |
259 | 167 | memos download_examples |
260 | 168 | ``` |
261 | 169 |
|
| 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 | + |
262 | 291 | ## 💬 Community & Support |
263 | 292 |
|
264 | 293 | Join our community to ask questions, share your projects, and connect with other developers. |
|
0 commit comments