Supabase vector store for AI agent retrieval

Describe the problem/error/question

Hi, so I have this error with Supabase vector store (again) when I tried to hook it up with AI agent tool and actually test it for the document I created.
The error is (PGRST202) it just fails to get back with the data information and I don’t know why. I found an old topic asking for the exact same error:

And again, the sql editor code had something to do with it, so I copy pasted the code it was offered as a solution, unfortunetly, I got the exact same error :frowning:

What is the error message (if any)?

Error searching for documents: PGRST202 Could not find the function public.match_documents(filter, match_count, query_embedding) in the schema cache Searched for the function public.match_documents with parameters filter, match_count, query_embedding or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.

Please share your workflow

Information on your n8n setup

  • n8n version: 2.35.7
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Browser
  • Operating system: Windows 11 Home

Hi @Mazen_Hassan
n8n’s Supabase retrieval calls match_documents with the named arguments filter, match_count and query_embedding, and the function from your setup SQL in yesterday’s thread is declared with match_threshold instead of filter, so PostgREST finds no function with that signature, which is exactly what PGRST202 reports. Pasting the block from the old topic could not fix it: that block starts with create extension vector without if not exists, the SQL editor runs the whole paste as one batch, and the first statement errors on your project, so the create function at the bottom never executed.
Run just this in a new SQL editor query, it removes the old signature and creates the one n8n expects against your table:

drop function if exists match_documents(vector, float, int);

create or replace function match_documents (
  query_embedding vector(1536),
  match_count int default null,
  filter jsonb default '{}'
) returns table (
  id bigint,
  content text,
  metadata jsonb,
  similarity float
)
language plpgsql
as $$
#variable_conflict use_column
begin
  return query
  select
    id,
    content,
    metadata,
    1 - (knowledge_chunks.embedding <=> query_embedding) as similarity
  from knowledge_chunks
  where metadata @> filter
  order by knowledge_chunks.embedding <=> query_embedding
  limit match_count;
end;
$$;

notify pgrst, 'reload schema';

The whole vector store and RAG setup in n8n is covered here:
https://axshul.site/n8n/guide/vector-stores-and-rag/

Hi @Anshul_Namdev, I read your reply and got a better understanding of what is being requested, but I tested your code back in sql editor and tried my workflow again. Still gives the same error :frowning:

PGRST202 persisting after that create means the database your workflow talks to still has no match_documents with those three named parameters, so the statement did not land where the node is looking. Run this in the SQL editor and look at the output:

select n.nspname as schema, p.proname, pg_get_function_identity_arguments(p.oid) as arguments
from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where p.proname = 'match_documents';

No rows: the block never executed. Run it again on its own and read the result panel for red error text, and compare the project ref in the SQL editor’s URL with the Host in your n8n Supabase credential, editing one project while the workflow calls another produces exactly this.
A row where schema is not public, or arguments not named query_embedding, match_count and filter: run the block from my last reply again as posted.
A row with schema public and those three names: run notify pgrst, 'reload schema'; on its own, give it a minute, then test the workflow again.
Paste the query’s output here if it still fails after that.

So I have execute a full run of the code you gave me and also tested the piece of code you sent. Everything return no rows. Does this have anything to do with the actual data table, or naming conventions?

“Success. No rows returned” is the block working. drop, Ah i think you got it figured out. :smiley:

It seems like it, thank you so much @Anshul_Namdev :smile: — I just hope it doesn’t break again by itself, you said that I give it time to refresh and that was the case : )