Mayil-AI-Sandbox / kuzudb_jan15

MIT License
0 stars 0 forks source link

Parse all paths between two nodes (hashtag2665) #57

Open vikramsubramanian opened 7 months ago

vikramsubramanian commented 7 months ago

Hello,

I have a question on how to get all possible paths between two nodes. I have the following graph:

      nB - nC
    /         \
  nA           nF
    \         /
      nG - nE

I want to get all possible paths between nodes nA and nC which are:

Based on the documentation, I found how to get the shortest path (path 1):

MATCH p = (s:Vertex {name:"nA"})-[r:Relation * ALL SHORTEST]-(t:Vertex {name: "nC"})
RETURN properties(nodes(p), 'name') AS name, properties(rels(p), 'info') AS info;

I thought that by removing ALL SHORTEST I would get all possible paths (path 1 and path 2):

MATCH p = (s:Vertex {name:"nA"})-[r:Relation *]-(t:Vertex {name: "nC"})
RETURN properties(nodes(p), 'name') AS name, properties(rels(p), 'info') AS info;

but this query raises the exception:

RuntimeError: Buffer manager exception: Failed to claim a frame.

You have an example in the documentation on how to parse all direct and indirect paths, but I find that example too complicated. Could you provide some guidelines on how to parse all paths between nodes nA and nC in this simple example?

Thank you in advance.

)

mayil-ai[bot] commented 7 months ago

To retrieve all possible paths between two nodes nA and nC in Kùzu, you can use a Cypher-like query that does not limit the path length or specify the shortest path. However, the error you encountered (RuntimeError: Buffer manager exception: Failed to claim a frame.) suggests that the query might be causing a resource exhaustion issue, likely due to the generation of a large number of paths or a memory management problem within Kùzu.

Here is a general approach to retrieve all paths between two nodes, but please note that this may need to be adapted based on the specific capabilities and limitations of Kùzu:

MATCH p = (s:Vertex {name:"nA"})-[r:Relation*]-(t:Vertex {name: "nC"})
RETURN properties(nodes(p), 'name') AS name, properties(rels(p), 'info') AS info;

This query attempts to find all paths (r:Relation*) between the start node s with name nA and the target node t with name nC. However, if this query is causing the buffer manager exception, you may need to:

If Kùzu supports a way to limit the recursion depth, you could try something like this:

MATCH p = (s:Vertex {name:"nA"})-[r:Relation*1..5]-(t:Vertex {name: "nC"})
RETURN properties(nodes(p), 'name') AS name, properties(rels(p), 'info') AS info;

This query limits the path length to a maximum of 5 hops, which might help avoid the buffer manager exception by reducing the number of paths generated. Adjust the maximum length according to the specifics of your graph and the capabilities of Kùzu.