using Postgres and pgvector. Use the Supabase client libraries to store, index, and query your vector embeddings at scale.In the notebook, we'll demo the SelfQueryRetriever wrapped around a Supabase vector store.Specifically, we will:Create a Supabase databaseEnable the pgvector extensionCreate a documents table and match_documents function that will be used by SupabaseVectorStoreLoad sample documents into the vector store (database table)Build and test a self-querying retrieverSetup Supabase Database‚ÄãHead over to https://database.new to provision your Supabase database.In the studio, jump to the SQL editor and run the following script to enable pgvector and setup your database as a vector store:-- Enable the pgvector extension to work with embedding vectorscreate extension if not exists vector;-- Create a table to store your documentscreate 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;$$;Creating a Supabase vector store‚ÄãNext we'll want to create a Supabase vector store and seed it with some data. We've created a small demo set of documents that contain summaries of movies.Be sure to install the latest version of langchain with openai support:%pip install langchain openai tiktokenThe self-query retriever requires you to have lark installed:%pip install larkWe also need the supabase package:%pip
Supabase is an open-source Firebase alternative.
Supabase is an open-source Firebase alternative. ->: using Postgres and pgvector. Use the Supabase client libraries to store, index, and query your vector embeddings at scale.In the notebook, we'll demo the SelfQueryRetriever wrapped around a Supabase vector store.Specifically, we will:Create a Supabase databaseEnable the pgvector extensionCreate a documents table and match_documents function that will be used by SupabaseVectorStoreLoad sample documents into the vector store (database table)Build and test a self-querying retrieverSetup Supabase Database‚ÄãHead over to https://database.new to provision your Supabase database.In the studio, jump to the SQL editor and run the following script to enable pgvector and setup your database as a vector store:-- Enable the pgvector extension to work with embedding vectorscreate extension if not exists vector;-- Create a table to store your documentscreate 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;$$;Creating a Supabase vector store‚ÄãNext we'll want to create a Supabase vector store and seed it with some data. We've created a small demo set of documents that contain summaries of movies.Be sure to install the latest version of langchain with openai support:%pip install langchain openai tiktokenThe self-query retriever requires you to have lark installed:%pip install larkWe also need the supabase package:%pip