Company RAG and data queries

Incremental Supabase Storage to pgvector file RAG chat workflow

Short answer

This n8n workflow lists files inside a private Supabase Storage bucket and compares them against records already logged in your Supabase files table. Only new uploads loop through TXT or PDF extraction, split into 500-character chunks and upsert into pgvector with file_id metadata for top-8 chat retrieval.

Catalogue ID
#1246
Functional nodes
22
Connections
23
Trigger
manualTrigger, chatTrigger
AI layer
AI-assisted
Business problem solved

Business problem solved

Re-indexing an entire document bucket whenever one new file lands wastes embedding tokens and creates duplicate chunks. Teams storing documents in Supabase need incremental detection before writing to pgvector.

Trigger

A manual trigger syncs new Supabase Storage files into pgvector; a chat trigger serves RAG questions.

Connected systems

Connected systems

  • Supabase Storage API
  • Supabase PostgreSQL and pgvector
  • PDF and text extraction
  • OpenAI
  • Chat interface
  • Self-hosted n8n

Every workflow is deployed on your own server with documentation, a run log and an error queue.

Workflow architecture

Workflow architecture

  1. 1. Get All files (Service and data) (connects to Loop Over Items)
  2. 2. Default Data Loader (AI layer) (connects to Insert into Supabase…)
  3. 3. Recursive Character Text… (AI layer) (connects to Default Data Loader)
  4. 4. Extract Document PDF (Service and data) (connects to Merge)
  5. 5. Embeddings OpenAI (AI layer) (connects to Insert into Supabase…)
  6. 6. Create File record2 (Service and data) (connects to Insert into Supabase…)
  7. 7. If (Logic and routing) (connects to Download, Loop Over Items)
  8. 8. Get All Files (Service and data) (connects to Aggregate)
  9. 9. Download (Service and data) (connects to Switch)
  10. 10. Loop Over Items (Logic and routing) (connects to If)
  11. 11. When clicking Test workflow (Trigger) (connects to Get All Files)
  12. 12. Aggregate (Logic and routing) (connects to Get All files)
  13. 13. When chat message received (Trigger) (connects to AI Agent)
  14. 14. OpenAI Chat Model1 (AI layer) (connects to AI Agent)
  15. 15. Embeddings OpenAI2 (AI layer) (connects to Supabase Vector Store)
  16. 16. OpenAI Chat Model2 (AI layer) (connects to Vector Store Tool1)
  17. 17. Vector Store Tool1 (AI layer) (connects to AI Agent)
  18. 18. Switch (Logic and routing) (connects to Merge, Extract Document PDF)
  19. 19. Insert into Supabase… (AI layer) (connects to Loop Over Items)
  20. 20. Merge (Logic and routing) (connects to Create File record2)
  21. 21. AI Agent (AI layer)
  22. 22. Supabase Vector Store (AI layer) (connects to Vector Store Tool1)
  • Trigger
  • AI layer
  • Logic and routing
  • Service and data

Node positions and directed links are generated from the verified catalogue record.

Workflow steps

Workflow steps

  1. 01

    Storage bucket and table diff

    HTTP lists bucket objects and compares them against the Supabase files table so already-indexed files are skipped.

  2. 02

    File logging and format switch

    Each new object registers in the files table while a switch node routes TXT and PDF payloads separately.

  3. 03

    Chunking and pgvector metadata insert

    Extracted text splits into 500-character chunks tagged with file_id metadata and inserts into the pgvector documents table.

  4. 04

    Top-8 knowledge base chat

    Chat enquiries invoke the AI agent with the Supabase knowledge_base tool retrieving the eight closest chunks.

Error queue and human approval

Error queue and human approval

Built-in state in the catalogue workflow

The verified catalogue workflow contains zero node-level error flags, while its table-comparison branch prevents duplicate re-indexing by design.

Production layer added by ALTAI

During live deployment, ALTAI adds scheduled or storage-webhook triggers, rollback cleanup if vector insertion fails after logging, row-level security filters and an error queue.

Frequently asked

Supabase Storage and pgvector RAG Frequently asked questions

No. Comparing the Storage listing against the Supabase files table filters out previously processed files.

Every chunk stores file_id metadata, allowing a single delete query against the documents table whenever a source file is removed.

Yes. Adding extra branches on the file-extension switch node handles Markdown, CSV or DOCX documents cleanly.

Mert Can Gundogdu
The founder takes the call, not a sales team
Next step

We write the proposal after we have found the problem together

In a thirty-minute call we listen to how you work and talk through where time and customers are slipping away. If you do not need a digital fix, we will tell you that too.

30 minutes · no preparation needed

The call and the week of discovery are both free.Read the terms

Chat on WhatsApp