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


##########
hugegraph-llm/src/hugegraph_llm/demo/rag_demo/configs_block.py:
##########
@@ -106,6 +106,83 @@ def test_api_connection(
     return resp.status_code
 
 
+def apply_vector_engine(engine: str):
+    # Persist the vector engine selection
+    setattr(index_settings, "cur_vector_index", engine)
+    try:
+        index_settings.update_env()
+    except Exception:  # pylint: disable=W0718
+        pass
+    gr.Info("Configured!")
+
+
+def apply_vector_engine_backend(  # pylint: disable=too-many-branches
+    engine: str,
+    host: Optional[str] = None,
+    port: Optional[str] = None,
+    user: Optional[str] = None,
+    password: Optional[str] = None,
+    api_key: Optional[str] = None,
+    origin_call=None,
+) -> int:
+    """Test connection and persist per-engine connection settings"""
+    status_code = -1
+
+    # Test connection first
+    try:
+        if engine == "Milvus":
+            from pymilvus import connections, utility
+
+            connections.connect(
+                host=host, port=int(port or 19530), user=user or "", 
password=password or ""
+            )
+            # Test if we can list collections
+            _ = utility.list_collections()
+            connections.disconnect("default")
+            status_code = 200
+        elif engine == "Qdrant":
+            from qdrant_client import QdrantClient
+
+            client = QdrantClient(host=host, port=int(port or 6333), 
api_key=api_key)
+            # Test if we can get collections
+            _ = client.get_collections()

Review Comment:
   ‼️ **业务逻辑问题**: `test_api_connection` 函数在连接失败时有不一致的行为。
   
   如果 `origin_call` 为 None,抛出 `gr.Error`;如果不为 None,只是返回 
-1。这种不一致的错误处理可能导致调用方难以处理错误情况。
   
   建议统一错误处理策略:
   ```python
   except ImportError as e:
       msg = f"Missing dependency: {e}. Please install with: uv sync --extra 
vectordb"
       log.error(msg)
       if origin_call is None:
           raise gr.Error(msg) from e
       return -1  # 或者定义明确的错误码常量
   ```



-- 
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