03DATABASE SETUP

Database Setup

Setting up the core data storage for our YouTube RAG project using Supabase.


Let us realize now start with setting up the most important thing in our project, "DATABASE".

Tables for Supabase

We will be creating a total of 5 tables for this project, each table having their own respective functionalities.

documents

This will help store the id and the timestamps of the youtube video.

conversations

This will help store the conversation id and timestamp of the RAG chat.

embedded_documents

This will be the most important table as it will contain the content, its embedding, metadata, along with the document id.

conversation_messages

This will be the actual conversations between the user and the assistant.

conversation_documents

This will store the document id and conversation id to keep a track of the conversations.


Setting up the DB

Follow the steps given below to setup your Supabase Database:

  1. Head over to your Supabase Dashboard and then go to Table Editor
    Table Editor
  2. Now, click on New Table.
    New Table
  3. This is the point where you start configuring the columns and data type for the respective columns in your table.
    Configuring Columns
  4. Start creating the following tables with their respective configurations:
    Table NameTable ContentData TypeDefault Value
    documentsiduuidgen_random_uuid()
    created_attimestampznow()
    conversationsiduuidgen_random_uuid()
    created_attimestampznow()
    embedded_documentsiduuidgen_random_uuid()
    created_attimestampznow()
    contenttextNULL
    metadatajsonbNULL
    embeddingvectorNULL
    document_iduuid((metadata ->> 'documentId'::text))::uuid
    conversation_messagesid#int8-
    created_attimestampznow()
    conversation_iduuidgen_random_uuid()
    contenttextNULL
    roletextNULL
    conversation_documentsiduuidgen_random_uuid()
    created_attimestampznow()
    document_iduuidgen_random_uuid()
    conversation_iduuidgen_random_uuid()

    - Here there is a new vector datatype as we see in embedded_documents table. Follow the steps given here to enable vector datatype in Supabase.

    - Also for the table conversation_documents we will have the following configuration for the foreign keys from conversations table and documents table.

    Foreign Key 1
    Foreign Key 2
  5. Now you are good to go.

⚙️ Next Steps

In the next section, we’ll:

  • Start with creating the backend APIs to for storing and fetching the documents
  • Complete Backend from getting the url, fetching transcripts, converting them to embedding, splitting them, storing into database.

If you want to know more about this, do checkout our video Guide: