From 9437df83cc628bd803cdf6298d920d42aaaee07e Mon Sep 17 00:00:00 2001 From: yangdx Date: Mon, 8 Sep 2025 15:56:35 +0800 Subject: [PATCH] Add memory management for pipeline history messages - Trim history at 10k messages - Keep latest 5k messages - Prevent memory growth - Add logging for trim events --- lightrag/lightrag.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index 67f82910..03699e08 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -1504,6 +1504,15 @@ class LightRAG: pipeline_status["latest_message"] = log_message pipeline_status["history_messages"].append(log_message) + # Prevent memory growth: keep only latest 5000 messages when exceeding 10000 + if len(pipeline_status["history_messages"]) > 10000: + pipeline_status["history_messages"] = ( + pipeline_status["history_messages"][-5000:] + ) + logger.info( + f"Trimming pipeline history from {len(pipeline_status['history_messages'])} to 5000 messages" + ) + # Get document content from full_docs content_data = await self.full_docs.get_by_id(doc_id) if not content_data: