All blocks
AI
Vector search
search_<table>(query, k) for each table in vectorSearch: the k nearest rows the caller can read, with pgvector iterative index scans so RLS filters still return k rows.
npx better-supabase sql add vector-searchimport { defineConfig } from "better-supabase/config";
export default defineConfig({
sql: {
modules: {
// Modes: "managed". The default is "managed".
"vector-search": { mode: "managed" },
},
},
});npx better-supabase sql add vector-search writes these files into your declarative schema with the default layout. See SQL modules for the migration step and the layout options.
supabase/schemas/900_better_supabase_18_vector_search.sqlschema25 linessupabase/better-supabase-data/900_better_supabase_18_vector_search.sqldata14 lines
supabase/schemas/900_better_supabase_18_vector_search.sql
-- better-supabase module: vector-search -- @bs-module vector-search@1 managed -- search_<table>(query, k) for each table in vectorSearch: the k nearest rows the caller can read, with pgvector iterative index scans so RLS filters still return k rows. -- Managed by `better-supabase sql add`; re-running it overwrites this file. -- Change it through `sql.modules` in better-supabase.config.ts and the module's SQL hooks. create extension if not exists vector with schema extensions; -- Functions for the tables in `vectorSearch` (better-supabase.config.ts); `sql sync` rewrites them. -- They are security invoker, so RLS (a tenant policy, say) filters inside the -- index scan. hnsw.iterative_scan keeps scanning until k visible rows are found -- (pgvector 0.8+) instead of returning fewer. create schema if not exists better_supabase; create table if not exists better_supabase.modules ( name text primary key, version integer not null, mode text not null, installed_at timestamptz not null default now(), updated_at timestamptz not null default now() ); alter table better_supabase.modules enable row level security; revoke all on better_supabase.modules from anon, authenticated; grant select on better_supabase.modules to service_role;
supabase/better-supabase-data/900_better_supabase_18_vector_search.sql
-- better-supabase module: vector-search
-- @bs-module-data vector-search
-- Rows and settings a schema diff doesn't capture. Run `better-supabase sql data`
-- after the schema migration to put them in a migration.
-- Managed by `better-supabase sql add`; re-running it overwrites this file.
-- Change it through `sql.modules` in better-supabase.config.ts and the module's SQL hooks.
create extension if not exists "vector" with schema "extensions";
insert into better_supabase.modules (name, version, mode)
values ('vector-search', 1, 'managed')
on conflict (name) do update
set version = excluded.version, mode = excluded.mode, updated_at = now();
This block is SQL only: call its functions from your policies, RPCs and the other modules.
This module writes no outbox events.