Skip to content

Commit 5dab4f1

Browse files
tangg555CaralHsi
andauthored
Refactor: Conflict resolution, bug fixes mainly for the mem scheduler (#221)
* rebase to address conflicts * fix bugs: fix a bug in retriever, and add new auth info for neo4j db * fix bugs & new feat: fix bugs in mem_scheduler examples, and remove initialize working memories (logically uneccessary). change the function parameters of search as the function input info as an addition * fix bugs: modify configs, examples, schedule handlers of mem_scheduler, and rename some variables * modify datetime to utc date time --------- Co-authored-by: CaralHsi <[email protected]>
1 parent c1e1a85 commit 5dab4f1

27 files changed

+250
-154
lines changed

evaluation/scripts/run_locomo_eval.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ VERSION="072001"
66
WORKERS=10
77
TOPK=20
88

9-
# echo "Running locomo_ingestion.py..."
10-
# CUDA_VISIBLE_DEVICES=0 python scripts/locomo/locomo_ingestion.py --lib $LIB --version $VERSION --workers $WORKERS
11-
# if [ $? -ne 0 ]; then
12-
# echo "Error running locomo_ingestion.py"
13-
# exit 1
14-
# fi
9+
echo "Running locomo_ingestion.py..."
10+
CUDA_VISIBLE_DEVICES=0 python scripts/locomo/locomo_ingestion.py --lib $LIB --version $VERSION --workers $WORKERS
11+
if [ $? -ne 0 ]; then
12+
echo "Error running locomo_ingestion.py"
13+
exit 1
14+
fi
1515

1616
echo "Running locomo_search.py..."
1717
CUDA_VISIBLE_DEVICES=0 python scripts/locomo/locomo_search.py --lib $LIB --version $VERSION --top_k $TOPK --workers $WORKERS
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
backend: general_scheduler
22
config:
33
top_k: 10
4-
top_n: 10
54
act_mem_update_interval: 30
65
context_window_size: 10
76
thread_pool_max_workers: 5
87
consume_interval_seconds: 1
8+
working_mem_monitor_capacity: 20
9+
activation_mem_monitor_capacity: 5
910
enable_parallel_dispatch: true
11+
enable_activation_memory: true

examples/data/config/mem_scheduler/mem_chat_config.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

examples/data/config/mem_scheduler/memos_config_w_scheduler.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ mem_scheduler:
3333
backend: "general_scheduler"
3434
config:
3535
top_k: 10
36-
top_n: 10
3736
act_mem_update_interval: 30
3837
context_window_size: 10
3938
thread_pool_max_workers: 10
4039
consume_interval_seconds: 1
40+
working_mem_monitor_capacity: 20
41+
activation_mem_monitor_capacity: 5
4142
enable_parallel_dispatch: true
43+
enable_activation_memory: true
4244
max_turns_window: 20
4345
top_k: 5
4446
enable_textual_memory: true

examples/data/config/mem_scheduler/memos_config_w_scheduler_and_openai.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ mem_scheduler:
3535
backend: "general_scheduler"
3636
config:
3737
top_k: 10
38-
top_n: 10
3938
act_mem_update_interval: 30
4039
context_window_size: 10
4140
thread_pool_max_workers: 10
4241
consume_interval_seconds: 1
42+
working_mem_monitor_capacity: 20
43+
activation_mem_monitor_capacity: 5
4344
enable_parallel_dispatch: true
44-
enable_act_memory_update: false
45+
enable_activation_memory: true
4546
max_turns_window: 20
4647
top_k: 5
4748
enable_textual_memory: true

examples/data/config/mem_scheduler/memos_config_wo_scheduler.yaml

Lines changed: 0 additions & 37 deletions
This file was deleted.

examples/mem_os/chat_w_scheduler.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,61 @@
11
import shutil
2-
import uuid
2+
import sys
33

44
from pathlib import Path
55

66
from memos.configs.mem_cube import GeneralMemCubeConfig
77
from memos.configs.mem_os import MOSConfig
8+
from memos.configs.mem_scheduler import AuthConfig
89
from memos.mem_cube.general import GeneralMemCube
910
from memos.mem_os.main import MOS
10-
from memos.mem_scheduler.utils.misc_utils import parse_yaml
1111

1212

13-
# init MOS
14-
config = parse_yaml("./examples/data/config/mem_scheduler/memos_config_w_scheduler.yaml")
13+
FILE_PATH = Path(__file__).absolute()
14+
BASE_DIR = FILE_PATH.parent.parent.parent
15+
sys.path.insert(0, str(BASE_DIR)) # Enable execution from any working directory
1516

16-
mos_config = MOSConfig(**config)
17-
mos = MOS(mos_config)
1817

19-
# create user
20-
user_id = str(uuid.uuid4())
21-
mos.create_user(user_id=user_id)
18+
# set configs
19+
mos_config = MOSConfig.from_yaml_file(
20+
f"{BASE_DIR}/examples/data/config/mem_scheduler/memos_config_w_scheduler_and_openai.yaml"
21+
)
2222

23-
config = GeneralMemCubeConfig.from_yaml_file(
24-
"./examples/data/config/mem_scheduler/mem_cube_config.yaml"
23+
mem_cube_config = GeneralMemCubeConfig.from_yaml_file(
24+
f"{BASE_DIR}/examples/data/config/mem_scheduler/mem_cube_config.yaml"
2525
)
26+
27+
# default local graphdb uri
28+
if AuthConfig.default_config_exists():
29+
auth_config = AuthConfig.from_local_config()
30+
31+
mos_config.mem_reader.config.llm.config.api_key = auth_config.openai.api_key
32+
mos_config.mem_reader.config.llm.config.api_base = auth_config.openai.base_url
33+
34+
mem_cube_config.text_mem.config.graph_db.config.uri = auth_config.graph_db.uri
35+
mem_cube_config.text_mem.config.graph_db.config.user = auth_config.graph_db.user
36+
mem_cube_config.text_mem.config.graph_db.config.password = auth_config.graph_db.password
37+
mem_cube_config.text_mem.config.graph_db.config.db_name = auth_config.graph_db.db_name
38+
mem_cube_config.text_mem.config.graph_db.config.auto_create = auth_config.graph_db.auto_create
39+
40+
# Initialization
41+
mos = MOS(mos_config)
42+
43+
user_id = "user_1"
44+
mos.create_user(user_id)
45+
2646
mem_cube_id = "mem_cube_5"
27-
mem_cube_name_or_path = f"./outputs/mem_scheduler/{user_id}/{mem_cube_id}"
47+
mem_cube_name_or_path = f"{BASE_DIR}/outputs/mem_scheduler/{user_id}/{mem_cube_id}"
48+
2849
if Path(mem_cube_name_or_path).exists():
2950
shutil.rmtree(mem_cube_name_or_path)
3051
print(f"{mem_cube_name_or_path} is not empty, and has been removed.")
3152

32-
mem_cube = GeneralMemCube(config)
53+
mem_cube = GeneralMemCube(mem_cube_config)
3354
mem_cube.dump(mem_cube_name_or_path)
34-
3555
mos.register_mem_cube(
3656
mem_cube_name_or_path=mem_cube_name_or_path, mem_cube_id=mem_cube_id, user_id=user_id
3757
)
58+
3859
messages = [
3960
{"role": "user", "content": "I like playing football."},
4061
{"role": "assistant", "content": "I like playing football too."},
@@ -51,8 +72,3 @@
5172
for node in retrieved_memories["text_mem"][0]["memories"]["nodes"]:
5273
if node["metadata"]["memory_type"] == "WorkingMemory":
5374
print(f"🤖 [Assistant]working mem : {node['memory']}\n")
54-
if retrieved_memories["act_mem"][0]["memories"]:
55-
for act_mem in retrieved_memories["act_mem"][0]["memories"]:
56-
print(f"🤖 [Assistant]act_mem: {act_mem['memory']}\n")
57-
else:
58-
print("🤖 [Assistant]act_mem: None\n")

examples/mem_scheduler/memos_w_scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def run_with_scheduler_init():
8585

8686
# default local graphdb uri
8787
if AuthConfig.default_config_exists():
88-
auth_config = AuthConfig.from_local_yaml()
88+
auth_config = AuthConfig.from_local_config()
8989

9090
mos_config.mem_reader.config.llm.config.api_key = auth_config.openai.api_key
9191
mos_config.mem_reader.config.llm.config.api_base = auth_config.openai.base_url

examples/mem_scheduler/memos_w_scheduler_for_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def init_task():
9797

9898
# default local graphdb uri
9999
if AuthConfig.default_config_exists():
100-
auth_config = AuthConfig.from_local_yaml()
100+
auth_config = AuthConfig.from_local_config()
101101

102102
mos_config.mem_reader.config.llm.config.api_key = auth_config.openai.api_key
103103
mos_config.mem_reader.config.llm.config.api_base = auth_config.openai.base_url

examples/mem_scheduler/rabbitmq_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def main():
2121
print("Please set configs for rabbitmq.")
2222
return
2323
else:
24-
rabbitmq_module.initialize_rabbitmq(config=AuthConfig.from_local_yaml().rabbitmq)
24+
rabbitmq_module.initialize_rabbitmq(config=AuthConfig.from_local_config().rabbitmq)
2525

2626
try:
2727
rabbitmq_module.wait_for_connection_ready()

0 commit comments

Comments
 (0)