Quick Overview
This workflow exposes a webhook-based FAQ endpoint that embeds incoming questions with OpenAI, retrieves relevant knowledge base chunks from Supabase pgvector, and asks Anthropic Claude to answer strictly from that context with citations, returning a structured JSON response.
How it works
- Receives a POST webhook request containing a user question (and optional session ID).
- Standardizes request fields and sets the Supabase URL, embedding model, top-k, and similarity threshold used for retrieval.
- Creates an embedding for the question using the OpenAI Embeddings API.
- Calls a Supabase PostgREST RPC (match_documents) backed by pgvector to return the most similar document chunks.
- Builds a citation-marked context block from the top matches (or a “no matches” context when nothing is found).
- Sends the context and question to Anthropic Claude with instructions to respond in JSON and cite only from the provided chunks.
- Parses Claude’s JSON, maps cited chunk IDs back to source metadata, and returns the answer, confidence flag, and citations in the webhook response.
Setup
- Create a Supabase Postgres database with the pgvector extension, a documents table (including an embedding vector(1536) column), and a match_documents RPC compatible with the workflow’s request body.
- Populate the Supabase documents table with chunked knowledge base content and embeddings (ingestion happens outside this workflow).
- Add HTTP Header Auth credentials for OpenAI (Authorization: Bearer <api_key>), Supabase (apikey and Authorization: Bearer <anon_key>), and Anthropic (x-api-key: <api_key>), then select them in the respective HTTP request steps.
- Update the Supabase project URL and business name in the workflow configuration, and adjust topK and matchThreshold as needed.
- Copy the production webhook URL from n8n and configure your chat UI, Slack bot, or frontend to POST a JSON body containing a question field to it.