Dear Neo4j Community,
Is there a way to export an object with HeteroData
datatype in PyG into Neo4j workspace?
I want to visualize my graph, created from Yelp dataset for recommendation and farther steps like building HybridRAG or GraphRAG agents. Here is a part of my code:
# Create the graph
yelp_graph = HeteroData()
yelp_graph['restaurant'].x = restaurant_node_x
yelp_graph['user'].x = user_x
yelp_graph['user', 'reviews', 'restaurant'].edge_index = reviews_index
yelp_graph['user', 'reviews', 'restaurant'].edge_attr = reviews_attr
# Add the reverse edges from restaurants to users in order to let a GNN be able to pass messages in both directions
yelp_graph = ToUndirected()(yelp_graph)
yelp_graph
Output:
HeteroData(
restaurant={ x=[1161, 142] },
user={ x=[37170, 20] },
(user, reviews, restaurant)={
edge_index=[2, 52807],
edge_attr=[52807, 5],
},
(restaurant, rev_reviews, user)={
edge_index=[2, 52807],
edge_attr=[52807, 5],
}
)
# Transform data type
# Impute -- those restaurant without reviews will have 0 for sentiment and compliment count
yelp_graph['restaurant'].x = torch.nan_to_num(yelp_graph['restaurant'].x, nan=0.0)
yelp_graph['restaurant'].x = yelp_graph['restaurant'].x.type(torch.float32)
yelp_graph['user'].x = yelp_graph['user'].x.type(torch.float32)
yelp_graph['user', 'reviews', 'restaurant'].edge_attr = yelp_graph['user', 'reviews', 'restaurant'].edge_attr.type(torch.float32)
yelp_graph['restaurant', 'rev_reviews', 'user'].edge_attr = yelp_graph['restaurant', 'rev_reviews', 'user'].edge_attr.type(torch.float32)
I will be grateful for your assistance.