Supabase is an open-sourceFirebase
alternative.Supabase
is built on top ofPostgreSQL
, which offers strongSQL
querying capabilities and enables a simple interface with already-existing tools and frameworks.
PostgreSQL also known asIn the notebook, we’ll demo thePostgres
, is a free and open-source relational database management system (RDBMS) emphasizing extensibility andSQL
compliance. Supabase provides an open-source toolkit for developing AI applications using Postgres and pgvector. Use the Supabase client libraries to store, index, and query your vector embeddings at scale.
SelfQueryRetriever
wrapped around a Supabase
vector store.
Specifically, we will:
- Create a Supabase database
- Enable the
pgvector
extension - Create a
documents
table andmatch_documents
function that will be used bySupabaseVectorStore
- Load sample documents into the vector store (database table)
- Build and test a self-querying retriever
Setup Supabase Database
- Head over to 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:
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 oflangchain
with openai
support:
lark
installed:
supabase
package:
SupabaseVectorStore
and OpenAIEmbeddings
, we have to load their API keys.
-
To find your
SUPABASE_URL
andSUPABASE_SERVICE_KEY
, head to your Supabase project’s API settings.SUPABASE_URL
corresponds to the Project URLSUPABASE_SERVICE_KEY
corresponds to theservice_role
API key
-
To get your
OPENAI_API_KEY
, navigate to API keys on your OpenAI account and create a new secret key.
.env
file, you can load them with dotenv
.
Creating our self-querying retriever
Now we can instantiate our retriever. To do this we’ll need to provide some information upfront about the metadata fields that our documents support and a short description of the document contents.Testing it out
And now we can try actually using our retriever!Filter k
We can also use the self query retriever to specifyk
: the number of documents to fetch.
We can do this by passing enable_limit=True
to the constructor.