Ragex.Store.Backend behaviour (Ragex v0.18.2)

View Source

Behaviour defining the storage contract for Ragex's knowledge graph, embeddings, and vector search.

Two implementations exist:

The active backend is selected at startup via:

config :ragex, :store_backend, :ets   # or :dllb

Summary

Functions

Returns the module implementing this behaviour for the configured backend.

Callbacks

bootstrap()

@callback bootstrap() :: :ok | {:error, term()}

One-time schema bootstrap (e.g. DEFINE TABLE for dllb). ETS is a no-op.

clear()

@callback clear() :: :ok

Clear all data.

count_nodes_by_type(node_type)

@callback count_nodes_by_type(node_type :: atom()) :: non_neg_integer()

find_function(module, name)

@callback find_function(module :: atom(), name :: atom()) :: map() | nil

find_node(node_type, node_id)

@callback find_node(node_type :: atom(), node_id :: term()) :: map() | nil

get_edge_weight(from_node, to_node, edge_type)

@callback get_edge_weight(from_node :: term(), to_node :: term(), edge_type :: atom()) ::
  float() | nil

get_embedding(node_type, node_id)

@callback get_embedding(node_type :: atom(), node_id :: term()) ::
  {[float()], String.t()} | nil

get_incoming_edges(to_node, edge_type)

@callback get_incoming_edges(to_node :: term(), edge_type :: atom()) :: [map()]

get_node(node_key)

@callback get_node(node_key :: {atom(), term()}) :: map() | nil

get_outgoing_edges(from_node, edge_type)

@callback get_outgoing_edges(from_node :: term(), edge_type :: atom()) :: [map()]

list_edges(opts)

@callback list_edges(opts :: keyword()) :: [map()]

list_embeddings(node_type, limit)

@callback list_embeddings(
  node_type :: atom() | nil,
  limit :: non_neg_integer() | :infinity
) :: [tuple()]

list_nodes(node_type, limit)

@callback list_nodes(node_type :: atom() | nil, limit :: non_neg_integer() | :infinity) ::
  [map()]

load_project(project_path)

@callback load_project(project_path :: String.t() | nil) :: :ok

Switch the store to a specific project path.

remove_node(node_type, node_id)

@callback remove_node(node_type :: atom(), node_id :: term()) :: :ok

search_vectors(query_embedding, opts)

@callback search_vectors(query_embedding :: [float()], opts :: keyword()) :: [map()]

stats()

@callback stats() :: map()

Return aggregate stats about the store.

store_edge(from_node, to_node, edge_type, opts)

@callback store_edge(
  from_node :: term(),
  to_node :: term(),
  edge_type :: atom(),
  opts :: keyword()
) :: :ok

store_embedding(node_type, node_id, embedding, text)

@callback store_embedding(
  node_type :: atom(),
  node_id :: term(),
  embedding :: [float()],
  text :: String.t()
) :: :ok

store_node(node_type, node_id, data)

@callback store_node(node_type :: atom(), node_id :: term(), data :: map()) :: :ok

update_node_metadata(node_type, node_id, metadata)

@callback update_node_metadata(node_type :: atom(), node_id :: term(), metadata :: map()) ::
  :ok

Functions

module()

@spec module() :: module()

Returns the module implementing this behaviour for the configured backend.