@@ -110,7 +110,7 @@ def __init__(
110
110
self ._gremlin_prompt = gremlin_prompt or prompt .gremlin_generate_prompt
111
111
112
112
def run (self , context : Dict [str , Any ]) -> Dict [str , Any ]:
113
- self ._init_client (context )
113
+ self .init_client (context )
114
114
115
115
# initial flag: -1 means no result, 0 means subgraph query, 1 means gremlin query
116
116
context ["graph_result_flag" ] = - 1
@@ -239,7 +239,9 @@ def _subgraph_query(self, context: Dict[str, Any]) -> Dict[str, Any]:
239
239
)
240
240
return context
241
241
242
- def _init_client (self , context ):
242
+ # TODO: move this method to a util file for reuse (remove self param)
243
+ def init_client (self , context ):
244
+ """Initialize the HugeGraph client from context or default settings."""
243
245
# pylint: disable=R0915 (too-many-statements)
244
246
if self ._client is None :
245
247
if isinstance (context .get ("graph_client" ), PyHugeClient ):
@@ -254,6 +256,15 @@ def _init_client(self, context):
254
256
self ._client = PyHugeClient (ip , port , graph , user , pwd , gs )
255
257
assert self ._client is not None , "No valid graph to search."
256
258
259
+ def get_vertex_details (self , vertex_ids : List [str ]) -> List [Dict [str , Any ]]:
260
+ if not vertex_ids :
261
+ return []
262
+
263
+ formatted_ids = ", " .join (f"'{ vid } '" for vid in vertex_ids )
264
+ gremlin_query = f"g.V({ formatted_ids } ).limit(20)"
265
+ result = self ._client .gremlin ().exec (gremlin = gremlin_query )["data" ]
266
+ return result
267
+
257
268
def _format_graph_from_vertex (self , query_result : List [Any ]) -> Set [str ]:
258
269
knowledge = set ()
259
270
for item in query_result :
@@ -374,8 +385,8 @@ def _extract_labels_from_schema(self) -> Tuple[List[str], List[str]]:
374
385
schema = self ._get_graph_schema ()
375
386
vertex_props_str , edge_props_str = schema .split ("\n " )[:2 ]
376
387
# TODO: rename to vertex (also need update in the schema)
377
- vertex_props_str = vertex_props_str [len ("Vertex properties: " ) :].strip ("[" ).strip ("]" )
378
- edge_props_str = edge_props_str [len ("Edge properties: " ) :].strip ("[" ).strip ("]" )
388
+ vertex_props_str = vertex_props_str [len ("Vertex properties: " ):].strip ("[" ).strip ("]" )
389
+ edge_props_str = edge_props_str [len ("Edge properties: " ):].strip ("[" ).strip ("]" )
379
390
vertex_labels = self ._extract_label_names (vertex_props_str )
380
391
edge_labels = self ._extract_label_names (edge_props_str )
381
392
return vertex_labels , edge_labels
0 commit comments