Skip to content

src/lakebase

Lakebase (Postgres) full-text runtime behind lakebaseAiSearch. It provisions a single table per index alias, indexes a generated tsvector, and answers queries with a prefix to_tsquery + ts_rank.

Queries are compiled rather than passed through websearch_to_tsquery, because a search box needs two things that function does not give: punctuation-insensitivity (so store-intelligence matches the same rows as store intelligence) and prefix matching (so intel reaches intelligence). See toSearchTerms / toTsQuery.

The whole point is parity: this backend returns the EXACT same @dbx-tools/shared-search shapes (SearchResult / SearchHit / UpsertResult) as the Vector Search backend, so the client, the Mastra tools, the routes, and the React search box cannot tell which one answered. A hit’s id is the primary key, its score is the text-rank, and fields is the stored document minus the internal columns.

Standalone callers can supply a PoolConfig factory and let this backend own the resulting pool. AppKit integrations instead supply the Lakebase plugin’s managed pool directly, preserving its routing and credential refresh.