Invoking an edge function via Supabase trigger/function

Hi all,

I'm working on implementing a RAG system in Supabase. Here's the desired flow for the part I'm focusing on at the moment:

New row is inserted in "document_chunks" table -> trigger fires to execute function "call_embed_edge_function" -> function runs, sends http post request to invoke "embed" edge function and pass "chunk_id" and "chunk_content" to it -> edge function runs, generates embed and updates row based on "chunk_id"

The issue I'm having now is that, while I've troubleshooted my trigger + function to the point where I don't get Supabase errors on attempting insert into "document_chunks", my edge function is still not getting invoked i.e. both invocations and logs are completely empty in the dashboard.

Here are the function & trigger definitions for reference:

create or replace function public.call_embed_edge_function()
returns trigger
language plpgsql
as $$
begin

perform
  net.http_post(
    url:=supabase_url() || '/functions/v1/embed',
    headers:= jsonb_build_object(
    'Content-Type', 'application/json',
    'Authorization', current_setting('request.headers')::json->>'authorization'
    ),
    body := jsonb_build_object(
      'chunk_id', new.id,
      'chunk_content', new.content
    )
  );

return null;

end;
$$;

CREATE or replace TRIGGER on_chunk_insert
AFTER INSERT ON public.document_chunks
FOR EACH ROW
EXECUTE PROCEDURE public.call_embed_edge_function();


Anyone see what I'm doing wrong?

Thanks,
GD
Was this page helpful?