@@ -110,7 +110,7 @@ def __init__(
110110 self ._gremlin_prompt = gremlin_prompt or prompt .gremlin_generate_prompt
111111
112112 def run (self , context : Dict [str , Any ]) -> Dict [str , Any ]:
113- self ._init_client (context )
113+ self .init_client (context )
114114
115115 # initial flag: -1 means no result, 0 means subgraph query, 1 means gremlin query
116116 context ["graph_result_flag" ] = - 1
@@ -239,7 +239,9 @@ def _subgraph_query(self, context: Dict[str, Any]) -> Dict[str, Any]:
239239 )
240240 return context
241241
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."""
243245 # pylint: disable=R0915 (too-many-statements)
244246 if self ._client is None :
245247 if isinstance (context .get ("graph_client" ), PyHugeClient ):
@@ -254,6 +256,15 @@ def _init_client(self, context):
254256 self ._client = PyHugeClient (ip , port , graph , user , pwd , gs )
255257 assert self ._client is not None , "No valid graph to search."
256258
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+
257268 def _format_graph_from_vertex (self , query_result : List [Any ]) -> Set [str ]:
258269 knowledge = set ()
259270 for item in query_result :
@@ -374,8 +385,8 @@ def _extract_labels_from_schema(self) -> Tuple[List[str], List[str]]:
374385 schema = self ._get_graph_schema ()
375386 vertex_props_str , edge_props_str = schema .split ("\n " )[:2 ]
376387 # 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 ("]" )
379390 vertex_labels = self ._extract_label_names (vertex_props_str )
380391 edge_labels = self ._extract_label_names (edge_props_str )
381392 return vertex_labels , edge_labels
0 commit comments