Skip to content
NEWMarketplace and the trig8n Agent: sell what you build, and get plans and changes that are tested before you see them. See what is new

Library / RAG & Knowledge Bases

RAG & Knowledge Bases

Answer Drive Document Questions with OpenAI and Supabase

When a chat message arrives, OpenAI answers using documents from Google Drive stored and retrieved as vectors in Supabase.

What it does

# PREPARATION (in Supabase) - your database needs the extension 'pgvector' enabled -> select Database > Extension > Search for 'vector' - make sure you have a table that has the following columns (if not, use the query below in the Supabase SQL Editor) ALTER TABLE "YOUR TABLE NAME" ADD COLUMN embedding VECTOR(1536), // check which number of dimensions you need (depends on the embed model) ADD COLUMN metadata JSONB, ADD COLUMN content TEXT; - make sure you have the right policies set -> select Authentication > Policies - make sure you have the custom function match_documents set up in Supabase -> This is needed for the Vector Store Node (as query name) (if not, use the query below in the Supabase SQL Editor to create that function) - make sure you check the size of the AI model as it should be the same vector size for the table (e.g. OpenAI's Text-Embedding-3-Small uses 1536) CREATE OR REPLACE FUNCTION public.match_documents( filter JSONB, match_count INT, query_embedding VECTOR(1536) // should match same dimensions as from insertion ) RETURNS TABLE ( id BIGINT, content TEXT, metadata JSONB, embedding VECTOR(1536), // should match same dimensions as from insertion similarity FLOAT ) LANGUAGE plpgsql AS $$ BEGIN RETURN QUERY SELECT v.id, v.content, v.metadata, v.embedding, 1 - (v.embedding match_documents.query_embedding) AS similarity FROM "YOUR TABLE NAME" v WHERE v.metadata @> filter ORDER BY v.embedding match_documents.query_embedding LIMIT match_count; END; $$ ;

The steps

  1. Google Drive
  2. Default Data Loader
  3. Question and Answer Chain
  4. OpenAI Chat Model
  5. Vector Store Retriever
  6. Recursive Character Text Splitter1
  7. Customize Response
  8. When chat message received
  9. Retrieve by Query
  10. Embeddings OpenAI Retrieval
  11. Embeddings OpenAI Insertion
  12. Placeholder (File/Content to Upsert)
  13. Embeddings OpenAI Upserting
  14. Insert Documents

16 steps in total.

Similar automations