Skip to content

Commit fc4817a

Browse files
authored
Merge pull request #90 from camaze/redis_persist_cjn
【CodeFuse】redis data persistence
2 parents cbf73a0 + 98d3b0b commit fc4817a

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

docker-compose.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,13 @@ services:
114114
- "8001:8001"
115115
volumes:
116116
- ./logs/redis:/var/lib/redis/logs
117+
- ./examples/redis-stack.conf:/redis-stack.conf
118+
- ./data/redis:/data
117119
networks:
118120
- ekg-net
119121
restart: always
122+
healthcheck:
123+
test: [ "CMD", "redis-cli", "--raw", "incr", "ping" ]
120124

121125

122126
ollama:
@@ -201,7 +205,7 @@ services:
201205
restart: on-failure
202206
networks:
203207
- ekg-net
204-
command: sh -c "uvicorn start:app --reload --reload-dir /home/user/muagent/examples --reload-dir /home/user/muagent/muagent --port=3737 --host=0.0.0.0"
208+
command: sh -c "uvicorn start:app --reload --reload-dir /home/user/muagent/examples --reload-dir /home/user/muagent/muagent --reload-exclude */test_config.py --port=3737 --host=0.0.0.0"
205209

206210
ekgfrontend:
207211
build:

examples/ekg_examples/start.py

+2
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,14 @@ def embed_query(self, text: str) -> List[float]:
273273
# )
274274
embed_config = None
275275

276+
clear_history_data = os.environ.get('clear_history_data', 'False') == 'True'
276277

277278
ekg_construct_service = EKGConstructService(
278279
embed_config=embed_config,
279280
llm_config=llm_config,
280281
tb_config=tb_config,
281282
gb_config=gb_config,
283+
clear_history_data=clear_history_data
282284
)
283285

284286

examples/redis-stack.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# https://redis.io/docs/latest/operate/oss_and_stack/management/config-file/
2+
3+
# disable rdb
4+
save ""
5+
6+
# aof config
7+
appendonly yes
8+
appendfsync everysec
9+
auto-aof-rewrite-min-size 8mb

examples/test_config.py.example

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ os.environ["tb_index_name"] = "ekg_migration_new"
4141
os.environ['tb_definition_value'] = 'message_test_new'
4242
os.environ['tb_expire_time'] = '604800' #86400*7
4343

44+
# clear history data in tb and gb
45+
os.environ['clear_history_data'] = 'True'
4446

4547

4648
########################################

muagent/service/ekg_construct/ekg_construct_base.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def __init__(
6262
intention_router: Optional[IntentionRouter] = None,
6363
do_init: bool = False,
6464
kb_root_path: str = KB_ROOT_PATH,
65-
initialize_space=True
65+
initialize_space=True,
66+
clear_history_data=True
6667
):
6768

6869
self.db_config = db_config
@@ -83,6 +84,7 @@ def __init__(
8384
self.model, embed_config=self.embed_config)
8485
# init db handler
8586
self.initialize_space = initialize_space
87+
self.clear_history_data = clear_history_data
8688
self.init_handler()
8789
# load custom keywords
8890
if os.path.exists(EXTRA_KEYWORDS_PATH):
@@ -138,7 +140,6 @@ def init_tb(self, do_init: bool=None):
138140
TextField("ekg_type",),
139141
]
140142

141-
142143
if self.tb_config:
143144
tb_dict = {"TbaseHandler": TbaseHandler}
144145
tb_class = tb_dict.get(self.tb_config.tb_type, TbaseHandler)
@@ -148,6 +149,11 @@ def init_tb(self, do_init: bool=None):
148149
definition_value=self.tb_config.extra_kwargs.get(
149150
"definition_value", "muagent_ekg")
150151
)
152+
153+
if self.clear_history_data:
154+
self.tb.drop_index(self.node_indexname)
155+
self.tb.drop_index(self.edge_indexname)
156+
151157
# # create index
152158
if not self.tb.is_index_exists(self.node_indexname):
153159
res = self.tb.create_index(
@@ -176,8 +182,11 @@ def init_gb(self, do_init: bool=None):
176182
self.gb.add_hosts('storaged0', 9779)
177183
print('增加NebulaGraph Storage主机中,等待20秒')
178184
time.sleep(20)
179-
# 初始化space
180-
self.gb.drop_space('client')
185+
186+
if self.clear_history_data:
187+
# 初始化space
188+
self.gb.drop_space('client')
189+
181190
self.gb.create_space('client')
182191

183192
# 创建node tags和edge types

0 commit comments

Comments
 (0)