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

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


The following commit(s) were added to refs/heads/graph-query by this push:
     new f3c27aa  refactor(llm): enhance a string of graph query method
f3c27aa is described below

commit f3c27aaa5cfe2318f863afd534c2e3b2b5076df6
Author: imbajin <[email protected]>
AuthorDate: Fri Sep 27 23:30:26 2024 +0800

    refactor(llm): enhance a string of graph query method
---
 .../src/hugegraph_llm/demo/gremlin_generate_web_demo.py      |  4 ++--
 .../src/hugegraph_llm/demo/rag_demo/configs_block.py         |  8 ++++----
 .../hugegraph_llm/operators/hugegraph_op/graph_rag_query.py  | 12 ++++++++----
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/hugegraph-llm/src/hugegraph_llm/demo/gremlin_generate_web_demo.py 
b/hugegraph-llm/src/hugegraph_llm/demo/gremlin_generate_web_demo.py
index 1ba7aba..6166321 100644
--- a/hugegraph-llm/src/hugegraph_llm/demo/gremlin_generate_web_demo.py
+++ b/hugegraph-llm/src/hugegraph_llm/demo/gremlin_generate_web_demo.py
@@ -91,7 +91,7 @@ if __name__ == '__main__':
                     ]
             else:
                 llm_config_input = []
-            llm_config_button = gr.Button("apply configuration")
+            llm_config_button = gr.Button("Apply Configuration")
 
             def apply_configuration(arg1, arg2, arg3, arg4):
                 llm_option = settings.llm_type
@@ -139,7 +139,7 @@ if __name__ == '__main__':
                     ]
             else:
                 embedding_config_input = []
-            embedding_config_button = gr.Button("apply configuration")
+            embedding_config_button = gr.Button("Apply Configuration")
 
             def apply_configuration(arg1, arg2, arg3):
                 embedding_option = settings.embedding_type
diff --git a/hugegraph-llm/src/hugegraph_llm/demo/rag_demo/configs_block.py 
b/hugegraph-llm/src/hugegraph_llm/demo/rag_demo/configs_block.py
index c3ef73c..b289482 100644
--- a/hugegraph-llm/src/hugegraph_llm/demo/rag_demo/configs_block.py
+++ b/hugegraph-llm/src/hugegraph_llm/demo/rag_demo/configs_block.py
@@ -192,7 +192,7 @@ def create_configs_block():
                 gr.Textbox(value=settings.graph_pwd, label="pwd", 
type="password"),
                 gr.Textbox(value=settings.graph_space, 
label="graphspace(Optional)"),
             ]
-        graph_config_button = gr.Button("Apply config")
+        graph_config_button = gr.Button("Apply Configuration")
     graph_config_button.click(apply_graph_config, inputs=graph_config_input)  
# pylint: disable=no-member
 
     with gr.Accordion("2. Set up the LLM.", open=False):
@@ -227,7 +227,7 @@ def create_configs_block():
                     ]
             else:
                 llm_config_input = []
-            llm_config_button = gr.Button("apply configuration")
+            llm_config_button = gr.Button("Apply Configuration")
             llm_config_button.click(apply_llm_config, inputs=llm_config_input) 
 # pylint: disable=no-member
 
     with gr.Accordion("3. Set up the Embedding.", open=False):
@@ -262,7 +262,7 @@ def create_configs_block():
             else:
                 embedding_config_input = []
 
-            embedding_config_button = gr.Button("apply configuration")
+            embedding_config_button = gr.Button("Apply Configuration")
 
             # Call the separate apply_embedding_configuration function here
             embedding_config_button.click(  # pylint: disable=no-member
@@ -299,7 +299,7 @@ def create_configs_block():
                     ]
             else:
                 reranker_config_input = []
-            reranker_config_button = gr.Button("apply configuration")
+            reranker_config_button = gr.Button("Apply Configuration")
 
             # TODO: use "gr.update()" or other way to update the config in 
time (refactor the click event)
             # Call the separate apply_reranker_configuration function here
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 eb90684..9feb48b 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
@@ -30,8 +30,9 @@ VERTEX_QUERY_TPL = "g.V({keywords}).as('subj').toList()"
 ID_QUERY_NEIGHBOR_TPL = """
 g.V({keywords}).as('subj')
 .repeat(
-   bothE({edge_labels}).as('rel').otherV().as('obj')
-).times({max_deep})
+   
bothE({edge_labels}).limit({edge_limit}).as('rel').otherV().dedup().as('obj')
+).times({max_deep}).emit()
+.simplePath()
 .path()
 .by(project('label', 'id', 'props')
    .by(label())
@@ -71,7 +72,7 @@ g.V().has('{prop}', within({keywords})).as('subj')
 
 class GraphRAGQuery:
 
-    def __init__(self, max_deep: int = 2, max_items: int = 30, prop_to_match: 
Optional[str] = None):
+    def __init__(self, max_deep: int = 2, max_items: int = 20, prop_to_match: 
Optional[str] = None):
         self._client = PyHugeClient(
             settings.graph_ip,
             settings.graph_port,
@@ -112,6 +113,8 @@ class GraphRAGQuery:
 
         _, edge_labels = self._extract_labels_from_schema()
         edge_labels_str = ",".join("'" + label + "'" for label in edge_labels)
+        # TODO: enhance the limit logic later
+        edge_limit_amount = len(edge_labels) * 10
 
         use_id_to_match = self._prop_to_match is None
         if use_id_to_match:
@@ -126,8 +129,9 @@ class GraphRAGQuery:
             gremlin_query = ID_QUERY_NEIGHBOR_TPL.format(
                 keywords=match_vids,
                 max_deep=self._max_deep,
-                max_items=self._max_items,
                 edge_labels=edge_labels_str,
+                edge_limit=edge_limit_amount,
+                max_items=self._max_items,
             )
             log.debug("Kneighbor query: %s", gremlin_query)
 

Reply via email to