Graph

org.llm4s.knowledgegraph.Graph
See theGraph companion object
case class Graph(nodes: Map[String, Node], edges: List[Edge])

Represents a Knowledge Graph containing nodes and edges.

Value parameters

edges

List of Edges in the graph

nodes

Map of Node ID to Node object

Attributes

Example
val alice = Node("alice", "Person", Map("name" -> ujson.Str("Alice")))
val acme = Node("acme", "Organization", Map("name" -> ujson.Str("Acme Corp")))
val edge = Edge("alice", "acme", "WORKS_FOR")
val graph = Graph.empty
 .addNode(alice)
 .addNode(acme)
 .addEdge(edge)
graph.getNeighbors("alice") // Set(acme)
graph.findNodesByLabel("Person") // List(alice)
Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def addEdge(edge: Edge): Graph

Adds an edge to the graph.

Adds an edge to the graph.

Value parameters

edge

The edge to add

Attributes

Returns

A new graph with the edge appended

def addNode(node: Node): Graph

Adds a node to the graph. If a node with the same ID exists, it is replaced.

Adds a node to the graph. If a node with the same ID exists, it is replaced.

Value parameters

node

The node to add

Attributes

Returns

A new graph with the node added

def findNodesByLabel(label: String): List[Node]

Finds nodes by label.

Finds nodes by label.

Value parameters

label

The label to match (e.g., "Person")

Attributes

Returns

All nodes with the given label

def findNodesByProperty(key: String, value: String): List[Node]

Finds nodes by property value. Compares against the JSON string representation of the value.

Finds nodes by property value. Compares against the JSON string representation of the value.

Attributes

def getConnectedEdges(nodeId: String): List[Edge]

Gets all edges connected to a node (both incoming and outgoing).

Gets all edges connected to a node (both incoming and outgoing).

Value parameters

nodeId

The ID of the node

Attributes

Returns

All edges where the node is either source or target

def getIncomingEdges(nodeId: String): List[Edge]

Gets incoming edges to a node.

Gets incoming edges to a node.

Value parameters

nodeId

The ID of the target node

Attributes

Returns

All edges pointing to the specified node

def getNeighbors(nodeId: String): Set[Node]

Gets neighbor nodes (both incoming and outgoing).

Gets neighbor nodes (both incoming and outgoing).

Value parameters

nodeId

The ID of the node

Attributes

Returns

All nodes directly connected to the specified node

def getOutgoingEdges(nodeId: String): List[Edge]

Gets outgoing edges from a node.

Gets outgoing edges from a node.

Value parameters

nodeId

The ID of the source node

Attributes

Returns

All edges originating from the specified node

def hasEdge(source: String, target: String, relationship: Option[String]): Boolean

Checks if an edge exists between two nodes.

Checks if an edge exists between two nodes.

Value parameters

relationship

Optional relationship type filter

source

The source node ID

target

The target node ID

Attributes

Returns

True if a matching edge exists

def hasNode(nodeId: String): Boolean

Checks if a node exists in the graph.

Checks if a node exists in the graph.

Value parameters

nodeId

The ID of the node to check

Attributes

Returns

True if a node with the given ID exists

def merge(other: Graph): Graph

Merges another graph into this one. Nodes are merged by ID; duplicate edges are removed.

Merges another graph into this one. Nodes are merged by ID; duplicate edges are removed.

Value parameters

other

The graph to merge in

Attributes

Returns

A new graph containing nodes and edges from both graphs

def validate(): Result[Unit]

Validates graph integrity - ensures all edge endpoints exist in node set.

Validates graph integrity - ensures all edge endpoints exist in node set.

Attributes

Returns

Right(()) if valid, Left(error) if invalid

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product