Skip to main content

Module sql

Module sql 

Source
Expand description

SQL builders for memory recall / listing. The queries run server-side (where KymaTable + the cosine_distance UDF live) against the columnar memory tables. Each query first dedups to the latest version per node id (row_number() ... ORDER BY updated_at DESC), matching the append-only “latest-wins” model.

Functions§

keyword_recall_sql
Keyword recall: rank latest memories by how many query tokens appear in content/title/tags. Each LIKE triggers the extent token-set pruning (ContainsTokens) so this is index-accelerated. Excludes rows with no hit.
latest_node_sql
Fetch the full latest version of a single node (for read-then-append mutations like status/importance updates).
list_sql
Non-semantic listing with filters, newest first.
neighbors_sql
One-hop neighbour edges for a set of seed node ids (both directions), used to graph-expand a contextual subgraph. Returns edge rows; the orchestrator derives the far endpoint per seed and follows target_namespace for cross-graph (catalog resource / trace) links. Caller must pass ≥1 seed.
nodes_by_id_sql
Fetch the latest versions of specific (currently-valid) memory node ids — used to materialize graph-pulled neighbour memories. Caller must pass ≥1 id.
recall_sql
Semantic recall: dedup → cosine distance → blended re-rank (relevance*0.7 + importance*0.3) → top limit.
sql_str
Quote + escape a string literal for inline SQL.
tokenize_query
Tokenize a free-text query the same way the columnar writer tokenizes stored text (lowercase, split on non-alphanumeric, drop tokens < 2 chars), so query tokens line up with the per-extent token index used for pruning.