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 python3; psql --version 2>/dev/null
/usr/bin/psql /usr/bin/curl /usr/bin/python3 psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg12+1)
cd /tmp && psql "$SUPABASE_DB_URL" -c "select version();" 2>&1 | head -5
version ------------------------------------------------------------------------------ PostgreSQL 17.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 15.2.0, 64-bit (1 row)
cd /tmp && psql "$SUPABASE_DB_URL" -c "\d public.documents" -c "select * from public.documents order by id;" 2>&1 | head -40
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)
cd /tmp && psql "$SUPABASE_DB_URL" -c "select name, default_version, installed_version from pg_available_extensions where name='vector';" -c "select current_user; show search_path;" 2>&1
name | default_version | installed_version
--------+-----------------+-------------------
vector | 0.8.2 |
(1 row)
current_user
--------------
postgres
(1 row)
search_path
------------------------------
"\$user", public, extensions
(1 row)
cd /tmp && psql "$SUPABASE_DB_URL" -c "select nspname from pg_namespace where nspname in ('extensions','public','graphql');" 2>&1nspname ------------ graphql extensions public (3 rows)
cd /tmp && psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -c "create extension if not exists vector with schema extensions;" -c "select e.extname, e.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)
cd /tmp && psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -c "alter table public.documents add column if not exists embedding extensions.vector(4);" -c "update public.documents set embedding = (embedding_json::text)::extensions.vector(4) where embedding is null;" 2>&1
ALTER TABLE UPDATE 6
cd /tmp && psql "$SUPABASE_DB_URL" -c "select id, title, embedding_json, embedding, count(*) filter (where embedding is null) over () as nulls from public.documents order by id;" 2>&1
id | title | embedding_json | embedding | nulls ----+---------+------------------+---------------+------- 1 | alpha | [10, 0.5, 0, 0] | [10,0.5,0,0] | 0 2 | bravo | [0.9, 0.3, 0, 0] | [0.9,0.3,0,0] | 0 3 | delta | [20, 60, 0, 0] | [20,60,0,0] | 0 4 | echo | [0, 1, 0, 0] | [0,1,0,0] | 0 5 | foxtrot | [-5, 0.1, 0, 0] | [-5,0.1,0,0] | 0 6 | golf | [0.1, 0.1, 3, 4] | [0.1,0.1,3,4] | 0 (6 rows)
cd /tmp && 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);" 2>&1
CREATE INDEX
cd /tmp && psql "$SUPABASE_DB_URL" -c "select indexname, indexdef from pg_indexes where tablename='documents' and schemaname='public';" 2>&1
indexname | indexdef -------------------------------------+--------------------------------------------------------------------------------------------------------------- documents_pkey | CREATE UNIQUE INDEX documents_pkey ON public.documents USING btree (id) documents_embedding_hnsw_cosine_idx | CREATE INDEX documents_embedding_hnsw_cosine_idx ON public.documents USING hnsw (embedding vector_cosine_ops) (2 rows)
cd /tmp && cat > fn.sql <<'SQL'
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
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;
SQL
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -f fn.sql 2>&1CREATE FUNCTION GRANT
cd /tmp && psql "$SUPABASE_DB_URL" -c "select relrowsecurity, relforcerowsecurity from pg_class where oid='public.documents'::regclass;" -c "select grantee, privilege_type from information_schema.role_table_grants where table_name='documents' and table_schema='public' order by grantee, privilege_type;" -c "select policyname, roles, cmd, qual from pg_policies where tablename='documents';" 2>&1
relrowsecurity | relforcerowsecurity
----------------+---------------------
f | f
(1 row)
grantee | privilege_type
---------------+----------------
anon | DELETE
anon | INSERT
anon | REFERENCES
anon | SELECT
anon | TRIGGER
anon | TRUNCATE
anon | UPDATE
authenticated | DELETE
authenticated | INSERT
authenticated | REFERENCES
authenticated | SELECT
authenticated | TRIGGER
authenticated | TRUNCATE
authenticated | UPDATE
postgres | DELETE
postgres | INSERT
postgres | REFERENCES
postgres | SELECT
postgres | TRIGGER
postgres | TRUNCATE
postgres | UPDATE
service_role | DELETE
service_role | INSERT
service_role | REFERENCES
service_role | SELECT
service_role | TRIGGER
service_role | TRUNCATE
service_role | UPDATE
(28 rows)
policyname | roles | cmd | qual
------------+-------+-----+------
(0 rows)
cd /tmp && psql "$SUPABASE_DB_URL" -c "select * from public.match_documents('[1,0,0,0]'::extensions.vector(4), 3);" 2>&1id | title | distance ----+-------+--------------------- 1 | alpha | 0.00124766112215546 2 | bravo | 0.0513167145152487 3 | delta | 0.683772233983162 (3 rows)
cd /tmp && python3 -c "
import math
docs={1:('alpha',[10,.5,0,0]),2:('bravo',[.9,.3,0,0]),3:('delta',[20,60,0,0]),4:('echo',[0,1,0,0]),5:('foxtrot',[-5,.1,0,0]),6:('golf',[.1,.1,3,4])}
q=[1,0,0,0]
def cd(a,b):
dot=sum(x*y for x,y in zip(a,b)); na=math.sqrt(sum(x*x for x in a)); nb=math.sqrt(sum(x*x for x in b))
return 1-dot/(na*nb)
for i,(t,v) in sorted(docs.items(), key=lambda kv: cd(q,kv[1][1])):
print(f'{i:2d} {t:8s} {cd(q,v):.6f}')
"1 alpha 0.001248 2 bravo 0.051317 3 delta 0.683772 6 golf 0.980008 4 echo 1.000000 5 foxtrot 1.999800
cd /tmp && 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
cd /tmp && psql "$SUPABASE_DB_URL" -c "notify pgrst, 'reload schema';" >/dev/null 2>&1; echo "--- query [0,0,1,1] (expect golf nearest) ---"; curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/match_documents" -H "apikey: $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d '{"query_embedding":[0,0,1,1],"match_count":2}'; echo; echo "--- query [-1,0,0,0] (expect foxtrot nearest) ---"; curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/match_documents" -H "apikey: $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d '{"query_embedding":[-1,0,0,0],"match_count":2}'; echo; echo "--- match_count=6 (all, check ordering) ---"; curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/match_documents" -H "apikey: $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d '{"query_embedding":[1,0,0,0],"match_count":6}'; echo--- query [0,0,1,1] (expect golf nearest) ---
[{"id":6,"title":"golf","distance":0.0104462577590937},
{"id":2,"title":"bravo","distance":1}]
--- query [-1,0,0,0] (expect foxtrot nearest) ---
[{"id":5,"title":"foxtrot","distance":0.000199944594884593},
{"id":4,"title":"echo","distance":1}]
--- match_count=6 (all, check ordering) ---
[{"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}]
cd /tmp && psql "$SUPABASE_DB_URL" -c "set local enable_seqscan=off; explain (costs off) select d.id, d.title, (d.embedding <=> '[1,0,0,0]'::extensions.vector(4))::float8 from public.documents d where d.embedding is not null order by d.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 d
Order By: (embedding <=> '[1,0,0,0]'::vector(4))
Filter: (embedding IS NOT NULL)
(4 rows)
cd /tmp && for n in 1 4; do echo -n "match_count=$n -> "; curl -s -X POST "$SUPABASE_URL/rest/v1/rpc/match_documents" -H "apikey: $SUPABASE_ANON_KEY" -H "Content-Type: application/json" -d "{\"query_embedding\":[1,0,0,0],\"match_count\":$n}" | tr -d '\n '; echo; donematch_count=1 -> [{"id":1,"title":"alpha","distance":0.00124766112215546}]
match_count=4 -> [{"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}]
cd /tmp && psql "$SUPABASE_DB_URL" -c "select pg_get_function_identity_arguments(oid) as args, pg_get_function_result(oid) as returns, prosecdef, proconfig from pg_proc where oid='public.match_documents'::regproc;" -c "select a.attname, format_type(a.atttypid,a.atttypmod) from pg_attribute a where a.attrelid='public.documents'::regclass and a.attnum>0 and not a.attisdropped;" 2>&1
args | returns | prosecdef | proconfig
---------------------------------------------+----------------------------------------------------------+-----------+------------------------------------
query_embedding vector, match_count integer | TABLE(id integer, title text, distance double precision) | f | {"search_path=public, extensions"}
(1 row)
attname | format_type
----------------+-------------
id | integer
title | text
embedding_json | jsonb
embedding | vector(4)
(4 rows)
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