JsonGraphStore

org.llm4s.knowledgegraph.storage.JsonGraphStore
class JsonGraphStore(path: Path) extends GraphStore

JSON-based implementation of GraphStore.

Thread-safety note: This implementation is NOT thread-safe. For concurrent access, wrap with synchronization or use a thread-safe alternative.

Value parameters

path

The file path to save/load the graph

Attributes

Graph
Supertypes
trait GraphStore
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def deleteEdge(source: String, target: String, relationship: String): Result[Unit]

Deletes a specific edge.

Deletes a specific edge.

Value parameters

relationship

The relationship type

source

The source node ID

target

The target node ID

Attributes

Returns

Right(()) on success or if edge doesn't exist, Left(error) on failure

Definition Classes
override def deleteNode(id: String): Result[Unit]

Deletes a node and all its connected edges.

Deletes a node and all its connected edges.

Value parameters

id

The node ID to delete

Attributes

Returns

Right(()) on success or if node doesn't exist, Left(error) on failure

Definition Classes
override def getNeighbors(nodeId: String, direction: Direction): Result[Seq[EdgeNodePair]]

Retrieves neighboring nodes and their connecting edges.

Retrieves neighboring nodes and their connecting edges.

Value parameters

direction

The direction of traversal (Outgoing, Incoming, Both)

nodeId

The ID of the node

Attributes

Returns

Right(Seq of (edge, neighbor node)) on success, Left(error) on failure

Definition Classes
override def getNode(id: String): Result[Option[Node]]

Retrieves a node by ID.

Retrieves a node by ID.

Value parameters

id

The node ID

Attributes

Returns

Right(Some(node)) if found, Right(None) if not found, Left(error) on failure

Definition Classes
def load(): Result[Graph]
override def loadAll(): Result[Graph]

Loads the entire graph.

Loads the entire graph.

For implementations backed by external databases, consider pagination or size limits to avoid memory issues with large graphs.

Attributes

Returns

Right(graph) on success, Left(error) on failure

Definition Classes
override def query(filter: GraphFilter): Result[Graph]

Queries the graph based on filter criteria. Returns a subgraph matching the filter conditions.

Queries the graph based on filter criteria. Returns a subgraph matching the filter conditions.

If propertyKey or propertyValue filters are specified but not supported, the implementation must either apply them or return a clear error.

Value parameters

filter

The filter criteria

Attributes

Returns

Right(subgraph) on success, Left(error) on failure

Definition Classes
def save(graph: Graph): Result[Unit]

Legacy method for backward compatibility

Legacy method for backward compatibility

Attributes

override def stats(): Result[GraphStats]

Computes statistics about the graph.

Computes statistics about the graph.

Attributes

Returns

Right(stats) on success, Left(error) on failure

Definition Classes
override def traverse(startId: String, config: TraversalConfig): Result[Seq[Node]]

Traverses the graph starting from a node using BFS. All implementations must use Breadth-First Search for consistent result ordering.

Traverses the graph starting from a node using BFS. All implementations must use Breadth-First Search for consistent result ordering.

Missing start node: should return Right(Seq.empty) not an error, since traversal of a non-existent node yields no nodes.

Value parameters

config

Traversal configuration (depth, direction, visited set). The direction parameter controls whether traversal follows outgoing, incoming, or all edges from each node.

startId

The ID of the starting node

Attributes

Returns

Right(Seq of traversed nodes) on success, Left(error) on critical failure

Definition Classes
override def upsertEdge(edge: Edge): Result[Unit]

Inserts or updates an edge in the graph. Both source and target nodes must exist. If an edge with the same source, target, and relationship already exists, it is replaced.

Inserts or updates an edge in the graph. Both source and target nodes must exist. If an edge with the same source, target, and relationship already exists, it is replaced.

Value parameters

edge

The edge to upsert

Attributes

Returns

Right(()) on success, Left(error) if source or target nodes don't exist

Definition Classes
override def upsertNode(node: Node): Result[Unit]

Inserts or updates a node in the graph. If the node ID already exists, the existing node is replaced.

Inserts or updates a node in the graph. If the node ID already exists, the existing node is replaced.

Value parameters

node

The node to upsert

Attributes

Returns

Right(()) on success, Left(error) on failure

Definition Classes