imbajin commented on code in PR #301:
URL: 
https://github.com/apache/incubator-hugegraph-ai/pull/301#discussion_r2447068804


##########
hugegraph-llm/src/hugegraph_llm/flows/build_vector_index.py:
##########
@@ -0,0 +1,55 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+from hugegraph_llm.flows.common import BaseFlow
+from hugegraph_llm.state.ai_state import WkFlowInput
+
+import json
+from PyCGraph import GPipeline
+
+from hugegraph_llm.operators.document_op.chunk_split import ChunkSplitNode
+from hugegraph_llm.operators.index_op.build_vector_index import 
BuildVectorIndexNode
+from hugegraph_llm.state.ai_state import WkFlowState
+
+
+class BuildVectorIndexFlow(BaseFlow):
+    def __init__(self):
+        pass
+
+    def prepare(self, prepared_input: WkFlowInput, texts):

Review Comment:
   ‼️ **Critical: Hardcoded configuration breaks flexibility**
   
   The `prepare` method hardcodes `language = "zh"` (Chinese) and `split_type = 
"paragraph"`. This contradicts the PR's goal of "flexible and extensible 
workflow scheduling."
   
   **Issues:**
   1. Non-Chinese users cannot use this flow without code modification
   2. No way to customize split strategy for different document types
   3. Breaks the principle of configuration over convention
   
   **Recommendation:**
   Make these configurable parameters:
   ```python
   def prepare(self, prepared_input: WkFlowInput, texts, language="zh", 
split_type="paragraph"):
       prepared_input.texts = texts
       prepared_input.language = language
       prepared_input.split_type = split_type
   ```



##########
hugegraph-llm/src/hugegraph_llm/flows/scheduler.py:
##########
@@ -0,0 +1,90 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+import threading
+from typing import Dict, Any
+from PyCGraph import GPipelineManager
+from hugegraph_llm.flows.build_vector_index import BuildVectorIndexFlow
+from hugegraph_llm.flows.common import BaseFlow
+from hugegraph_llm.flows.graph_extract import GraphExtractFlow
+from hugegraph_llm.utils.log import log
+
+
+class Scheduler:
+    pipeline_pool: Dict[str, Any] = None
+    max_pipeline: int
+
+    def __init__(self, max_pipeline: int = 10):
+        self.pipeline_pool = {}
+        # pipeline_pool act as a manager of GPipelineManager which used for 
pipeline management
+        self.pipeline_pool["build_vector_index"] = {
+            "manager": GPipelineManager(),
+            "flow": BuildVectorIndexFlow(),
+        }
+        self.pipeline_pool["graph_extract"] = {
+            "manager": GPipelineManager(),
+            "flow": GraphExtractFlow(),
+        }
+        self.max_pipeline = max_pipeline
+
+    # TODO: Implement Agentic Workflow
+    def agentic_flow(self):
+        pass
+
+    def schedule_flow(self, flow: str, *args, **kwargs):
+        if flow not in self.pipeline_pool:
+            raise ValueError(f"Unsupported workflow {flow}")
+        manager = self.pipeline_pool[flow]["manager"]
+        flow: BaseFlow = self.pipeline_pool[flow]["flow"]
+        pipeline = manager.fetch()
+        if pipeline is None:
+            # call coresponding flow_func to create new workflow
+            pipeline = flow.build_flow(*args, **kwargs)

Review Comment:
   ‼️ **Critical: Incomplete error recovery logic**
   
   When `pipeline.init()` or `pipeline.run()` fails, the code raises an 
exception but never calls `manager.add(pipeline)` to return the pipeline to the 
pool. This creates a **resource leak** where failed pipelines are never 
recycled.
   
   **Impact:** After `max_pipeline` failures, the system runs out of pipelines 
and cannot process new requests.
   
   **Recommendation:**
   Use try-finally to ensure pipelines are always returned:
   ```python
   pipeline = flow.build_flow(*args, **kwargs)
   try:
       status = pipeline.init()
       if status.isErr():
           raise RuntimeError(f"Error in flow init: {status.getInfo()}")
       status = pipeline.run()
       if status.isErr():
           raise RuntimeError(f"Error in flow execution: {status.getInfo()}")
       res = flow.post_deal(pipeline)
       return res
   finally:
       manager.add(pipeline)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to