Skip to content

Commit 5219de3

Browse files
committed
Add documentation for bidirectional pregel computation
1 parent 4b4574d commit 5219de3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

doc/modules/ROOT/pages/algorithms/pregel-api.adoc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,45 @@ public class CustomComputation implements PregelComputation<CustomConfig> {
404404
}
405405
----
406406

407+
[[algorithms-pregel-api-bidirectional]]
408+
=== Traversing incoming relationships
409+
410+
Some algorithms implemented in Pregel might require or benefit from the ability to access and send messages to all incoming relationships of the current context node.
411+
GDS supports the creation of inverse indexes for relationship types, which enables the traversal of incoming relationships for directed relationship types.
412+
413+
A Pregel algorithm can access this index by implementing the `org.neo4j.gds.beta.pregel.BidirectionalPregelComputation` interface instead of the `PregelComputation` interface.
414+
Implementing this interface has the following consequences:
415+
416+
* The Pregel framework will make sure that all relationships passed into the algorithm are inverse indexed.
417+
If no such index exists, an error will be thrown.
418+
* The signature of the `init` and `compute` functions now accept a `org.neo4j.gds.beta.pregel.context.InitContext.BidirectionalInitContext` and `org.neo4j.gds.beta.pregel.context.ComputeContext.BidirectionalComputeContext` respectively.
419+
* Algorithms annotated with the `@PregelProcedure` annotation will automatically create all required inverse indexes.
420+
421+
The `BidirectionalInitContext` and `BidirectionalComputeContexts` expose the following new methods in addition to the methods defined by `InitContext` and `ComputeContext`:
422+
423+
[source, java]
424+
----
425+
//Returns the incoming degree (number of relationships) of the currently processed node.
426+
public int incomingDegree();
427+
// Calls the consumer for each incoming neighbor of the currently processed node.
428+
public void forEachIncomingNeighbor(LongConsumer targetConsumer);
429+
// Calls the consumer for each incoming neighbor of the given node.
430+
public void forEachIncomingNeighbor(long nodeId, LongConsumer targetConsumer);
431+
// Calls the consumer once for each incoming neighbor of the currently processed node.
432+
public void forEachDistinctIncomingNeighbor(LongConsumer targetConsumer);
433+
// Calls the consumer once for each incoming neighbor of the given node.
434+
public void forEachDistinctIncomingNeighbor(long nodeId, LongConsumer targetConsumer);
435+
----
436+
437+
In addition, the `BidirectionalComputeContext` also exposes the following function:
438+
439+
[source, java]
440+
----
441+
// Sends the given message to all neighbors of the node.
442+
public void sendToIncomingNeighbors(double message);
443+
----
444+
445+
407446
[[algorithms-pregel-api-logging]]
408447
=== Logging
409448

0 commit comments

Comments
 (0)