Skip to content

Semantic columns

Say “embed these columns of this table with this model” and the project keeps a pgvector column up to date by itself. Your users then search the table by meaning, and the answer only contains rows their row level security lets them read.

In the dashboard under AI Gateway, Semantic columns:

  1. In AI Gateway add a model of kind Embedding. The gateway does not have to be switched on for end users.
  2. Press Add semantic column: a name, the table (docs or public.docs, with a single-column primary key), 1 to 8 source columns, the embedding model and optionally a template.
  3. The project adds the vector column semantic_<name> (extensions.vector(n)), an HNSW cosine index and a trigger, then embeds every existing row in the background. Rows you insert or edit later are embedded automatically.

The template is text with {column} placeholders for the source columns (no SQL), for example {title}\n\n{body}. Empty values vanish and the result is cut to max_chars (default 8000). Without a template each source becomes one line column: value.

import { createClient } from "@potalab/base"
import { withSemantic } from "@potalab/base-cloud-sdk-semantic"
const base = withSemantic(createClient({ url, key })) // signed in as a user
const { data, error, meta } = await base.semantic.search({
table: "docs",
query: "how do I cook pasta?",
k: 5,
filter: { lang: "en", n: { gte: 2 } }, // equality, eq/neq/gt/gte/lt/lte, in, is_null
select: ["id", "title"], // default: every column except the vectors
min_score: 0.3, // cosine similarity 0..1
})
// data: [{ row, distance, score }, ...]

Over HTTP: POST /semantic/v1/search with apikey and Authorization: Bearer <user access token>.

The query is embedded with the column’s model and runs as the signed-in user, so policies decide which rows can match: a user never sees, or is ranked against, rows the policies hide. The service key is refused (403 user_token_required); call it with the user’s token (Functions and Flows already carry it).

Errors: 400 invalid_column | invalid_filter, 403 permission_denied (no GRANT on the table), 404 semantic_column_not_found, 429 semantic_rate_limited | semantic_quota_exceeded (with retry-after), 402 feature_not_in_plan.

Choose Re-embed with this model (or PATCH /v1/projects/:ref/semantic/columns/:name). A new vector column is filled while the old one keeps serving search; when it is complete, search switches over and the old column is dropped. A model with other dimensions is fine. Cancel re-embed drops the new column and changes nothing else.

Plan key Meaning
semantic_enabled false answers 402 everywhere
semantic_tokens_month embedding tokens per month (indexing and search); when reached, indexing pauses and search answers 429
semantic_reembed_rows_day rows embedded per day by a backfill or re-embed
semantic_max_columns columns per project

A failing provider backs rows off; after 8 attempts a row is parked as failed and shown on the column. Retry failed rows makes them due again.

  • Vectors live on your table. select=* through the Data API returns them too (large): pick columns explicitly or use a view.
  • Existing projects need the Cloud project SQL applied once before the first column; the page says “Not installed” until then.
  • Removing a column drops the trigger, the queue and (unless you keep the data) the vector columns.