RAG Knowledge Pipeline

A retrieval-augmented generation system built with n8n and Supabase pgvector — lets an AI agent answer questions grounded in a client's private document library.

n8nSupabasepgvectorRAGEmbeddingsOpenAI API
2024-08

Overview

Most LLM deployments hallucinate when asked about proprietary data. This RAG pipeline solves that by giving the model grounded context — relevant chunks from the client's actual documentation — before generating any answer.

Architecture

Ingestion Pipeline

  1. Document intake — files uploaded to a watched folder or via webhook trigger
  2. Chunking — documents are split into overlapping 512-token chunks using a custom n8n function node
  3. Embedding — each chunk is embedded via OpenAI's text-embedding-3-small model
  4. Storage — vectors + original chunk text stored in a Supabase pgvector table with metadata (source file, chunk index, timestamp)

Query Pipeline

  1. User question arrives via webhook or chat UI integration
  2. Query embedding — the question is embedded with the same model
  3. Semantic search — a Supabase RPC call runs a cosine-similarity search, returning the top-k most relevant chunks
  4. Context injection — chunks are assembled into a structured prompt alongside the user's question
  5. LLM call — Claude or GPT-4 generates an answer, citing which source chunks it used
  6. Response delivery — answer returned to the caller with source references

Key Design Decisions

  • n8n as orchestrator — no custom server needed; the whole pipeline runs as n8n workflows, fully visible and editable by non-engineers
  • pgvector over a dedicated vector DB — Supabase already in the client's stack; one fewer moving part
  • Metadata filtering — queries can be scoped to a specific document category before the vector search runs
  • Source citation — every answer includes chunk references so users can verify claims

Outcome

Reduced the client's support team's time-to-answer for internal policy questions from 15–20 minutes (manual document search) to under 30 seconds.


← BACK TO AI AUTOMATION & AGENTS