GraphRanking

org.llm4s.knowledgegraph.query.GraphRanking
object GraphRanking

Graph ranking algorithms for entity importance scoring.

Provides PageRank, betweenness centrality, closeness centrality, and degree centrality implementations that operate on the immutable Graph data structure.

These scores are used by GraphQAPipeline to prioritize which entities to include in LLM context when the result set exceeds context limits.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def betweennessCentrality(graph: Graph): Map[String, Double]

Computes betweenness centrality for all nodes in the graph.

Computes betweenness centrality for all nodes in the graph.

Betweenness centrality measures the fraction of shortest paths between all pairs of nodes that pass through a given node. High betweenness indicates a node is a bridge or broker in the network.

Uses Brandes' algorithm for efficient computation.

Value parameters

graph

The graph to analyze

Attributes

Returns

Map of node ID to betweenness centrality score (normalized by (n-1)(n-2)/2)

def closenessCentrality(graph: Graph): Map[String, Double]

Computes closeness centrality for all nodes in the graph.

Computes closeness centrality for all nodes in the graph.

Closeness centrality measures the reciprocal of the average shortest path distance from a node to all other reachable nodes. Nodes that are "close" to all others have high closeness centrality.

Value parameters

graph

The graph to analyze

Attributes

Returns

Map of node ID to closeness centrality score (0.0 to 1.0)

def degreeCentrality(graph: Graph): Map[String, Double]

Computes degree centrality for all nodes in the graph.

Computes degree centrality for all nodes in the graph.

Degree centrality is the simplest centrality measure, equal to the number of edges connected to a node normalized by the maximum possible degree.

Value parameters

graph

The graph to analyze

Attributes

Returns

Map of node ID to degree centrality score (0.0 to 1.0)

def pageRank(graph: Graph, dampingFactor: Double, maxIterations: Int, tolerance: Double): Map[String, Double]

Computes PageRank scores for all nodes in the graph.

Computes PageRank scores for all nodes in the graph.

PageRank measures the importance of a node based on the link structure. Nodes with many incoming edges from other important nodes get higher scores.

Value parameters

dampingFactor

The probability of following a link (typically 0.85)

graph

The graph to analyze

maxIterations

Maximum number of iterations before convergence

tolerance

Convergence threshold — stops when max score change < tolerance

Attributes

Returns

Map of node ID to PageRank score (scores sum to ~1.0)