env | grep -i supabase | sed 's/\(KEY=\|PASSWORD=\|URL=\).*/\1<hidden>/' ; which psql curl python3
SUPABASE_DB_PASSWORD=<hidden> SUPABASE_DB_URL=<hidden> SUPABASE_URL=<hidden> SUPABASE_SERVICE_ROLE_KEY=<hidden> SUPABASE_PROJECT_REF=<ref> SUPABASE_ANON_KEY=<hidden> /usr/bin/psql /usr/bin/curl /usr/bin/python3
psql --version 2>&1; curl --version 2>&1 | head -1
psql (PostgreSQL) 18.4 (Debian 18.4-1.pgdg12+1) curl 7.88.1 (x86_64-pc-linux-gnu) libcurl/7.88.1 OpenSSL/3.0.20 zlib/1.2.13 brotli/1.0.9 zstd/1.5.4 libidn2/2.3.3 libpsl/0.21.2 (+libidn2/2.3.3) libssh2/1.10.0 nghttp2/1.52.0 librtmp/2.3 OpenLDAP/2.5.13
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 name,default_version,installed_version from pg_available_extensions where name='vector';" -c "select current_user, current_database();" 2>&1
name | default_version | installed_version --------+-----------------+------------------- vector | 0.8.2 | (1 row) current_user | current_database --------------+------------------ postgres | postgres (1 row)
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 e.extname='vector';" 2>&1
CREATE EXTENSION extname | extversion | nspname ---------+------------+------------ vector | 0.8.2 | extensions (1 row)
psql "$SUPABASE_DB_URL" -c "show search_path;" -c "select unnest(setconfig) from pg_db_role_setting s join pg_database d on d.oid=s.setdatabase where d.datname=current_database();" 2>&1
search_path
------------------------------
"\$user", public, extensions
(1 row)
unnest
---------------------------
app.settings.jwt_exp=3600
(1 row)
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(x::float8 order by ord)::extensions.vector(4)
from jsonb_array_elements_text(embedding_json) with ordinality as t(x, ord)
)
where embedding is null;
select id, title, embedding_json, embedding,
jsonb_array_length(embedding_json) as json_dims
from public.documents order by id;
SQLALTER TABLE UPDATE 6 id | title | embedding_json | embedding | json_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 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" 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, pg_temp
as $$
select d.id,
d.title,
(d.embedding operator(extensions.<=>) query_embedding)::float8 as distance
from public.documents d
where d.embedding is not null
order by d.embedding operator(extensions.<=>) query_embedding
limit greatest(coalesce(match_count, 0), 0);
$$;
SQLCREATE FUNCTION
psql "$SUPABASE_DB_URL" -v ON_ERROR_STOP=1 -c "grant execute on function public.match_documents(extensions.vector(4), int) to anon, authenticated, service_role;" -c "grant usage on schema public to anon, authenticated;" -c "grant usage on schema extensions to anon, authenticated;" 2>&1
GRANT GRANT GRANT
psql "$SUPABASE_DB_URL" -c "select relname, relrowsecurity, relforcerowsecurity from pg_class where oid='public.documents'::regclass;" -c "select polname, polcmd, roles::text, qual from pg_policies p join pg_class c on c.relname=p.tablename where p.schemaname='public' and p.tablename='documents';" -c "select grantee, privilege_type from information_schema.role_table_grants where table_schema='public' and table_name='documents' order by grantee, privilege_type;" 2>&1
relname | relrowsecurity | relforcerowsecurity
-----------+----------------+---------------------
documents | f | f
(1 row)
ERROR: column "polname" does not exist
LINE 1: select polname, polcmd, roles::text, qual from pg_policies p...
^
HINT: Perhaps you meant to reference the column "c.relname".
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)
psql "$SUPABASE_DB_URL" -c "select * from public.match_documents('[1,0,0,0]'::vector(4), 3);" -c "select * from public.match_documents('[0,0,1,1]'::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 "notify pgrst, 'reload schema';" 2>&1
NOTIFY
sleep 3; 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
set -e
for q in '[0,1,0,0]' '[0,0,1,1]' '[-1,0,0,0]'; do
echo "=== query $q (top 2) ==="
curl -s -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\":$q,\"match_count\":2}"
echo
done
echo "=== all 6, ordering sanity ==="
curl -s -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":6}'
echo=== query [0,1,0,0] (top 2) ===
[{"id":4,"title":"echo","distance":0},
{"id":3,"title":"delta","distance":0.0513167019494862}]
=== query [0,0,1,1] (top 2) ===
[{"id":6,"title":"golf","distance":0.0104462577590937},
{"id":2,"title":"bravo","distance":1}]
=== query [-1,0,0,0] (top 2) ===
[{"id":5,"title":"foxtrot","distance":0.000199944594884593},
{"id":4,"title":"echo","distance":1}]
=== all 6, ordering sanity ===
[{"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}]
psql "$SUPABASE_DB_URL" -c "set local enable_seqscan=off; explain (costs off) select d.id from public.documents d where d.embedding is not null order by d.embedding <=> '[1,0,0,0]'::vector(4) limit 3;" 2>&1
SET
QUERY PLAN
-----------------------------------------------------------------------
Limit
-> Index Scan using documents_embedding_hnsw_cosine on documents d
Order By: (embedding <=> '[1,0,0,0]'::vector(4))
Filter: (embedding IS NOT NULL)
(4 rows)
python3 -c "
import math
docs={1:'alpha',2:'bravo',3:'delta',4:'echo',5:'foxtrot',6:'golf'}
emb={1:[10,.5,0,0],2:[.9,.3,0,0],3:[20,60,0,0],4:[0,1,0,0],5:[-5,.1,0,0],6:[.1,.1,3,4]}
q=[1,0,0,0]
def cd(a,b):
d=math.sqrt(sum(x*x for x in a))*math.sqrt(sum(x*x for x in b))
return 1-sum(x*y for x,y in zip(a,b))/d
r=sorted(((cd(v,q),k) for k,v in emb.items()))
print('expected order for [1,0,0,0]:')
for d,k in r: print(f' {k} {docs[k]:8s} {d:.15f}')
"expected order for [1,0,0,0]: 1 alpha 0.001247661122155 2 bravo 0.051316701949486 3 delta 0.683772233983162 6 golf 0.980007995203198 4 echo 1.000000000000000 5 foxtrot 1.999800059980007
echo "--- match_count=1 ---"; curl -s -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":1}'
echo; echo "--- service_role key ---"; curl -s -o /dev/null -w 'HTTP %{http_code}\n' -X POST "$SUPABASE_URL/rest/v1/rpc/match_documents" -H "apikey: $SUPABASE_SERVICE_ROLE_KEY" -H "Authorization: Bearer $SUPABASE_SERVICE_ROLE_KEY" -H "Content-Type: application/json" -d '{"query_embedding":[0,0,1,1],"match_count":2}'
echo "--- no apikey (should be 401) ---"; curl -s -o /dev/null -w 'HTTP %{http_code}\n' -X POST "$SUPABASE_URL/rest/v1/rpc/match_documents" -H "Content-Type: application/json" -d '{"query_embedding":[1,0,0,0],"match_count":2}'--- match_count=1 ---
[{"id":1,"title":"alpha","distance":0.00124766112215546}]
--- service_role key ---
HTTP 200
--- no apikey (should be 401) ---
HTTP 401
psql "$SUPABASE_DB_URL" -c "\d public.documents" -c "select p.proname, pg_get_function_arguments(p.oid) as args, pg_get_function_result(p.oid) as result, p.provolatile, p.prosecdef, p.proconfig from pg_proc p join pg_namespace n on n.oid=p.pronamespace where n.nspname='public' and p.proname='match_documents';" -c "select count(*) as total, count(embedding) as with_embedding from public.documents;" -c "select indexdef from pg_indexes where tablename='documents' and indexname='documents_embedding_hnsw_cosine';" 2>&1
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" hnsw (embedding vector_cosine_ops)
proname | args | result | provolatile | prosecdef | proconfig
-----------------+---------------------------------------------+----------------------------------------------------------+-------------+-----------+---------------------------------------------
match_documents | query_embedding vector, match_count integer | TABLE(id integer, title text, distance double precision) | s | f | {"search_path=public, extensions, pg_temp"}
(1 row)
total | with_embedding
-------+----------------
6 | 6
(1 row)
indexdef
-----------------------------------------------------------------------------------------------------------
CREATE INDEX documents_embedding_hnsw_cosine ON public.documents USING hnsw (embedding vector_cosine_ops)
(1 row)
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