Guides
Graph traversal
Navigate relationships in your graph
A traversal starts at a node and follows edges outgoing, incoming, or in both directions. Steps chain, so a multi-hop query reads left to right.
Basic traversal
TypeScript
// Find all users that Alice follows (outgoing edges)const following = db .from(alice.id) .out('follows') .nodes();// Find all followers of Alice (incoming edges)const followers = db .from(alice.id) .in('follows') .nodes();// Follow edges in both directionsconst connections = db .from(alice.id) .both('knows') .nodes();Multi-hop traversal
TypeScript
// Find friends of friends (2-hop)const friendsOfFriends = db .from(alice.id) .out('follows') .out('follows') .nodes();// Chain different edge typesconst authorsOfLikedArticles = db .from(alice.id) .out('likes') // Alice -> Articles .in('authored') // Articles <- Users .nodes();Variable-depth traversal
TypeScript
// Traverse 1-3 hopsconst network = db .from(alice.id) .traverse('follows', { minDepth: 1, maxDepth: 3 }) .nodes();// Limit resultsconst topConnections = db .from(alice.id) .out('follows') .take(10) .nodes();Next steps
- Vector search: find similar nodes, then traverse from them
- High-level API: the full traversal API