Skip to content

Commit 4f9c568

Browse files
committed
fix(memory): add init backend before search memory
1 parent d55ad50 commit 4f9c568

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

veadk/memory/long_term_memory.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ async def add_session_to_memory(
203203
@override
204204
async def search_memory(self, *, app_name: str, user_id: str, query: str):
205205
# prevent model invoke `load_memory` before add session to this memory
206+
if not self._backend and isinstance(self.backend, str):
207+
self._index = build_long_term_memory_index(app_name, user_id)
208+
self._backend = _get_backend_cls(self.backend)(
209+
index=self._index, **self.backend_config if self.backend_config else {}
210+
)
211+
logger.info(
212+
f"Initialize long term memory backend now, index is {self._index}"
213+
)
214+
215+
if not self._index and self._index != build_long_term_memory_index(
216+
app_name, user_id
217+
):
218+
logger.warning(
219+
f"The `app_name` or `user_id` is different from the initialized one. Initialized index: {self._index}, current built index: {build_long_term_memory_index(app_name, user_id)}. Search memory return empty list."
220+
)
221+
return SearchMemoryResponse(memories=[])
222+
206223
if not self._backend:
207224
logger.error(
208225
"Long term memory backend is not initialized, cannot search memory."

0 commit comments

Comments
 (0)