Has anyone solved 22000 different vector dimensions 1536 and 768 error with pgvector in n8n + Supabase?

I’m using Supabase + pgvector inside my n8n workflow to store and search document embeddings.
Here’s what I did:

  • Created my table like this:

  • create table DNA_builder_questions (
      id bigserial primary key,
      content text, -- corresponds to Document.pageContent
      metadata jsonb, -- corresponds to Document.metadata
      embedding vector(768) -- 1536 works for OpenAI embeddings, change if needed
    );
    -- Create a function to search for documents
    create function match_UVP (
      query_embedding vector(768),
      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 - (documents.embedding <=> query_embedding) as similarity
      from documents
      where metadata @> filter
      order by documents.embedding <=> query_embedding
      limit match_count;
    end;
    $$;
    
  1. I inserted embeddings that are 768 dimensions (from the model I’m currently using).
  2. Insert works fine, data is stored correctly.
  3. But when I run a search using the match_documents function, I get this error:

“Error searching for documents: 22000 different vector dimensions 1536 and 768”

It seems my table expects 1536 dimensions, but my vectors are 768.

Has anyone here experienced the same mismatch problem? Would love to hear how you have handled this!

Thanks :folded_hands:

Hey @Mohamed_Necib2 hope all is good.

Two potential issues I see:

  • in your match function *match_UVP" you are still referencing documents table:

  • in your workflow you are probably using match_documents instead of your match_UVP.

Thank you @jabbson