This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch graphspace
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-ai.git


The following commit(s) were added to refs/heads/graphspace by this push:
     new b5cd196  feat: support graphspace in rag demo
b5cd196 is described below

commit b5cd196f3df8cd36f520fcb136fda96731048774
Author: imbajin <[email protected]>
AuthorDate: Wed Aug 14 03:01:16 2024 +0800

    feat: support graphspace in rag demo
---
 hugegraph-llm/src/hugegraph_llm/config/config.py           |  2 +-
 hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py       | 14 ++++++++------
 hugegraph-llm/src/hugegraph_llm/indices/graph_index.py     |  3 ++-
 .../operators/hugegraph_op/commit_to_hugegraph.py          |  1 +
 .../operators/hugegraph_op/graph_rag_query.py              |  4 +++-
 .../hugegraph_llm/operators/hugegraph_op/schema_manager.py |  1 +
 hugegraph-llm/src/hugegraph_llm/utils/hugegraph_utils.py   |  2 ++
 .../src/pyhugegraph/utils/huge_config.py                   |  3 ++-
 8 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/hugegraph-llm/src/hugegraph_llm/config/config.py 
b/hugegraph-llm/src/hugegraph_llm/config/config.py
index 62d41d4..2e8ec2b 100644
--- a/hugegraph-llm/src/hugegraph_llm/config/config.py
+++ b/hugegraph-llm/src/hugegraph_llm/config/config.py
@@ -67,8 +67,8 @@ class Config:
     """HugeGraph settings"""
     graph_ip: Optional[str] = "127.0.0.1"
     graph_port: Optional[int] = 8080
-    # graph_space: Optional[str] = "DEFAULT"
     graph_name: Optional[str] = "hugegraph"
+    graph_space: Optional[str] = None
     graph_user: Optional[str] = "admin"
     graph_pwd: Optional[str] = "xxx"
 
diff --git a/hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py 
b/hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py
index 2c9bade..e349a3e 100644
--- a/hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py
+++ b/hugegraph-llm/src/hugegraph_llm/demo/rag_web_demo.py
@@ -169,9 +169,9 @@ if __name__ == "__main__":
                 gr.Textbox(value=settings.graph_ip, label="ip"),
                 gr.Textbox(value=str(settings.graph_port), label="port"),
                 gr.Textbox(value=settings.graph_name, label="graph"),
-                gr.Textbox(value=settings.graph_space, label="graphspace"),
                 gr.Textbox(value=settings.graph_user, label="user"),
-                gr.Textbox(value=settings.graph_pwd, label="pwd")
+                gr.Textbox(value=settings.graph_pwd, label="pwd"),
+                gr.Textbox(value=settings.graph_space, label="graphspace 
(None)"),
             ]
         graph_config_button = gr.Button("apply configuration")
 
@@ -196,16 +196,18 @@ if __name__ == "__main__":
                 gr.Error(f"Connection failed with status code: 
{response.status_code}")
 
 
-        def apply_graph_configuration(ip, port, name, gs, user, pwd):
+        def apply_graph_configuration(ip, port, name, user, pwd, gs):
             settings.graph_ip = ip
             settings.graph_port = int(port)
             settings.graph_name = name
-            settings.graph_space = gs
             settings.graph_user = user
             settings.graph_pwd = pwd
+            settings.graph_space = gs
             # Test graph connection (Auth)
-            test_url = 
f"http://{ip}:{port}/graphspaces/{gs}/graphs/{name}/schema";
-            # test_api_connection(test_url)
+            if gs and gs.strip():
+                test_url = 
f"http://{ip}:{port}/graphspaces/{gs}/graphs/{name}/schema";
+            else:
+                test_url = f"http://{ip}:{port}/graphs/{name}/schema";
             auth = HTTPBasicAuth(user, pwd)
             test_api_connection(test_url, auth=auth)
             settings.update_env()
diff --git a/hugegraph-llm/src/hugegraph_llm/indices/graph_index.py 
b/hugegraph-llm/src/hugegraph_llm/indices/graph_index.py
index 74269fc..f35d79d 100644
--- a/hugegraph-llm/src/hugegraph_llm/indices/graph_index.py
+++ b/hugegraph-llm/src/hugegraph_llm/indices/graph_index.py
@@ -28,10 +28,11 @@ class GraphIndex:
             graph_ip: Optional[str] = settings.graph_ip,
             graph_port: Optional[int] = settings.graph_port,
             graph_name: Optional[str] = settings.graph_name,
+            graph_space: Optional[str] = settings.graph_space,
             graph_user: Optional[str] = settings.graph_user,
             graph_pwd: Optional[str] = settings.graph_pwd,
     ):
