Supabase Vector Store - 403 error to data table

Describe the problem/error/question

I’m following an n8n course and I’m pretty sure that I have everything set properly, but whenever I execute the workflow I get an access error. My Supabase account is connected via API key “service_role
secret” in legacy tab, so I don’t understand why the node is unable to access the table.
I just now tried to open Data API access in Supabase and exposed my table for access, but still got a different access error.
Would appreciate any help offered

What is the error message (if any)?

Error inserting: permission denied for sequence documents_id_seq 403 Forbidden

Please share your workflow

Share the output returned by the last node

It did not return a clear output, but what I simply need is sending the embedding vector data bakc to Supabase in a chunks.

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): In browser
  • Operating system: Windows 11 Home

This is my sql editor code for a simple vector store if it has anything related:

-- 1. Enable the pgvector extension to allow vector data types
create extension if not exists vector;

-- 2. Create the documents table to store your embeddings
create table if not exists documents (
    id bigserial primary key,
    content text,                  -- Stores the text chunk
    metadata jsonb,                -- Stores source, file name, or author data
    embedding vector(1536)         -- 1536 dimensions is standard for OpenAI models
);

-- 3. Create an HNSW index for high-performance similarity search
-- Note: Use 'vector_cosine_ops' for cosine distance searches
create index on documents using hnsw (embedding vector_cosine_ops);

-- 4. Create the similarity search function (called by AI/RAG tools)
create or replace function match_documents (
  query_embedding vector(1536),
  match_threshold float,
  match_count int
)
returns table (
  id bigint,
  content text,
  metadata jsonb,
  similarity float
)
language plpgsql stable
as $$
begin
  return query
  select
    documents.id,
    documents.content,
    documents.metadata,
    1 - (documents.embedding <=> query_embedding) as similarity
  from documents
  where 1 - (documents.embedding <=> query_embedding) > match_threshold
  order documents.embedding <=> query_embedding asc
  limit match_count;
end;
$$;

Hey @Mazen_Hassan, while you wait for a response, here are some things that might help:

Suggested resources

Automatically matched to your question.

Docs:

Forum:

@jabbson, @fahmiiireza, @Oskar_Niedojadlo - you’ve helped with similar issues before, can you take a look?

Automatically suggested by n8n’s community bot. It’s a pilot - please share feedback here.

Hi @Mazen_Hassan
The insert leaves id to the bigserial default, so Postgres calls nextval on the sequence behind that column, and a sequence carries its own grant separately from the table’s. That is why the table is reachable and the insert still comes back 403. Run this in the SQL editor:

grant usage, select on sequence documents_id_seq to anon, authenticated, service_role;

Keep that exact sequence name even though the node points at knowledge_chunks, the error is naming the sequence that table draws its ids from.
Your match_documents never got created either, step 4 has order documents.embedding where it needs order by, so that statement failed while the first three went through. The known good table and function are here:

Hi @Anshul_Namdev

Thanks for the great clarification! I copied the line of code and placed it at the end of my SQL editor. Funny enough, when I tested it, I got the same error. Turns out the editor hadn’t saved the changes yet and just took a while to do so, lol.

I appreciate your help Anshul :smile: