From 7fb9786241e22c9df170721b3b367193193b7657 Mon Sep 17 00:00:00 2001 From: LuiKlee Date: Tue, 16 Dec 2025 19:00:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(long=5Fterm=5Fmanager):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96embedding=E7=94=9F=E6=88=90=E9=98=9F=E5=88=97=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E9=81=BF=E5=85=8D=E8=87=AA?= =?UTF-8?q?=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/memory_graph/long_term_manager.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/memory_graph/long_term_manager.py b/src/memory_graph/long_term_manager.py index f7bb99c87..84fb6c701 100644 --- a/src/memory_graph/long_term_manager.py +++ b/src/memory_graph/long_term_manager.py @@ -1037,12 +1037,15 @@ class LongTermMemoryManager: async def _queue_embedding_generation(self, node_id: str, content: str) -> None: """将节点加入embedding生成队列""" + # 先在锁内写入,再在锁外触发批量处理,避免自锁 + should_flush = False async with self._embedding_lock: self._pending_embeddings.append((node_id, content)) - - # 如果队列达到批次大小,立即处理 if len(self._pending_embeddings) >= self._embedding_batch_size: - await self._flush_pending_embeddings() + should_flush = True + + if should_flush: + await self._flush_pending_embeddings() async def _flush_pending_embeddings(self) -> None: """批量处理待生成的embeddings"""