memgraph/mage

neighbor algorithm cannot find nodes over 2 hops

Opened this issue · 7 comments

Memgraph version
2.12.1

Environment
memgraph running on docker

Describe the bug
I created a very simple graph that looks like this:
Screenshot 2023-12-07 at 6 38 58 PM
When running this query to find neighbors of Paper_id nodes:
"MATCH (p:Paper_id {id: "710.4637"})
CALL neighbors.at_hop(p, ["connected"], 1) YIELD nodes
RETURN nodes;"
I'm able to get the correct results.
Screenshot 2023-12-07 at 6 40 12 PM

However, when I try to get nodes that are 2 hops away, there was nothing returned.
If I use the results I found from the first hop, I'm able to get the results, this means that the edges are correctly created, yet I can't retrieve the results.

The "connected" relations are created using my csv files:
LOAD CSV FROM "/usr/work_space/data/csvs/author_edges.csv" WITH HEADER AS row
CREATE (n1:Paper_id {id: row.paper_id})-[:connected]->(n2:Author {id: row.author});

Hi @reggiehsu111 thanks for opening the issue.

This is expected, so the at_hop returns the nodes that are at specific hop from the node. In this case there is no nodes at 2 hops. Related at_hop docs
From docs:

Returns nodes that are at a specific distance from a given node, considering only the relationships of a specified type

We have by_hop this should return all relationships up to 2 hops.
From docs:

Returns nodes that are at any or up to a specific distance from a given node, considering only the relationships of a specified type.

Please let me know if this helps 🚀

Thanks for replying.
It doesn't work for both at_hop and by_hop.
Essentially I'm constructing a bipartite graph (Paper_id nodes <-> all other nodes). So when I start the algorithm from a single Paper_id node and set the hops to 2, I expect it to first hop on all other types of nodes, and then hop to a new group of Paper_id nodes that are 2 hops away from the original one. But currently it's returning nothing.

Both at_hop and by_hop only works with 1 hop on my data, and if I start from a node, and use it's direct neighbor as a starting point to run the 1-hop algorithm again, I'm still able to get another group of nodes which should be nodes that are 2 hops away from the original node. That means that I'm constructing the graph correctly, just somehow the algorithm couldn't find nodes that are more than 1 hop away.

Hi @reggiehsu111. I've tried testing out your issue and it seems to be working as expected. From the simple graph you provided, it's expected only to have nodes that are 1 hop away. Could you be able to provide us with the dataset of the bipartite graph you mentioned in order for me to try and replicate your issue?
One more thing, we've had some changes in the latest versions of Memgraph regarding the neighbors procedure, what version of Memgraph are you using?

I'd like to work on this is the issue is still open

Hi @garrett-mcclay, any contribution is more than welcome. Feel free to open a PR on mage repo when you're ready and link the issue it closes :)
Are you working on something with Memgraph that could use this feature?

Thanks for letting me contribute, and no I've just been interested in contributing to a project and this seemed like a good fit so I thought I would go for a smaller issue first. I do have a couple questions about this issue though, firstly did the original poster ever send the dataset they were using and if so can you send it to me because I'm having some difficulty recreating the issue

Unfortunately, I don't have a dataset, as you can see from few messages above, I had troubles replicating the issue myself. @reggiehsu111 could you help us out?