# Supabase

## Prerequisite

1. Register an account for [Supabase](https://supabase.com/)
2. Click **New project**\\

   <figure><img src="/files/byRlRsf73CnAqKgo0bJm" alt=""><figcaption></figcaption></figure>
3. Input required fields\
   **Name**, name of the project to be created. (e.g. LangFlux)\
   **Database** Password, password to your postgres database. (e.g. click **Generate a password**)\\

   <figure><img src="/files/F1OketcaPh3vu1JTeYKP" alt=""><figcaption></figcaption></figure>
4. Click **Create new project** and wait for the project to finish setting up
5. Click **SQL Editor**\\

   <figure><img src="/files/0bgt9WG5oeAxSd9i4mu6" alt=""><figcaption></figcaption></figure>
6. Click **New query**\\

   <figure><img src="/files/1FfQH857BLFx8BkULfGz" alt=""><figcaption></figcaption></figure>
7. Copy & Paste [query ](https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase#create-a-table-and-search-function-in-your-database)and run it by `Ctrl + Enter` or click **RUN**\
   **Table name**: documents\
   **Query name**: match\_documents

   ```plsql
   -- 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 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;
   $$;

   ```

   <figure><img src="/files/2RAGsLZHq3pjJiOg8Ecs" alt=""><figcaption></figcaption></figure>

## Setup

1. Click **Project Settings**\\

   <figure><img src="/files/Ye9u6WcN6d4xQXfH307S" alt=""><figcaption></figcaption></figure>
2. Get your **Project URL & API Key**

   <figure><img src="/files/JFKXdMftPfZIIWutropl" alt=""><figcaption></figcaption></figure>
3. Copy & Paste each details (*API Key, URL, Table Name, Query Name*) into **Supabase Upsert Document** node or **Supabase Load Existing** node\
   ![](/files/QziPy4P6R8dziEbzbhnU)![](/files/A9z3jcd1ZbNsenSsZPGG)
4. **Document** can be connected with any node under [**Document Loader**](/integrations/document-loaders.md) category
5. **Embeddings** can be connected with any node under [**Embeddings** ](/integrations/embeddings.md)category

## Resources

* [LangChain JS Supabase](https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/supabase)
* [Supabase Blog Post](https://supabase.com/blog/openai-embeddings-postgres-vector)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.langflux.space/integrations/vector-stores/supabase.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
