OriginChainDB
Graph

List routes without repeated nodes

← Graph examples

The language tabs use earlier client interfaces. Check SDK versions and connection setup before running them.

Find routes between two records without repeating a node inside each route. These are called simple paths.

Before you run it: Dense graphs can contain many routes. Keep both bounds deliberate.

For the quickstart cycle, u1 → u2 → u3 is a route from u1 to u3. Continuing around the cycle would repeat u1, so it is not a simple path. Read the pks list in order; each list is one route, not a set of alternatives.

List paths without repeating a nodeBound both the maximum path length and the number of returned paths.
  1. Choose u1 and u3Set the source and destination keys.
  2. Follow links without cyclesDo not revisit a node within the same path.
  3. Inspect the ordered keysEach returned list describes one bounded route.

Follow the example

  1. Prepare the self-referencing relationship.
  2. Set source and destination keys.
  3. Bound max_depth and max_paths.
  4. Inspect the returned sequences.

Set up the relationship

First complete the graph quickstart to create graph_demo.people and the u1 → u2 → u3 → u1 cycle. The follows relation is declared in the schema's [[relations]] block. See schemas/reference#relations.

Run the request

curl -G "https://$OC_HOST/v1/tenants/$OC_TENANT/graph/graph_demo.people/all_simple_paths" \
  --data-urlencode "rel=follows" \
  --data-urlencode "src=u1" \
  --data-urlencode "dst=u3" \
  --data-urlencode "max_depth=3" \
  -H "Authorization: Bearer $OC_TOKEN"

Check the result

Each path includes its starting and ending records.

[{"pks": ["u1", "u2", "u3"]}]

An array of { pks: [...] } objects, one per discovered path. pks includes both endpoints, in walk order.

Understand the behavior

  • Bounded DFS from src, tracking the path stack to enforce the "no repeated node" rule.
  • Stops descending past max_depth and stops emitting past max_paths.
  • The number of simple paths can grow combinatorially with depth - that's why both caps exist.

Important limits and checks

  • Not capping max_depth. The path count is exponential in depth. Even 4-5 hops on a moderately dense graph can hit the max_paths cap immediately.
  • Using this when you only need one. If you just want the shortest, use dijkstra. If you just want yes/no, use path.

Continue

Continue to find the best few routes.

© 2026 Silicoyn Technologies Pvt Ltd

On this page