-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample4
More file actions
48 lines (38 loc) · 1.5 KB
/
example4
File metadata and controls
48 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from memos.configs.mem_cube import GeneralMemCubeConfig
from memos.configs.mem_os import MOSConfig
from memos.mem_cube.general import GeneralMemCube
from memos.mem_os.main import MOS
# 1. Setup CUDA (if needed) — for local GPU inference
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
# 2. Define user & paths
user_id = "root"
cube_id = "root/mem_cube_kv_cache"
tmp_cube_path = "/tmp/default/mem_cube_5"
# 3. Initialize MOSConfig
mos_config = MOSConfig.from_json_file("examples/data/config/simple_treekvcache_memos_config.json")
mos = MOS(mos_config)
# 4. Initialize the MemCube (TreeTextMemory + KVCacheMemory)
cube_config = GeneralMemCubeConfig.from_json_file(
"examples/data/config/simple_treekvcache_cube_config.json"
)
mem_cube = GeneralMemCube(cube_config)
# 5. Dump the MemCube to disk
try:
mem_cube.dump(tmp_cube_path)
except Exception as e:
print(e)
# 6. Register the MemCube explicitly
mos.register_mem_cube(tmp_cube_path, mem_cube_id=cube_id, user_id=user_id)
# 7. Extract and add a KVCache memory (simulate stable context)
extract_kvmem = mos.mem_cubes[cube_id].act_mem.extract("I like football")
mos.mem_cubes[cube_id].act_mem.add([extract_kvmem])
# 8. Start chatting — now your chat uses:
# - TreeTextMemory: for structured multi-hop retrieval
# - KVCacheMemory: for fast context injection
while True:
user_input = input("👤 [You] ").strip()
print()
response = mos.chat(user_input)
print(f"🤖 [Assistant] {response}\n")
print("📢 [System] MemChat has stopped.")