Domain-aware query builders for MetaAST data stored in dllb.
Every function returns a plain query string (or list of query strings)
ready to be sent through Dllb.query/1 or Dllb.batch/1. Higher-level
exec_* variants accept a query function and return parsed results via
Dllb.MetaAST.from_dllb_row/1.
Query categories
- Node queries -- find/list AST nodes by file, kind, module, or composite key
- Graph traversals -- callers, callees, importers, imports, call chains
- Search -- HNSW vector similarity, full-text BM25, hybrid
- Lifecycle -- delete by file/project, stats
- Tree reconstruction -- rebuild MetaAST 3-tuples from stored data
Summary
Functions
Multi-hop call chain traversal from a starting node.
Graph traversal: find all callees of a node (outgoing calls edges).
Graph traversal: find all callers of a node (incoming calls edges).
Returns a COUNT query for ast_node rows that have a source_embedding
set -- i.e. the number of stored embedding vectors.
Deletes all AST nodes belonging to a file.
Executes a query through query_fn and returns parsed result maps.
Executes a COUNT query and returns {:ok, count} or {:error, reason}.
Counts stored embedding vectors (ast_node rows with source_embedding).
Executes a two-step delete-by-file: SELECT ids, then batch DELETE.
Executes a two-step delete-by-project: SELECT ids, then batch DELETE.
Loads all nodes for a file and returns them as parsed maps.
Executes stats query and returns aggregated counts.
SELECT a function node by module, name, and arity.
SELECT a module (container) node by name.
SELECT function nodes belonging to a module.
Combined vector + full-text hybrid search.
Graph traversal: find all modules that import a given node.
Graph traversal: find all imports of a node.
SELECT all AST nodes belonging to a file.
SELECT all AST nodes of a given kind (e.g. "function_def", "container").
SELECT nodes filtered by project path.
Full-text BM25 search on docstring.
Full-text BM25 search on source_text.
Builds an UPDATE ast_node SET source_embedding = [...] WHERE <attrs>
statement that attaches an embedding to the row(s) identified by attrs.
HNSW vector similarity search on source_embedding.
Returns a SELECT for overall statistics (node count).
Functions
@spec call_chain(String.t(), pos_integer()) :: String.t()
Multi-hop call chain traversal from a starting node.
Builds a chained ->calls->ast_node traversal repeated depth times.
Graph traversal: find all callees of a node (outgoing calls edges).
Graph traversal: find all callers of a node (incoming calls edges).
Returns a SELECT with <-calls<-ast_node traversal syntax.
@spec count_embeddings_query() :: String.t()
Returns a COUNT query for ast_node rows that have a source_embedding
set -- i.e. the number of stored embedding vectors.
Deletes all AST nodes belonging to a file.
Since dllb currently supports DELETE table:id (point deletes) but not
DELETE ... WHERE, this returns a two-step approach: a SELECT to find
the ids, then point DELETEs for each. Use with exec_delete_by_file/2.
@spec exec(String.t(), Dllb.MetaAST.query_fn()) :: {:ok, [map()]} | {:error, term()}
Executes a query through query_fn and returns parsed result maps.
@spec exec_count(String.t(), Dllb.MetaAST.query_fn()) :: {:ok, non_neg_integer()} | {:error, term()}
Executes a COUNT query and returns {:ok, count} or {:error, reason}.
@spec exec_count_embeddings(Dllb.MetaAST.query_fn()) :: {:ok, non_neg_integer()} | {:error, term()}
Counts stored embedding vectors (ast_node rows with source_embedding).
@spec exec_delete_by_file(String.t(), Dllb.MetaAST.query_fn()) :: {:ok, non_neg_integer()} | {:error, term()}
Executes a two-step delete-by-file: SELECT ids, then batch DELETE.
Returns {:ok, count} or {:error, reason}.
@spec exec_delete_by_project(String.t(), Dllb.MetaAST.query_fn()) :: {:ok, non_neg_integer()} | {:error, term()}
Executes a two-step delete-by-project: SELECT ids, then batch DELETE.
@spec exec_load_file_nodes(String.t(), Dllb.MetaAST.query_fn()) :: {:ok, [map()]} | {:error, term()}
Loads all nodes for a file and returns them as parsed maps.
@spec exec_stats(Dllb.MetaAST.query_fn()) :: {:ok, map()} | {:error, term()}
Executes stats query and returns aggregated counts.
@spec find_function(String.t(), String.t(), non_neg_integer()) :: String.t()
SELECT a function node by module, name, and arity.
SELECT a module (container) node by name.
SELECT function nodes belonging to a module.
Requires the module field to be populated during ingestion.
Combined vector + full-text hybrid search.
Scores are combined as vec_weight * vec_score + ft_weight * ft_score.
Options
:limit- max results (default 10):ef- HNSW exploration factor (default 100):vec_weight- weight for vector score (default 0.6):ft_weight- weight for full-text score (default 0.4)
Graph traversal: find all modules that import a given node.
Graph traversal: find all imports of a node.
SELECT all AST nodes belonging to a file.
SELECT all AST nodes of a given kind (e.g. "function_def", "container").
SELECT nodes filtered by project path.
Full-text BM25 search on docstring.
Full-text BM25 search on source_text.
Options
:limit- max results (default 20):kind- optional kind filter
Builds an UPDATE ast_node SET source_embedding = [...] WHERE <attrs>
statement that attaches an embedding to the row(s) identified by attrs.
attrs is a map of column => value (e.g. %{kind: "function_def", module: "Foo", name: "bar", arity: 2}). nil values are dropped and the
remaining columns are ANDed together (sorted for determinism). Targeting by
stable attributes avoids reconstructing synthetic record IDs.
HNSW vector similarity search on source_embedding.
Options
:limit- max results (default 10):ef- HNSW exploration factor (default 100):kind- optional kind filter:file_path- optional file filter:language- optional language filter
@spec stats_query() :: String.t()
Returns a SELECT for overall statistics (node count).
Note: dllb does not yet support COUNT/GROUP BY, so this returns all ids and the caller aggregates client-side.