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.
Builds a single-statement DELETE ast_node WHERE file_path = ... that
removes every node belonging to a file in one server-side operation
(secondary, full-text, and vector indexes are maintained by the engine).
Pair with exec_delete_by_file/2.
Builds a single-statement DELETE ast_node WHERE project_path = ... that
removes every node of a project in one server-side operation. Pair with
exec_delete_by_project/2.
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 native delete-by-file (DELETE ... WHERE) in a single
round-trip, returning {:ok, count} (rows removed) or {:error, reason}.
Executes a native delete-by-project (DELETE ... WHERE) in a single
round-trip, returning {:ok, count} or {:error, reason}.
Loads all nodes for a file and returns them as parsed maps.
Executes the grouped stats query and returns
{:ok, %{total: n, by_kind: %{kind => count}}}.
SELECT a function node by module, name, and arity.
SELECT a module (container) node by name.
SELECT function nodes belonging to a module.
Combined full-text + vector hybrid search via the engine's native
HYBRID SEARCH verb: BM25 on source_text fused with HNSW on
source_embedding. Each row carries score, text_score, and
vector_score.
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, built with the engine's native
SEARCH verb. Each row carries a score.
Full-text BM25 search on source_text, built with the engine's native
SEARCH verb. Each row carries a score. Requires a full-text index 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.
Vector (HNSW) similarity search over source_embedding, built with the
engine's native VECTOR SEARCH verb. Results come back nearest-first, each
row carrying a distance field. Requires a vector index on
source_embedding (see Dllb.Schema.ast_node_search_indexes/0).
Returns a COUNT ast_node GROUP BY kind query: one row per kind, each
carrying a count, aggregated server-side.
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.
Builds a single-statement DELETE ast_node WHERE file_path = ... that
removes every node belonging to a file in one server-side operation
(secondary, full-text, and vector indexes are maintained by the engine).
Pair with exec_delete_by_file/2.
Builds a single-statement DELETE ast_node WHERE project_path = ... that
removes every node of a project in one server-side operation. Pair with
exec_delete_by_project/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 native delete-by-file (DELETE ... WHERE) in a single
round-trip, returning {:ok, count} (rows removed) or {:error, reason}.
@spec exec_delete_by_project(String.t(), Dllb.MetaAST.query_fn()) :: {:ok, non_neg_integer()} | {:error, term()}
Executes a native delete-by-project (DELETE ... WHERE) in a single
round-trip, returning {:ok, count} or {:error, reason}.
@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 the grouped stats query and returns
{:ok, %{total: n, by_kind: %{kind => count}}}.
The grouped rows carry serde-tagged values (e.g. %{"String" => "..."}),
which are unwrapped here into plain kinds and integer 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 full-text + vector hybrid search via the engine's native
HYBRID SEARCH verb: BM25 on source_text fused with HNSW on
source_embedding. Each row carries score, text_score, and
vector_score.
Options
:limit- max results (default 10):alpha- weight on the text score in0.0..1.0(default 0.5); the vector score gets1 - alpha:kind/:file_path/:language/:project_path- optional scope filters
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, built with the engine's native
SEARCH verb. Each row carries a score.
Options
:limit- max results (default 20)
Full-text BM25 search on source_text, built with the engine's native
SEARCH verb. Each row carries a score. Requires a full-text index on
source_text.
Options
:limit- max results (default 20):kind/:file_path/:language/:project_path- optional scope filters
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.
Vector (HNSW) similarity search over source_embedding, built with the
engine's native VECTOR SEARCH verb. Results come back nearest-first, each
row carrying a distance field. Requires a vector index on
source_embedding (see Dllb.Schema.ast_node_search_indexes/0).
Options
:limit- max results (default 10):kind- optional kind filter (scopes results server-side):file_path- optional file filter:language- optional language filter:project_path- optional project filter (multi-project isolation)
@spec stats_query() :: String.t()
Returns a COUNT ast_node GROUP BY kind query: one row per kind, each
carrying a count, aggregated server-side.