env | grep -i supabase | sed 's/\(KEY=.\{12\}\).*/\1.../' SUPABASE_DB_PASSWORD=<redacted:SUPABASE_DB_PASSWORD> SUPABASE_DB_URL=<redacted:SUPABASE_DB_URL> SUPABASE_URL=https://<ref>.supabase.co SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJI... SUPABASE_PROJECT_REF=<ref> SUPABASE_ANON_KEY=eyJhbGciOiJI...
which psql curl jq python3; psql --version 2>/dev/null
/usr/bin/psql /usr/bin/curl /usr/bin/jq /usr/bin/python3 psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg12+1)
psql "$SUPABASE_DB_URL" -c "select version();" 2>&1 | head -20
version ------------------------------------------------------------------------------ PostgreSQL 17.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 15.2.0, 64-bit (1 row)
psql "$SUPABASE_DB_URL" -c "\d public.documents" -c "select id, title, embedding_json from public.documents order by id;" 2>&1
Table "public.documents"
Column | Type | Collation | Nullable | Default
----------------+---------+-----------+----------+---------
id | integer | | not null |
title | text | | not null |
embedding_json | jsonb | | not null |
Indexes:
"documents_pkey" PRIMARY KEY, btree (id)
id | title | embedding_json
----+---------+------------------
1 | alpha | [10, 0.5, 0, 0]
2 | bravo | [0.9, 0.3, 0, 0]
3 | delta | [20, 60, 0, 0]
4 | echo | [0, 1, 0, 0]
5 | foxtrot | [-5, 0.1, 0, 0]
6 | golf | [0.1, 0.1, 3, 4]
(6 rows)
psql "$SUPABASE_DB_URL" -c "select extname, extversion, n.nspname from pg_extension e join pg_namespace n on n.oid=e.extnamespace;" -c "select name, default_version, installed_version from pg_available_extensions where name='vector';" 2>&1
extname | extversion | nspname --------------------+------------+------------ plpgsql | 1.0 | pg_catalog pgcrypto | 1.3 | extensions uuid-ossp | 1.1 | extensions pg_stat_statements | 1.11 | extensions supabase_vault | 0.3.1 | vault (5 rows) name | default_version | installed_version --------+-----------------+------------------- vector | 0.8.2 | (1 row)
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -c "create extension if not exists vector with schema extensions;" -c "select extname, extversion, n.nspname from pg_extension e join pg_namespace n on n.oid=e.extnamespace where extname='vector';" 2>&1
CREATE EXTENSION extname | extversion | nspname ---------+------------+------------ vector | 0.8.2 | extensions (1 row)
psql "$SUPABASE_DB_URL" -c "select rolname, rolconfig from pg_roles where rolname in ('anon','authenticated','service_role','authenticator','postgres');" 2>&1 rolname | rolconfig
---------------+------------------------------------------------------------------------------------------
authenticated | {statement_timeout=8s}
anon | {statement_timeout=3s}
service_role |
postgres | {"search_path=\"\\$user\", public, extensions"}
authenticator | {"session_preload_libraries=supautils, safeupdate",statement_timeout=8s,lock_timeout=8s}
(5 rows)
psql "$SUPABASE_DB_URL" -c "select setdatabase::regnamespace, setconfig from pg_db_role_setting s left join pg_database d on d.oid=s.setdatabase where s.setrole=0;" -c "show search_path;" 2>&1
setdatabase | setconfig
-------------+-----------------------------
5 | {app.settings.jwt_exp=3600}
(1 row)
search_path
------------------------------
"\$user", public, extensions
(1 row)
psql "$SUPABASE_DB_URL" -At -c "select datname, (select setconfig from pg_db_role_setting where setdatabase=d.oid and setrole=0) from pg_database d where datname=current_database();" 2>&1
postgres|{app.settings.jwt_exp=3600}
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 <<'SQL' 2>&1 alter table public.documents add column if not exists embedding extensions.vector(4); update public.documents set embedding = ( select array_agg((e.v)::float8 order by e.ord)::extensions.vector(4) from jsonb_array_elements(embedding_json) with ordinality as e(v, ord) ) where embedding is null; select id, title, embedding_json, embedding, vector_dims(embedding) as dims from public.documents order by id; SQL
ALTER TABLE UPDATE 6 id | title | embedding_json | embedding | dims ----+---------+------------------+---------------+------ 1 | alpha | [10, 0.5, 0, 0] | [10,0.5,0,0] | 4 2 | bravo | [0.9, 0.3, 0, 0] | [0.9,0.3,0,0] | 4 3 | delta | [20, 60, 0, 0] | [20,60,0,0] | 4 4 | echo | [0, 1, 0, 0] | [0,1,0,0] | 4 5 | foxtrot | [-5, 0.1, 0, 0] | [-5,0.1,0,0] | 4 6 | golf | [0.1, 0.1, 3, 4] | [0.1,0.1,3,4] | 4 (6 rows)
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -c "create index if not exists documents_embedding_hnsw_cosine_idx on public.documents using hnsw (embedding extensions.vector_cosine_ops);" -c "\d public.documents" 2>&1
CREATE INDEX
Table "public.documents"
Column | Type | Collation | Nullable | Default
----------------+-----------+-----------+----------+---------
id | integer | | not null |
title | text | | not null |
embedding_json | jsonb | | not null |
embedding | vector(4) | | |
Indexes:
"documents_pkey" PRIMARY KEY, btree (id)
"documents_embedding_hnsw_cosine_idx" hnsw (embedding vector_cosine_ops)
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 <<'SQL' 2>&1
create or replace function public.match_documents(
query_embedding extensions.vector(4),
match_count int
)
returns table (id int, title text, distance float8)
language sql
stable
parallel safe
security invoker
set search_path = public, extensions
as $$
select d.id,
d.title,
(d.embedding <=> query_embedding)::float8 as distance
from public.documents d
where d.embedding is not null
order by d.embedding <=> query_embedding
limit greatest(coalesce(match_count, 0), 0);
$$;
grant execute on function public.match_documents(extensions.vector(4), int) to anon, authenticated, service_role;
SQLCREATE FUNCTION GRANT
psql "$SUPABASE_DB_URL" -c "select * from public.match_documents('[1,0,0,0]'::extensions.vector(4), 3);" -c "select * from public.match_documents('[0,0,1,1]'::extensions.vector(4), 2);" 2>&1id | title | distance ----+-------+--------------------- 1 | alpha | 0.00124766112215546 2 | bravo | 0.0513167145152487 3 | delta | 0.683772233983162 (3 rows) id | title | distance ----+-------+-------------------- 6 | golf | 0.0104462577590937 2 | bravo | 1 (2 rows)
psql "$SUPABASE_DB_URL" -c "set local enable_seqscan=off; explain (costs off) select id, title, embedding <=> '[1,0,0,0]'::extensions.vector(4) from public.documents order by embedding <=> '[1,0,0,0]'::extensions.vector(4) limit 3;" 2>&1
SET
QUERY PLAN
-------------------------------------------------------------------------
Limit
-> Index Scan using documents_embedding_hnsw_cosine_idx on documents
Order By: (embedding <=> '[1,0,0,0]'::vector(4))
(3 rows)
curl -s -w "\nHTTP:%{http_code}\n" -X POST "$SUPABASE_URL/rest/v1/rpc/match_documents" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d '{"query_embedding":[1,0,0,0],"match_count":3}' 2>&1[{"id":1,"title":"alpha","distance":0.00124766112215546},
{"id":2,"title":"bravo","distance":0.0513167145152487},
{"id":3,"title":"delta","distance":0.683772233983162}]
HTTP:200
rpc(){ curl -s -o /tmp/o -w "%{http_code}" -X POST "$SUPABASE_URL/rest/v1/rpc/match_documents" -H "apikey: $SUPABASE_ANON_KEY" -H "Authorization: Bearer $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d "$1"; echo " <- $1"; cat /tmp/o | jq -c . 2>/dev/null || cat /tmp/o; echo; }
rpc '{"query_embedding":[0,1,0,0],"match_count":6}'
rpc '{"query_embedding":[0,0,1,1],"match_count":2}'
rpc '{"query_embedding":[-1,0,0,0],"match_count":1}'
rpc '{"query_embedding":"[1,0,0,0]","match_count":2}'
rpc '{"query_embedding":[1,0,0,0],"match_count":100}'200 <- {"query_embedding":[0,1,0,0],"match_count":6}
[{"id":4,"title":"echo","distance":0},{"id":3,"title":"delta","distance":0.0513167019494862},{"id":2,"title":"bravo","distance":0.683772217228812},{"id":1,"title":"alpha","distance":0.950062383056108},{"id":5,"title":"foxtrot","distance":0.980003998593934},{"id":6,"title":"golf","distance":0.98000799508818}]
200 <- {"query_embedding":[0,0,1,1],"match_count":2}
[{"id":6,"title":"golf","distance":0.0104462577590937},{"id":2,"title":"bravo","distance":1}]
200 <- {"query_embedding":[-1,0,0,0],"match_count":1}
[{"id":5,"title":"foxtrot","distance":0.000199944594884593}]
200 <- {"query_embedding":"[1,0,0,0]","match_count":2}
[{"id":1,"title":"alpha","distance":0.00124766112215546},{"id":2,"title":"bravo","distance":0.0513167145152487}]
200 <- {"query_embedding":[1,0,0,0],"match_count":100}
[{"id":1,"title":"alpha","distance":0.00124766112215546},{"id":2,"title":"bravo","distance":0.0513167145152487},{"id":3,"title":"delta","distance":0.683772233983162},{"id":6,"title":"golf","distance":0.98000799508818},{"id":4,"title":"echo","distance":1},{"id":5,"title":"foxtrot","distance":1.99980005540512}]
python3 - <<'PY'
import json,os,urllib.request
def rpc(key,body):
r=urllib.request.Request(os.environ['SUPABASE_URL']+'/rest/v1/rpc/match_documents',
data=json.dumps(body).encode(),
headers={'apikey':key,'Authorization':'Bearer '+key,'Content-Type':'application/json'})
return json.load(urllib.request.urlopen(r))
ok=True
for q in ([1,0,0,0],[0,1,0,0],[0,0,1,1],[-1,0,0,0],[0.5,0.5,0,0]):
rows=rpc(os.environ['SUPABASE_ANON_KEY'],{'query_embedding':q,'match_count':6})
d=[x['distance'] for x in rows]
sorted_ok = d==sorted(d)
keys_ok = all(set(x)=={'id','title','distance'} for x in rows)
print(f"q={q} sorted={sorted_ok} keys={keys_ok} top={rows[0]['title']}")
ok &= sorted_ok and keys_ok and len(rows)==6
r=rpc(os.environ['SUPABASE_SERVICE_ROLE_KEY'],{'query_embedding':[1,0,0,0],'match_count':2})
print("service_role ok:", [x['title'] for x in r])
print("match_count respected:", len(rpc(os.environ['SUPABASE_ANON_KEY'],{'query_embedding':[1,0,0,0],'match_count':1}))==1)
print("ALL CHECKS PASS" if ok else "FAIL")
PYq=[1, 0, 0, 0] sorted=True keys=True top=alpha q=[0, 1, 0, 0] sorted=True keys=True top=echo q=[0, 0, 1, 1] sorted=True keys=True top=golf q=[-1, 0, 0, 0] sorted=True keys=True top=foxtrot q=[0.5, 0.5, 0, 0] sorted=True keys=True top=bravo service_role ok: ['alpha', 'bravo'] match_count respected: True ALL CHECKS PASS
psql "$SUPABASE_DB_URL" -c "select a.attname, format_type(a.atttypid,a.atttypmod) as type from pg_attribute a where a.attrelid='public.documents'::regclass and a.attnum>0 and not a.attisdropped order by a.attnum;" -c "select indexdef from pg_indexes where tablename='documents' and schemaname='public';" -c "select p.proname, pg_get_function_identity_arguments(p.oid) as args, pg_get_function_result(p.oid) as result, p.prosecdef as security_definer, p.proconfig from pg_proc p join pg_namespace n on n.oid=p.pronamespace where n.nspname='public' and p.proname='match_documents';" 2>&1
attname | type
----------------+-----------
id | integer
title | text
embedding_json | jsonb
embedding | vector(4)
(4 rows)
indexdef
---------------------------------------------------------------------------------------------------------------
CREATE UNIQUE INDEX documents_pkey ON public.documents USING btree (id)
CREATE INDEX documents_embedding_hnsw_cosine_idx ON public.documents USING hnsw (embedding vector_cosine_ops)
(2 rows)
proname | args | result | security_definer | proconfig
-----------------+---------------------------------------------+----------------------------------------------------------+------------------+------------------------------------
match_documents | query_embedding vector, match_count integer | TABLE(id integer, title text, distance double precision) | f | {"search_path=public, extensions"}
(1 row)
psql "$SUPABASE_DB_URL" -At -c "select count(*) as total, count(embedding) as with_embedding, count(*) filter (where embedding::text != replace(replace(embedding_json::text,' ',''),'.0,',',')) as mismatch_candidates from public.documents;" -c "select has_function_privilege('anon','public.match_documents(extensions.vector(4),int)','execute') as anon_exec, has_table_privilege('anon','public.documents','select') as anon_select;" 2>&16|6|0 t|t
14 earlier narration turn(s) are in the raw transcript.
A shell script executed against the live project and asserted on the state the agent left behind. No model judged another model.
Raw transcript · Task definition and verifier · Every attempt