Ragex.Graph.Persistence (Ragex v0.14.0)

View Source

Persistence layer for the knowledge graph (nodes and edges).

Saves and loads graph structure to/from disk using ETS serialization, complementing the embedding persistence in Ragex.Embeddings.Persistence.

Graph data is stored at ~/.cache/ragex/<project_hash>/graph.ets.

Usage

# Save graph (called automatically on shutdown)
{:ok, path} = Graph.Persistence.save()

# Load graph (called automatically on startup)
{:ok, %{nodes: 500, edges: 2000}} = Graph.Persistence.load()

# Check if cache exists and is valid
Graph.Persistence.cache_valid?()

Summary

Functions

Checks if a valid graph cache exists.

Clears the graph cache for the current project.

Loads graph nodes and edges from disk.

Saves graph nodes and edges to disk.

Returns statistics about the graph cache.

Functions

cache_valid?(project_path \\ nil)

@spec cache_valid?(String.t() | nil) :: boolean()

Checks if a valid graph cache exists.

clear(project_path \\ nil)

@spec clear(String.t() | nil) :: :ok

Clears the graph cache for the current project.

load(project_path \\ nil)

@spec load(String.t() | nil) :: {:ok, map()} | {:error, term()}

Loads graph nodes and edges from disk.

Returns

  • {:ok, %{nodes: count, edges: count}} - Loaded successfully
  • {:error, :not_found} - No cache file
  • {:error, reason} - Failure

save(project_path \\ nil)

@spec save(String.t() | nil) :: {:ok, Path.t()} | {:error, term()}

Saves graph nodes and edges to disk.

Returns

  • {:ok, path} - Cache file path
  • {:error, reason} - Failure

stats(project_path \\ nil)

@spec stats(String.t() | nil) :: {:ok, map()} | {:error, term()}

Returns statistics about the graph cache.