File tree Expand file tree Collapse file tree 1 file changed +17
-20
lines changed
mcp_server/src/mcp_server_neo4j_gds Expand file tree Collapse file tree 1 file changed +17
-20
lines changed Original file line number Diff line number Diff line change @@ -679,27 +679,24 @@ def all_pairs_shortest_paths(self, **kwargs):
679679 if apsp_data .empty :
680680 return {"found" : False , "message" : "No shortest paths found" }
681681
682- # Convert to native Python types as needed
683- paths = []
684-
685- for _ , row in apsp_data .iterrows ():
686- source_id = int (row ["sourceNodeId" ])
687- target_id = int (row ["targetNodeId" ])
688- distance = float (row ["distance" ])
689-
690- # Get node names using GDS utility function
691- source_name = self .gds .util .asNode (source_id )
692- target_name = self .gds .util .asNode (target_id )
682+ # Get node names using GDS utility function (batch operation)
683+ apsp_data ["sourceNodeName" ] = self .gds .util .asNodes (
684+ apsp_data ["sourceNodeId" ].tolist ()
685+ )
686+ apsp_data ["targetNodeName" ] = self .gds .util .asNodes (
687+ apsp_data ["targetNodeId" ].tolist ()
688+ )
693689
694- paths .append (
695- {
696- "sourceNodeId" : source_id ,
697- "targetNodeId" : target_id ,
698- "sourceNodeName" : source_name ,
699- "targetNodeName" : target_name ,
700- "distance" : distance ,
701- }
702- )
690+ # Convert to list of dictionaries
691+ paths = apsp_data [
692+ [
693+ "sourceNodeId" ,
694+ "targetNodeId" ,
695+ "sourceNodeName" ,
696+ "targetNodeName" ,
697+ "distance" ,
698+ ]
699+ ].to_dict ("records" )
703700
704701 return {
705702 "found" : True ,
You can’t perform that action at this time.
0 commit comments