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
- Google Drive
- Default Data Loader
- Question and Answer Chain
- OpenAI Chat Model
- Vector Store Retriever
- Recursive Character Text Splitter1
- Customize Response
- When chat message received
- Retrieve by Query
- Embeddings OpenAI Retrieval
- Embeddings OpenAI Insertion
- Placeholder (File/Content to Upsert)
- Embeddings OpenAI Upserting
- Insert Documents
16 steps in total.
Similar automations
RAG & Knowledge BasesAnswer Drive Document Questions with Supabase and OpenAI23 stepsRAG & Knowledge BasesTelegram Document Assistant with Gemini and Supabase25 stepsRAG & Knowledge BasesDocument Chatbot with RAG, OpenAI, Supabase and Cohere Reranker13 stepsRAG & Knowledge BasesAnswer HR Policy Questions from BambooHR with OpenAI39 steps