-        self.client = PyHugeClient(graph_ip, graph_port, graph_name, 
graph_user, graph_pwd)
+        self.client = PyHugeClient(graph_ip, graph_port, graph_name, 
graph_user, graph_pwd, gs=graph_space)
 
     def clear_graph(self):
         self.client.gremlin().exec("g.V().drop()")
diff --git 
a/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/commit_to_hugegraph.py 
b/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/commit_to_hugegraph.py
index b4ad640..01718c3 100644
--- 
a/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/commit_to_hugegraph.py
+++ 
b/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/commit_to_hugegraph.py
@@ -32,6 +32,7 @@ class CommitToKg:
             settings.graph_name,
             settings.graph_user,
             settings.graph_pwd,
+            gs=settings.graph_space,
         )
         self.schema = self.client.schema()
 
diff --git 
a/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/graph_rag_query.py 
b/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/graph_rag_query.py
index 2c81ee0..ed61eff 100644
--- a/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/graph_rag_query.py
+++ b/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/graph_rag_query.py
@@ -81,6 +81,7 @@ class GraphRAGQuery:
             settings.graph_name,
             settings.graph_user,
             settings.graph_pwd,
+            gs=settings.graph_space,
         )
         self._max_deep = max_deep
         self._max_items = max_items
@@ -97,7 +98,8 @@ class GraphRAGQuery:
                 graph = context.get("graph") or "hugegraph"
                 user = context.get("user") or "admin"
                 pwd = context.get("pwd") or "admin"
-                self._client = PyHugeClient(ip=ip, port=port, graph=graph, 
user=user, pwd=pwd)
+                graphspace = context.get("graphspace") or settings.graph_space
+                self._client = PyHugeClient(ip=ip, port=port, graph=graph, 
user=user, pwd=pwd, gs=graphspace)
         assert self._client is not None, "No valid graph to search."
 
         keywords = context.get("keywords")
diff --git 
a/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/schema_manager.py 
b/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/schema_manager.py
index 78c06a5..cee6f59 100644
--- a/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/schema_manager.py
+++ b/hugegraph-llm/src/hugegraph_llm/operators/hugegraph_op/schema_manager.py
@@ -29,6 +29,7 @@ class SchemaManager:
             self.graph_name,
             settings.graph_user,
             settings.graph_pwd,
+            gs=settings.graph_space,
         )
         self.schema = self.client.schema()
 
diff --git a/hugegraph-llm/src/hugegraph_llm/utils/hugegraph_utils.py 
b/hugegraph-llm/src/hugegraph_llm/utils/hugegraph_utils.py
index d942bf9..1b829bd 100644
--- a/hugegraph-llm/src/hugegraph_llm/utils/hugegraph_utils.py
+++ b/hugegraph-llm/src/hugegraph_llm/utils/hugegraph_utils.py
@@ -25,6 +25,7 @@ def run_gremlin_query(query, format=False):
     return json.dumps(res, indent=4, ensure_ascii=False) if format else res
 
 
+# TODO: we should re-use the PyHugeClient rather than creating a new one every 
time
 def get_hg_client():
     return PyHugeClient(
         settings.graph_ip,
@@ -32,6 +33,7 @@ def get_hg_client():
         settings.graph_name,
         settings.graph_user,
         settings.graph_pwd,
+        gs=settings.graph_space,
     )
 
 
diff --git a/hugegraph-python-client/src/pyhugegraph/utils/huge_config.py 
b/hugegraph-python-client/src/pyhugegraph/utils/huge_config.py
index f7e00d9..7cc187c 100644
--- a/hugegraph-python-client/src/pyhugegraph/utils/huge_config.py
+++ b/hugegraph-python-client/src/pyhugegraph/utils/huge_config.py
@@ -37,8 +37,9 @@ class HGraphConfig:
 
     def __post_init__(self):
 
-        if self.graphspace is not None:
+        if self.graphspace is not None and self.graphspace.strip():
             self.gs_supported = True
+            print(f"Use gs request: graph space is set to '{self.graphspace}'")
 
         else:
             try:

Reply via email to