table  documents (    id uuid 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 documentscreate function match_documents (  query_embedding vector (1536),  filter jsonb default '{}') returns table (  id uuid,  content text,  metadata jsonb,  similarity float) language plpgsql as $$#variable_conflict use_columnbegin  return query  select    id,    content,    metadata,    1 - (documents.embedding <=> query_embedding) as similarity  from documents  where metadata @> filter  order by documents.embedding <=> query_embedding;end;$$;# with pippip install supabase# with conda# !conda install -c conda-forge supabaseWe want to use OpenAIEmbeddings so we have to get the OpenAI API Key.import osimport getpassos.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API Key:")os.environ["SUPABASE_URL"] = getpass.getpass("Supabase URL:")os.environ["SUPABASE_SERVICE_KEY"] = getpass.getpass("Supabase Service Key:")# If you're storing your Supabase and OpenAI API keys in a .env file, you can load them with dotenvfrom dotenv import load_dotenvload_dotenv()First we'll create a Supabase client and instantiate a OpenAI embeddings class.import osfrom supabase.client import Client, create_clientfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.vectorstores import SupabaseVectorStoresupabase_url = os.environ.get("SUPABASE_URL")supabase_key = os.environ.get("SUPABASE_SERVICE_KEY")supabase: Client = create_client(supabase_url, supabase_key)embeddings = OpenAIEmbeddings()Next we'll load and parse some data for our vector store (skip if you already have documents with embeddings stored in your DB).from langchain.text_splitter import CharacterTextSplitterfrom langchain.document_loaders import TextLoaderloader = TextLoader("../../modules/state_of_the_union.txt")documents =
Supabase is an open-source Firebase alternative. Supabase is built on top of PostgreSQL, which offers strong SQL querying capabilities and enables a simple interface with already-existing tools and frameworks.
Supabase is an open-source Firebase alternative. Supabase is built on top of PostgreSQL, which offers strong SQL querying capabilities and enables a simple interface with already-existing tools and frameworks. ->: table  documents (    id uuid 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 documentscreate function match_documents (  query_embedding vector (1536),  filter jsonb default '{}') returns table (  id uuid,  content text,  metadata jsonb,  similarity float) language plpgsql as $$#variable_conflict use_columnbegin  return query  select    id,    content,    metadata,    1 - (documents.embedding <=> query_embedding) as similarity  from documents  where metadata @> filter  order by documents.embedding <=> query_embedding;end;$$;# with pippip install supabase# with conda# !conda install -c conda-forge supabaseWe want to use OpenAIEmbeddings so we have to get the OpenAI API Key.import osimport getpassos.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API Key:")os.environ["SUPABASE_URL"] = getpass.getpass("Supabase URL:")os.environ["SUPABASE_SERVICE_KEY"] = getpass.getpass("Supabase Service Key:")# If you're storing your Supabase and OpenAI API keys in a .env file, you can load them with dotenvfrom dotenv import load_dotenvload_dotenv()First we'll create a Supabase client and instantiate a OpenAI embeddings class.import osfrom supabase.client import Client, create_clientfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.vectorstores import SupabaseVectorStoresupabase_url = os.environ.get("SUPABASE_URL")supabase_key = os.environ.get("SUPABASE_SERVICE_KEY")supabase: Client = create_client(supabase_url, supabase_key)embeddings = OpenAIEmbeddings()Next we'll load and parse some data for our vector store (skip if you already have documents with embeddings stored in your DB).from langchain.text_splitter import CharacterTextSplitterfrom langchain.document_loaders import TextLoaderloader = TextLoader("../../modules/state_of_the_union.txt")documents =