Flowise icon indicating copy to clipboard operation
Flowise copied to clipboard

[BUG] Supabase Setup

Open JayP127 opened this issue 2 years ago • 2 comments

Using the same template to query a csv file works with Pinecone but not with Supabase. I get the following error with Supabase:

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

I am attaching a screenshot: image

I have triple-checked the Supabase API Key and Project URL. They seem to be OK

JayP127 avatar May 24 '23 15:05 JayP127

Yeah I'm getting some other type of errors with Supabase.. Seems like there is an update needed perhaps?

mgunnin avatar May 24 '23 17:05 mgunnin

you'll have to use the pg-vector extension. you can follow the guide here:

1.) Register Supabase account

2.) Dashboard => New Project => SQL Editor => New Query

3.) Copy & Paste queries below and execute:

-- Enable the pgvector extension to work with embedding vectors
create extension vector;

-- Create a table to store your documents
create table documents (
  id bigserial primary key,
  content text, -- corresponds to Document.pageContent
  metadata jsonb, -- corresponds to Document.metadata
  embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
);

-- Create a function to search for documents
create function match_documents (
  query_embedding vector(1536),
  match_count int,
  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;
$$;

HenryHengZJ avatar May 24 '23 17:05 HenryHengZJ

There we go! Thank you! Works like a charm now <3

mgunnin avatar May 24 '23 18:05 mgunnin

I have it working now. I also have a couple of comments regarding the "Supabase Upsert Document" module:

  1. The Supabase API Key corresponds to the "service_role" key
  2. The Query Name field corresponds to the name of the function, in the code you presented above, the function is "match_documents".

Best.

Jay

JayP127 avatar May 25 '23 15:05 JayP127

I tried everything as described here, documents are being upserted however there is an error: 42883 operator does not exist: extensions.vector <=> extensions.vector null

I couldn't run this command as it said its already installed: "create extension vector;"

Screen Shot 2023-05-30 at 04 48 50

Regards

jbainpro avatar May 30 '23 12:05 jbainpro

I solved the issue.

jbainpro avatar May 30 '23 18:05 jbainpro

@HenryHengZJ and @mgunnin just wanted to say ty. Reading both your comments allowed me to set up a working example. I wish some of that was in official documentation or something tho, cause I was lost for a good while. Anyway, thanks again.

sunnythaper avatar Jun 01 '23 23:06 sunnythaper

@sunnythaper its now available - https://docs.flowiseai.com/vector-stores/supabase

HenryHengZJ avatar Jun 02 '23 00:06 HenryHengZJ

@HenryHengZJ wow, thank you so much! I hope this saves future users some time! Potentially future me when I try to do this again after a brief hiatus.

sunnythaper avatar Jun 02 '23 04:06 sunnythaper