Skip to content

Commit 5c3164a

Browse files
committed
Feature & Fix bugs: mem scheduler with rabbitmq and web log submission
* fix bug of message consuming * add a range of configs * support rabbitmq * add new docs for the beginner * add more examples
1 parent 4ab316c commit 5c3164a

File tree

21 files changed

+1253
-784
lines changed

21 files changed

+1253
-784
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ dmypy.json
185185
# Cython debug symbols
186186
cython_debug/
187187

188+
# auth file
189+
*_auth.yaml
190+
188191
# PyCharm
189192
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
190193
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Mem Scheduler Beginner's Guide
2+
3+
Welcome to the mem_scheduler tutorial!
4+
5+
mem_scheduler is a system for managing memory and conversation scheduling, consisting of:
6+
- Mem Cube: Stores and manages user memory data
7+
- Scheduler: Coordinates memory storage and retrieval processes
8+
- Dispatcher (Router): Trigger different memory reorganization strategies by checking messages from MemOS systems.
9+
- Message Queue Hub: Central communication backbone
10+
11+
Memory Scheduler is built to optimize memory when MemOS is running. Here are two approaches to initializing Memory Scheduler with MemOS.
12+
13+
An example code can be found in ```examples/mem_scheduler/schedule_w_memos.py```
14+
15+
## Configs for Initialization
16+
17+
Below is an example YAML configuration. You can find this in ```examples/data/config/mem_scheduler/memos_config_w_scheduler.yaml```
18+
19+
```
20+
user_id: "root"
21+
chat_model:
22+
backend: "huggingface"
23+
config:
24+
model_name_or_path: "Qwen/Qwen3-1.7B"
25+
temperature: 0.1
26+
remove_think_prefix: true
27+
max_tokens: 4096
28+
mem_reader:
29+
backend: "simple_struct"
30+
config:
31+
llm:
32+
backend: "ollama"
33+
config:
34+
model_name_or_path: "qwen3:0.6b"
35+
remove_think_prefix: true
36+
temperature: 0.8
37+
max_tokens: 1024
38+
top_p: 0.9
39+
top_k: 50
40+
embedder:
41+
backend: "ollama"
42+
config:
43+
model_name_or_path: "nomic-embed-text:latest"
44+
chunker:
45+
backend: "sentence"
46+
config:
47+
tokenizer_or_token_counter: "gpt2"
48+
chunk_size: 512
49+
chunk_overlap: 128
50+
min_sentences_per_chunk: 1
51+
mem_scheduler:
52+
backend: "general_scheduler"
53+
config:
54+
top_k: 10
55+
top_n: 5
56+
act_mem_update_interval: 300
57+
context_window_size: 5
58+
activation_mem_size: 1000
59+
thread_pool_max_workers: 10
60+
consume_interval_seconds: 3
61+
enable_parallel_dispatch: true
62+
max_turns_window: 20
63+
top_k: 5
64+
enable_textual_memory: true
65+
enable_activation_memory: true
66+
enable_parametric_memory: false
67+
enable_mem_scheduler: true
68+
```
69+
## Steps to Initialize with MemOS
70+
71+
### 1. Load config and initialize MOS
72+
```
73+
config = parse_yaml("./examples/data/config/mem_scheduler/memos_config_w_scheduler.yaml")
74+
mos_config = MOSConfig(**config)
75+
mos = MOS(mos_config)
76+
```
77+
### 2. Create a User
78+
```
79+
user_id = "user_1"
80+
mos.create_user(user_id)
81+
```
82+
### 3. Create and Register a Memory Cube
83+
```
84+
config = GeneralMemCubeConfig.from_yaml_file("mem_cube_config.yaml")
85+
mem_cube_id = "mem_cube_5"
86+
mem_cube = GeneralMemCube(config)
87+
mem_cube.dump(mem_cube_name_or_path)
88+
mos.register_mem_cube(mem_cube_name_or_path, mem_cube_id, user_id)
89+
```
90+
91+
## Run with MemOS
92+
93+
### 4. Add Conversations (transformed to memories) to Memory Cube
94+
```
95+
mos.add(conversations, user_id=user_id, mem_cube_id=mem_cube_id)
96+
```
97+
98+
### 5. Scheduler with the chat function of MemOS
99+
```
100+
for item in questions:
101+
query = item["question"]
102+
response = mos.chat(query, user_id=user_id)
103+
print(f"Query:\n {query}\n\nAnswer:\n {response}")
104+
```
105+
### 6. Display Logs and Stop the Scheduler
106+
```
107+
show_web_logs(mos.mem_scheduler)
108+
mos.mem_scheduler.stop()
109+
```
110+
111+
## Check the Scheduling Info
112+
113+
This guide provides a foundational understanding of setting up and using mem_scheduler. Explore and modify configurations to suit your needs!

docs/modules/mem_scheduler.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ def init_task():
9595
]
9696
return conversations, questions
9797

98-
def show_web_logs(mem_scheduler: GeneralScheduler):
99-
# Display web logs generated by the scheduler
100-
# Includes memory operations, retrieval events, etc.
101-
10298
def run_with_automatic_scheduler_init():
10399
# Automatic initialization: Load configuration from YAML files
104100
# Create user and memory cube

examples/data/config/mem_scheduler/mem_cube_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ text_mem:
2020
graph_db:
2121
backend: "neo4j"
2222
config:
23-
uri: "bolt://123.57.48.226:7687"
23+
uri: "bolt://localhost:7687"
2424
user: "neo4j"
2525
password: "12345678"
2626
db_name: "user11alice"

examples/mem_os/chat_w_generated_cube_explicit_memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"graph_db": {
8585
"backend": "neo4j",
8686
"config": {
87-
"uri": "bolt://123.57.48.226:7687",
87+
"uri": "bolt://localhost:7687",
8888
"user": "neo4j",
8989
"password": "12345678",
9090
"db_name": "user03alice11",

0 commit comments

Comments
 (0)