This workflow automates document storage and retrieval using PostgreSQL PGVector and OpenAI’s GPT-4o-mini and text-embedding-3-small for Retrieval-Augmented Generation (RAG). Key nodes include Manual Trigger (initiates workflow), Input Validation (sets operation, query, document_text, table_name), Validate Input (checks operation and query length), Check If Cleanup Needed, Cleanup Table (drops table), Check If Store Needed, Prepare Document (loads text), Store In PGVector (saves embeddings), Check Store Success, Check If Query Needed, Question Answer Chain (processes query), Document Loader, Token Splitter, Embeddings OpenAI (Store/QA), Vector Store Retriever, Check QA Success, Format Success Response, and error nodes (Format Validation/Store/QA Error). It uses PostgreSQL and OpenAI APIs.\n\nSetup Requirements and Configuration: Install n8n from n8n.io for self-hosting or sign up at cloud.n8n.io. Follow installation prompts or create a cloud account. Set up a PostgreSQL database with PGVector extension enabled (e.g., via cloud providers like AWS RDS or local installation). Obtain an OpenAI API key from platform.openai.com under ‘API Keys.’ In n8n, import the JSON workflow. Configure Embeddings OpenAI (Store/QA) and OpenAI Chat Model with your OpenAI API key, and Store In PGVector, Vector Store For Retrieval, and Cleanup Table with PostgreSQL credentials (host, database, user, password) under ‘Credentials’ > ‘Postgres.’ Replace Manual Trigger with a Webhook Trigger: set path to ‘pgvector-rag,’ configure for POST requests, and optionally add header authentication. Ensure sufficient server resources.\n\nTesting and Deployment Steps: Test via Postman with a POST request to the Webhook URL. Example JSON: {'operation': 'store_and_query', 'query': 'What is the size of a block header?', 'document': 'Bitcoin: A Peer-to-Peer...block header with no transactions would be about 80 bytes...'} with an authentication header if enabled. Alternatively, use Manual Trigger. The ‘Format Success Response’ node returns a 200 status with answer and table_used, or error nodes (400 for invalid inputs, 500 for store/QA errors) for issues like ‘Invalid PostgreSQL credentials’ or ‘Table not found.’ Check logs, verify credentials, and input format. Activate workflow in n8n. Validate answer matches query.
$6.99
Workflow steps: 25
Integrated apps: manualTrigger, set, if