Dllb.Schema (Dllb v0.6.0)

Copy Markdown View Source

Bootstraps the dllb database schema for code intelligence use.

Provides functions that generate all DEFINE TABLE, DEFINE FIELD, and DEFINE INDEX statements needed for the ast_node table and its indexes. The bootstrap/1 function accepts a query execution function, decoupling schema definition from the connection pool.

Summary

Functions

Returns all schema statements (table, secondary index, full-text/vector search index, and edge-index definitions) in order.

Returns the list of query strings that define the secondary indexes on the ast_node table.

Returns the list of query strings that define the full-text and vector search indexes on the ast_node table.

Returns the list of query strings to define the ast_node table and its 15 fields.

Executes all schema DEFINE statements through the given query function.

Returns the list of query strings to define the _edge_idx table.

Functions

all_statements()

@spec all_statements() :: [String.t()]

Returns all schema statements (table, secondary index, full-text/vector search index, and edge-index definitions) in order.

ast_node_indexes()

@spec ast_node_indexes() :: [String.t()]

Returns the list of query strings that define the secondary indexes on the ast_node table.

These are persisted in the engine's index catalog and transparently accelerate equality and range predicates in WHERE clauses:

  • idx_kind on kind
  • idx_language on language
  • idx_file_path on file_path
  • idx_module on module
  • idx_project_path on project_path
  • idx_file_kind composite on file_path, kind (leftmost-prefix)

Full-text (BM25) and vector (HNSW) search indexes over the embedding and text fields are defined separately by ast_node_search_indexes/0.

ast_node_search_indexes()

@spec ast_node_search_indexes() :: [String.t()]

Returns the list of query strings that define the full-text and vector search indexes on the ast_node table.

Created over the wire via the engine's DEFINE FULLTEXT INDEX / DEFINE VECTOR INDEX DDL. These require a dllb server with full-text/vector services enabled (the default server build):

  • idx_source_text - full-text (BM25) on source_text
  • idx_docstring - full-text (BM25) on docstring
  • idx_source_embedding - vector (HNSW) on source_embedding, 768-dim, cosine
  • idx_structure_embedding - vector (HNSW) on structure_embedding, 384-dim, cosine

ast_node_table()

@spec ast_node_table() :: [String.t()]

Returns the list of query strings to define the ast_node table and its 15 fields.

Fields:

  • kind (string, required) - the Metastatic node type
  • name (string) - symbol/identifier name
  • language (string, required) - source language
  • file_path (string, required) - absolute file path
  • module (string) - parent module/container name
  • arity (int) - function arity (for function_def nodes)
  • visibility (string) - "public" or "private"
  • project_path (string) - project root path (multi-project support)
  • line_start (int) - starting line number
  • line_end (int) - ending line number
  • source_text (string) - raw source text
  • signature (string) - function/method signature
  • docstring (string) - documentation string
  • source_embedding (array) - 768-dim source code embedding
  • structure_embedding (array) - 384-dim structural embedding

bootstrap(query_fn)

@spec bootstrap((String.t() -> {:ok, any()} | {:error, any()})) ::
  {:ok, :bootstrapped} | {:error, any()}

Executes all schema DEFINE statements through the given query function.

The query_fn must have the signature (String.t() -> {:ok, any()} | {:error, any()}). Returns {:ok, :bootstrapped} on success or {:error, reason} on the first failure.

Examples

iex> Dllb.Schema.bootstrap(fn query -> send(self(), {:query, query}); {:ok, %{}} end)
{:ok, :bootstrapped}

edge_idx_table()

@spec edge_idx_table() :: [String.t()]

Returns the list of query strings to define the _edge_idx table.

This schemaless table mirrors graph RELATE edges as queryable documents so that SELECT * FROM _edge_idx WHERE edge_type = 'calls' works.