Serialization bridge between Metastatic's Elixir 3-tuple format and dllb document/edge storage.
Metastatic AST nodes are represented as {type_atom, keyword_meta, children_or_value}.
This module converts them into maps suitable for Dllb.Query operations and
handles bulk ingestion of full AST trees into the database.
Summary
Functions
Converts a dllb result row (string-keyed map from JSON) into a ragex-compatible map with atom keys and proper types.
Walks a MetaAST tree, generates CREATE statements for structural nodes
and RELATE statements for edges, and executes them via query_fn.
Converts a single Metastatic AST node into a map of fields suitable
for Dllb.Query.create/2.
Walks a full MetaAST tree and extracts structural relationship edges.
Returns an UPDATE query string to set embedding fields on an existing record.
Types
Functions
Converts a dllb result row (string-keyed map from JSON) into a ragex-compatible map with atom keys and proper types.
The kind field is converted back to an atom via NodeTypes.from_dllb_kind/1.
Unknown kinds are kept as the original string in the :kind field.
@spec ingest_tree(meta_ast_node(), context(), query_fn()) :: {:ok, %{nodes: non_neg_integer(), edges: non_neg_integer()}} | {:error, any()}
Walks a MetaAST tree, generates CREATE statements for structural nodes
and RELATE statements for edges, and executes them via query_fn.
Returns {:ok, %{nodes: count, edges: count}} on success or
{:error, reason} on the first failure.
@spec to_dllb_document(meta_ast_node(), context()) :: map()
Converts a single Metastatic AST node into a map of fields suitable
for Dllb.Query.create/2.
Extracts metadata from the keyword list: :name, :line, :end_line,
:source_text, :signature, :doc. The kind and contextual fields
(language, file_path) are derived from the type atom and context map.
Examples
iex> node = {:function_def, [name: "parse", line: 10, end_line: 25], []}
iex> ctx = %{language: :elixir, file_path: "/app/lib/parser.ex"}
iex> doc = Dllb.MetaAST.to_dllb_document(node, ctx)
iex> doc.kind
"function_def"
iex> doc.name
"parse"
@spec to_dllb_edges(meta_ast_node(), context()) :: [edge()]
Walks a full MetaAST tree and extracts structural relationship edges.
Returns a list of {from_id, edge_type, to_id, properties} tuples.
Edge types extracted:
"contains"- container -> function_def relationships"calls"- function_call edges (caller -> callee)"imports"- import edges
Returns an UPDATE query string to set embedding fields on an existing record.
Examples
iex> embeddings = %{source_embedding: [0.1, 0.2, 0.3]}
iex> query = Dllb.MetaAST.to_dllb_embeddings("ast_node:MyMod_parse_2", embeddings)
iex> String.starts_with?(query, "UPDATE ast_node:MyMod_parse_2 SET")
true