Skip to content

Commit 300ca15

Browse files
committed
feat:vllm llm support version0
2 parents 036a99f + 5c3164a commit 300ca15

35 files changed

+4835
-832
lines changed

.gitignore

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

189+
# auth file
190+
*_auth.yaml
191+
189192
# PyCharm
190193
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
191194
# 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!

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",
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""
2+
Example demonstrating how to use MOSProduct for multi-user scenarios.
3+
"""
4+
5+
from memos.configs.mem_cube import GeneralMemCubeConfig
6+
from memos.configs.mem_os import MOSConfig
7+
from memos.mem_cube.general import GeneralMemCube
8+
from memos.mem_os.product import MOSProduct
9+
10+
11+
def get_config(user_name):
12+
openapi_config = {
13+
"model_name_or_path": "gpt-4o-mini",
14+
"temperature": 0.8,
15+
"max_tokens": 1024,
16+
"top_p": 0.9,
17+
"top_k": 50,
18+
"remove_think_prefix": True,
19+
"api_key": "your-api-key-here",
20+
"api_base": "https://api.openai.com/v1",
21+
}
22+
# Create a default configuration
23+
default_config = MOSConfig(
24+
user_id="root",
25+
chat_model={"backend": "openai", "config": openapi_config},
26+
mem_reader={
27+
"backend": "naive",
28+
"config": {
29+
"llm": {
30+
"backend": "openai",
31+
"config": openapi_config,
32+
},
33+
"embedder": {
34+
"backend": "ollama",
35+
"config": {
36+
"model_name_or_path": "nomic-embed-text:latest",
37+
},
38+
},
39+
},
40+
},
41+
enable_textual_memory=True,
42+
enable_activation_memory=False,
43+
top_k=5,
44+
max_turns_window=20,
45+
)
46+
default_cube_config = GeneralMemCubeConfig.model_validate(
47+
{
48+
"user_id": user_name,
49+
"cube_id": f"{user_name}_default_cube",
50+
"text_mem": {
51+
"backend": "tree_text",
52+
"config": {
53+
"extractor_llm": {"backend": "openai", "config": openapi_config},
54+
"dispatcher_llm": {"backend": "openai", "config": openapi_config},
55+
"graph_db": {
56+
"backend": "neo4j",
57+
"config": {
58+
"uri": "bolt://localhost:7687",
59+
"user": "neo4j",
60+
"password": "12345678",
61+
"db_name": user_name,
62+
"auto_create": True,
63+
},
64+
},
65+
"embedder": {
66+
"backend": "ollama",
67+
"config": {
68+
"model_name_or_path": "nomic-embed-text:latest",
69+
},
70+
},
71+
},
72+
},
73+
"act_mem": {},
74+
"para_mem": {},
75+
}
76+
)
77+
default_mem_cube = GeneralMemCube(default_cube_config)
78+
return default_config, default_mem_cube
79+
80+
81+
def main():
82+
default_config, default_mem_cube = get_config(user_name="alice")
83+
# Initialize MOSProduct with default config
84+
mos_product = MOSProduct(default_config=default_config)
85+
86+
# Register first user with default config
87+
result1 = mos_product.user_register(
88+
user_id="alice",
89+
user_name="alice",
90+
interests="I'm interested in machine learning and AI research.",
91+
default_mem_cube=default_mem_cube,
92+
)
93+
print(f"User registration result: {result1}")
94+
95+
# Chat with Alice
96+
print("\n=== Chatting with Alice ===")
97+
for response_chunk in mos_product.chat(query="What are my interests?", user_id="alice"):
98+
print(response_chunk, end="")
99+
100+
# Add memory for Alice
101+
mos_product.add(
102+
user_id="alice",
103+
memory_content="I attended a machine learning conference last week.",
104+
mem_cube_id=result1["default_cube_id"],
105+
)
106+
107+
# Search memories for Alice
108+
search_result = mos_product.search(query="conference", user_id="alice")
109+
print(f"\nSearch result for Alice: {search_result}")
110+
111+
# Search memories for Alice
112+
search_result = mos_product.get_all(query="conference", user_id="alice", memory_type="text_mem")
113+
print(f"\nSearch result for Alice: {search_result}")
114+
115+
# List all users
116+
users = mos_product.list_users()
117+
print(f"\nAll registered users: {users}")
118+
119+
# Get user info
120+
alice_info = mos_product.get_user_info("alice")
121+
print(f"\nAlice's info: {alice_info}")
122+
123+
124+
if __name__ == "__main__":
125+
main()

0 commit comments

Comments
 (0)