Build an OpenAI RAG system with document upload, semantic search and caching
Ready for 3.0What this workflow does
This AI workflow has 20 nodes and runs when an HTTP POST request hits its webhook URL. Along the way it connects Embeddings OpenAI, Postgres PGVector Store, Postgres and OpenAI Chat Model and 1 more.
How it runs
Trigger: When an HTTP POST request hits its webhook URL.
- Workflow Configuration (Edit Fields (Set)): sets 5 fields: chunkSize, chunkOverlap, topK…
- Route by Action (Switch): routes items into 2 branches
- Extract Text from Document (Extract from File): extracts data from a file (pdf)
- Check Query Cache (Postgres): run a query
- Store Embeddings in PGVector (Postgres PGVector Store): stores documents in the Postgres PGVector Store vector store, with embeddings: OpenAI Embeddings; document loader: Document Loader
- Cache Hit or Miss (Switch): routes items into 2 branches
- Log Upload to Cache (Postgres): run a query
- Format Cached Response (Edit Fields (Set)): sets 3 fields: answer, cached, user_id
- Answer Query with Context (AI Agent): runs an AI agent, with model: OpenAI Chat Model; 1 tool (Answer questions with a vector store)
- Respond Upload Success (Respond to Webhook): sends the response back to the webhook caller
…plus 3 more steps. See the full node list below.
Services it uses
Before you upgrade to n8n 3.0
Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.
Nodes used (13)
- Webhook
n8n-nodes-base.webhook - Edit Fields (Set)
n8n-nodes-base.set - Switch
n8n-nodes-base.switch - Extract from File
n8n-nodes-base.extractFromFile - Recursive Character Text Splitter
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter - Default Data Loader
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - Embeddings OpenAI
@n8n/n8n-nodes-langchain.embeddingsOpenAi - Postgres PGVector Store
@n8n/n8n-nodes-langchain.vectorStorePGVector - Postgres
n8n-nodes-base.postgres - Respond to Webhook
n8n-nodes-base.respondToWebhook - OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - AI Agent
@n8n/n8n-nodes-langchain.agent - Vector Store Question Answer Tool
@n8n/n8n-nodes-langchain.toolVectorStore
From the author
Overview This workflow implements a complete Retrieval-Augmented Generation (RAG) system for document ingestion and intelligent querying. It allows users to upload documents, convert them into vector embeddings, and query them using natural language. The…