examples · graph · 7 / 7
7. pagerank - over a caller-supplied node set
← Graph exampleswhat this does
Computes PageRank scores over a subgraph that you define via nodes=. The engine restricts the iteration to that node universe and the edges between them; everything outside is ignored. Returns a { pk → score } map summing to 1.
when to use it
- Influence ranking inside a tenant / project / topic - "who matters in this subgraph?"
- Recommendation seeds - score a candidate set, take the top-K.
- Any case where the full graph is too big to rank globally, but a slice is the right scope.
schema requirement
The relation must be declared in the schema's [[relations]] block. See schemas/reference#relations.
the request
nodes is a comma-separated list of the primary keys that form the universe. Edges to keys outside the list are dropped; the iteration is scoped to what you pass.
GET /v1/tenants/:t/graph/:schema/pagerank?rel=...&nodes=...
curl -G "https://$OC_HOST/v1/tenants/$OC_TENANT/graph/shop.orders/pagerank" \
--data-urlencode "rel=bought_product" \
--data-urlencode "nodes=o001,o002,o003,o004,o005" \
-H "Authorization: Bearer $OC_TOKEN"result = db.graph.pagerank(
"shop.orders",
rel="bought_product",
nodes=["o001", "o002", "o003", "o004", "o005"],
)const result = await db.graph.pagerank("shop.orders", {
rel: "bought_product",
nodes: ["o001", "o002", "o003", "o004", "o005"],
});result, _ := db.Graph().PageRank(ctx, "shop.orders", originchain.PageRankRequest{
Rel: "bought_product",
Nodes: []string{"o001", "o002", "o003", "o004", "o005"},
}) what you get back
{
"o001": 0.241,
"o002": 0.198,
"o003": 0.187,
"o004": 0.192,
"o005": 0.182
} A map from primary key to score. Scores sum to 1 across the supplied node set. Sort client-side for "top-K influencers".
how it works
- Power-iteration PageRank with damping factor 0.85.
- The induced subgraph is built once from the
nodeslist; iteration converges on that subgraph only. - Caller-scoped universe is intentional - the engine refuses to rank the entire tenant graph because that's almost never what you want and is unbounded in cost.
common mistakes
- Omitting
nodes=. The engine 400s because it requires the universe up front. Pick the candidate set first; rank second. - Comparing scores across different node sets. Scores are relative to the universe you pass. A pk's score in one subgraph isn't comparable to its score in another.