Skip to content

Commit 0990db6

Browse files
authored
Merge branch 'main' into hotfix/scheduler
2 parents 4ef6fec + 33fc280 commit 0990db6

File tree

5 files changed

+505
-274
lines changed

5 files changed

+505
-274
lines changed

README.md

Lines changed: 121 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -131,85 +131,6 @@ showcasing its capabilities in **information extraction**, **temporal and cross-
131131
- **🔌 Extensible**: Easily extend and customize memory modules, data sources, and LLM integrations.
132132
- **🏂 Lightweight Deployment** 🆕: Support for quick mode and complete mode deployment options.
133133

134-
## 🚀 Getting Started
135-
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-
213134
## 📦 Installation
214135

215136
### Install via pip
@@ -259,6 +180,126 @@ To download example code, data and configurations, run the following command:
259180
memos download_examples
260181
```
261182

183+
## 🚀 Getting Started
184+
185+
### ⭐️ MemOS online API
186+
The easiest way to use MemOS. Equip your agent with memory **in minutes**!
187+
188+
Sign up and get started on[`MemOS dashboard`](https://memos-dashboard.openmem.net/cn/quickstart/?source=landing).
189+
190+
191+
### Self-Hosted Server
192+
1. Get the repository.
193+
```bash
194+
git clone https://github.com/MemTensor/MemOS.git
195+
cd MemOS
196+
pip install -r ./docker/requirements.txt
197+
```
198+
199+
2. Configure `docker/.env.example` and copy to `MemOS/.env`
200+
3. Start the service.
201+
```bash
202+
uvicorn memos.api.server_api:app --host 0.0.0.0 --port 8001 --workers 8
203+
```
204+
205+
### Interface SDK
206+
#### Here is a quick example showing how to create interface SDK
207+
208+
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.
209+
```python
210+
# Please make sure MemoS is installed (pip install MemoryOS -U)
211+
from memos.api.client import MemOSClient
212+
213+
# Initialize the client using the API Key
214+
client = MemOSClient(api_key="YOUR_API_KEY")
215+
216+
messages = [
217+
{"role": "user", "content": "I have planned to travel to Guangzhou during the summer vacation. What chain hotels are available for accommodation?"},
218+
{"role": "assistant", "content": "You can consider [7 Days, All Seasons, Hilton], and so on."},
219+
{"role": "user", "content": "I'll choose 7 Days"},
220+
{"role": "assistant", "content": "Okay, ask me if you have any other questions."}
221+
]
222+
user_id = "memos_user_123"
223+
conversation_id = "0610"
224+
res = client.add_message(messages=messages, user_id=user_id, conversation_id=conversation_id)
225+
226+
print(f"result: {res}")
227+
```
228+
229+
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'.
230+
```python
231+
# Please make sure MemoS is installed (pip install MemoryOS -U)
232+
from memos.api.client import MemOSClient
233+
234+
# Initialize the client using the API Key
235+
client = MemOSClient(api_key="YOUR_API_KEY")
236+
237+
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?"
238+
user_id = "memos_user_123"
239+
conversation_id = "0928"
240+
res = client.search_memory(query=query, user_id=user_id, conversation_id=conversation_id)
241+
242+
print(f"result: {res}")
243+
```
244+
245+
This interface is used to delete the memory of specified users and supports batch deletion.
246+
```python
247+
# Please make sure MemoS is installed (pip install MemoryOS -U)
248+
from memos.api.client import MemOSClient
249+
250+
# Initialize the client using the API Key
251+
client = MemOSClient(api_key="YOUR_API_KEY")
252+
253+
user_ids = ["memos_user_123"]
254+
# Replace with the memory ID
255+
memory_ids = ["6b23b583-f4c4-4a8f-b345-58d0c48fea04"]
256+
res = client.delete_memory(user_ids=user_ids, memory_ids=memory_ids)
257+
258+
print(f"result: {res}")
259+
```
260+
261+
This interface is used to add feedback to messages in the current session, allowing MemOS to correct its memory based on user feedback.
262+
```python
263+
# Please make sure MemoS is installed (pip install MemoryOS -U)
264+
from memos.api.client import MemOSClient
265+
266+
# Initialize the client using the API Key
267+
client = MemOSClient(api_key="YOUR_API_KEY")
268+
269+
user_id = "memos_user_123"
270+
conversation_id = "memos_feedback_conv"
271+
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."
272+
# Replace with the knowledgebase ID
273+
allow_knowledgebase_ids = ["basee5ec9050-c964-484f-abf1-ce3e8e2aa5b7"]
274+
275+
res = client.add_feedback(
276+
user_id=user_id,
277+
conversation_id=conversation_id,
278+
feedback_content=feedback_content,
279+
allow_knowledgebase_ids=allow_knowledgebase_ids
280+
)
281+
282+
print(f"result: {res}")
283+
```
284+
285+
This interface is used to create a knowledgebase associated with a project
286+
```python
287+
# Please make sure MemoS is installed (pip install MemoryOS -U)
288+
from memos.api.client import MemOSClient
289+
290+
# Initialize the client using the API Key
291+
client = MemOSClient(api_key="YOUR_API_KEY")
292+
293+
knowledgebase_name = "Financial Reimbursement Knowledge Base"
294+
knowledgebase_description = "A compilation of all knowledge related to the company's financial reimbursements."
295+
296+
res = client.create_knowledgebase(
297+
knowledgebase_name=knowledgebase_name,
298+
knowledgebase_description=knowledgebase_description
299+
)
300+
print(f"result: {res}")
301+
```
302+
262303
## 💬 Community & Support
263304

264305
Join our community to ask questions, share your projects, and connect with other developers.
@@ -316,4 +357,4 @@ We welcome contributions from the community! Please read our [contribution guide
316357

317358
## 📄 License
318359

319-
MemOS is licensed under the [Apache 2.0 License](./LICENSE).
360+
MemOS is licensed under the [Apache 2.0 License](./LICENSE).

0 commit comments

Comments
 (0)