Build a PDF-based RAG system with OpenAI, Pinecone and Cohere reranking
This workflow contains community nodes that are only compatible with the self-hosted version of n8n.
This workflow provides a complete, ready-to-use template for a Retrieval-Augmented Generation (RAG) system. It allows you to build a powerful AI chatbot that can answer questions based on the content of PDF documents you provide, using a modern and powerful stack for optimal performance.
Good to know
- Costs: This workflow uses paid services (OpenAI, Pinecone, Cohere). Costs will be incurred based on your usage. Please review the pricing pages for each service to understand the potential expenses.
- Video Tutorial (Bahasa Indonesia): For a step-by-step guide on how this workflow functions, you can watch the accompanying video tutorial here: N8N Tutorial: Membangun Chatbot RAG dengan Pinecone, OpenAI, & Cohere
How it works
This workflow operates in two distinct stages:
1. Data Ingestion & Indexing:
- It begins when a .pdf file is uploaded via the n8n Form Trigger.
- The Default Data Loader node processes the PDF, and the Recursive Character Text Splitter breaks down the content into smaller, manageable chunks.
- The Embeddings OpenAI node converts these text chunks into vector embeddings (numerical representations).
- Finally, the Pinecone Vector Store node takes these embeddings and stores (upserts) them into your specified Pinecone index, creating a searchable knowledge base.
2. Conversational AI Agent:
- A user sends a message through the Chat Trigger.
- The AI Agent receives the message and uses its VectorDB tool to search the Pinecone index for relevant information.
- The Reranker Cohere node refines these search results, ensuring only the most relevant context is selected.
- The user's original question and the refined context are sent to the OpenAI Chat Model (
gpt-4.1), which generates a helpful, context-aware answer. - The Simple Memory node maintains conversation history, allowing for natural, multi-turn dialogues.
How to use
Using this workflow is a two-step process:
- Populate the Knowledge Base: First, you need to add documents. Trigger the workflow by using the Form Trigger and uploading a PDF file. Wait for the execution to complete. You can do this for multiple documents.
- Start Chatting: Once your data has been ingested, open the Chat Trigger's interface and start asking questions related to the content of your uploaded documents.
The Form Trigger is just an example. Feel free to replace it with other triggers, such as a node that watches a Google Drive or Dropbox folder for new files.
Requirements
To run this workflow, you will need active accounts and API keys for the following services.
- OpenAI Account & API Key:
- Function: Powers text embedding and the final chat generation. Required for the
Embeddings OpenAIandOpenAI Chat Modelnodes.
- Function: Powers text embedding and the final chat generation. Required for the
- Pinecone Account & API Key:
- Function: Used to store and retrieve your vector knowledge base. Required for the
Pinecone Vector StoreandVectorDBnodes. You also need to provide your Pinecone Environment.
- Function: Used to store and retrieve your vector knowledge base. Required for the
- Cohere Account & API Key:
- Function: Improves the accuracy of your chatbot by re-ranking search results for relevance. Required for the
Reranker Coherenode.
- Function: Improves the accuracy of your chatbot by re-ranking search results for relevance. Required for the
Customising this workflow
This template is a great starting point. Here are a few ways you can customize it:
- Change the AI Personality: Edit the System Message in the
AI Agentnode to change the bot's behavior, tone, or instructions. - Use Different Models: You can easily swap the OpenAI model for another one (e.g.,
gpt-3.5-turbofor lower costs) in theOpenAI Chat Modelnode. - Adjust Retrieval: In the
VectorDBtool node, you can modify theTop Kparameter to retrieve more or fewer document chunks to use as context. - Automate Ingestion: Replace the manual
Form Triggerwith an automated one, like a node that triggers whenever a new file is added to a specific cloud storage folder.
n8n PDF-based RAG System with OpenAI, Pinecone, and Cohere Reranking
This n8n workflow demonstrates a robust Retrieval-Augmented Generation (RAG) system designed to answer user queries based on a corpus of PDF documents. It leverages OpenAI for embeddings and chat, Pinecone as a vector store for document retrieval, and Cohere for reranking search results to improve relevance.
What it does
This workflow orchestrates a sophisticated RAG process:
- Triggers on Chat Message: The workflow starts when a new chat message is received, likely containing a user's question or query.
- Loads Documents: It uses a "Default Data Loader" to process and load documents. While the JSON doesn't specify the source (e.g., PDF files), this node is typically configured to ingest data from various sources.
- Splits Text: The loaded documents are then broken down into smaller, manageable chunks using a "Recursive Character Text Splitter." This is crucial for efficient embedding and retrieval.
- Generates Embeddings: OpenAI's Embeddings node converts these text chunks into numerical vector representations, capturing their semantic meaning.
- Stores and Retrieves Vectors: The "Pinecone Vector Store" is used to store these embeddings. When a query comes in, it's also embedded, and Pinecone is queried to find the most semantically similar document chunks.
- Reranks Results: The "Reranker Cohere" node takes the initial search results from Pinecone and re-evaluates their relevance to the original query, using Cohere's advanced reranking capabilities to provide a more accurate set of top results.
- Manages Chat Memory: A "Simple Memory" node (Buffer Window Memory) maintains the context of the conversation, allowing the AI agent to remember previous turns in the chat.
- Orchestrates AI Agent: An "AI Agent" node (LangChain Agent) acts as the central intelligence, using the OpenAI Chat Model, the Pinecone Vector Store (for retrieval), and the Cohere Reranker to formulate a comprehensive answer based on the retrieved and reranked document chunks and the ongoing conversation.
Prerequisites/Requirements
To use this workflow, you will need:
- n8n Instance: A running n8n instance.
- OpenAI API Key: For generating embeddings and powering the chat model.
- Pinecone Account & API Key: For setting up and interacting with your vector database.
- Cohere API Key: For utilizing the Cohere reranking service.
- Documents: A collection of documents (e.g., PDFs, text files) that you want your RAG system to query. The "Default Data Loader" will need to be configured to access these.
Setup/Usage
- Import the Workflow:
- Download the provided JSON file.
- In your n8n instance, go to "Workflows" and click "New Workflow".
- Click the three dots menu (...) in the top right and select "Import from JSON".
- Paste the JSON content or upload the file.
- Configure Credentials:
- Locate the "Embeddings OpenAI" and "OpenAI Chat Model" nodes and configure your OpenAI API credentials.
- Locate the "Pinecone Vector Store" node and configure your Pinecone API credentials (API Key, Environment, and Index Name).
- Locate the "Reranker Cohere" node and configure your Cohere API credentials.
- Configure Document Loading:
- Adjust the "Default Data Loader" node to point to your specific document source (e.g., local files, S3 bucket, Google Drive). You will need to ensure n8n has access to these documents.
- Ensure the "Recursive Character Text Splitter" is configured appropriately for your document structure.
- Activate the Workflow:
- Save the workflow.
- Activate the workflow by toggling the "Active" switch in the top right corner.
- Interact:
- Use the "When chat message received" trigger to send queries to your RAG system. This typically involves integrating with a chat platform (e.g., Slack, Discord, custom chat UI) that can send messages to n8n's webhook URL for this trigger.
Related Templates
Create Dynamic Seating & Venue Layout Plans with Google Sheets
Enhance event logistics with this automated n8n workflow. Triggered by seating requests, it fetches attendee data and venue templates from Google Sheets, calculates totals, and optimizes seating layouts. The workflow generates detailed recommendations, splits individual assignments, and sends alerts, ensuring efficient venue planning and real-time updates. 🎪📋 Key Features Optimizes seating arrangements based on attendee data and event type. Generates venue layouts with visual and statistical insights. Provides real-time alerts with comprehensive seating plans. Logs detailed assignments and layouts in Google Sheets. Workflow Process The Webhook Trigger node initiates the workflow upon receiving venue requirements and attendee data via webhook. Validate Request Data ensures the incoming data is complete and accurate. Fetch Attendee Data retrieves attendee information, including groups, accessibility needs, and VIP preferences from Google Sheets. Fetch Venue Templates reads venue layout templates from Google Sheets. Calculate Totals aggregates attendee data and venue constraints for optimal planning. Combine All Data merges attendee and venue data for analysis. AI Optimization uses algorithms to calculate optimal seating based on venue dimensions, attendee groups, accessibility needs, VIP placement, and aisle placement. Optimize Seating Layout refines the seating plan for efficiency. Format Recommendations structures the seating plan with visual layout map, seat assignments, statistics & metrics, and optimization tips. Split Seat Assignments divides the plan into individual seat assignments. Send Response returns the complete seating plan with visual layout map, seat assignment list, statistics & recommendations, and export-ready format. Send Alert notifies organizers with the finalized plan details. Update Sheets saves the master plan summary, individual seat assignments, and layout specifications to Google Sheets. Save Individual Assignments appends or updates individual seat assignments to Google Sheets. Setup Instructions Import the workflow into n8n and configure Google Sheets OAuth2 for data access. Set up the Webhook Trigger with your event management system's API credentials. Configure the AI Optimization node with a suitable algorithm or model. Test the workflow by sending sample seating requests and verifying layouts. Adjust optimization parameters as needed for specific venue or event requirements. Prerequisites Google Sheets OAuth2 credentials Webhook integration with the event management system Structured attendee and venue data in a Google Sheet Google Sheet Structure: Attendee Data Sheet with columns: Name Group Accessibility Needs VIP Status Preferences Updated At Venue Templates Sheet with columns: Venue Name Capacity Dimensions Layout Template Updated At Modification Options Customize the Validate Request Data node to include additional validation rules. Adjust the AI Optimization node to prioritize specific criteria (e.g., proximity, accessibility). Modify the Format Recommendations node to include custom visual formats. Integrate with venue management tools for live layout updates. Set custom alert triggers in the Send Alert node. Discover more workflows – Get in touch with us
Automate Instagram complaint handling with Claude AI, tickets & SLA management
This enterprise-grade n8n workflow automates the Instagram complaint handling process — from detection to resolution — using Claude AI, dynamic ticket assignment, and SLA enforcement. It converts customer complaints in comments into actionable support tickets with auto-assignment, escalation alerts, and full audit trails, ensuring timely responses and improved customer satisfaction with zero manual intervention. Key Features Real-time Instagram polling for new comments AI-powered complaint detection using Claude 3.5 Sonnet for sentiment and issue classification Automatic ticket creation in Google Sheets (or integrable with Zendesk/Jira) Round-robin assignment to team members from a dynamic roster SLA timer and monitoring (e.g., 24-hour response window with escalation at 80% elapsed) Escalation engine notifies managers via Slack if near breach Multi-channel notifications: Slack for assignees and escalations Audit-ready: Logs ticket details, assignments, and actions Scalable triggers: Webhook or scheduled polling Workflow Process | Step | Node | Description | | ---- | ----------------------------------- | -------------------------------------------------------- | | 1 | Schedule Trigger | Runs every 15 minutes or via webhook (/complaint-handler) | | 2 | Get Instagram Posts | Fetches recent posts from Instagram Graph API | | 3 | Get Comments | Retrieves comments for the latest post | | 4 | Loop Over Comments | Processes each comment individually to avoid rate limits | | 5 | Detect Complaint (Claude AI) | Uses AI to classify if complaint, extract issue/severity | | 6 | IF Complaint | Branches: Proceed if yes, end if no | | 7 | Get Team Members | Loads team roster from TeamMembers sheet | | 8 | Assign Ticket | Sets assignee via round-robin logic | | 9 | Create Ticket (Google Sheet) | Appends new ticket with details and SLA due date | | 10 | Notify Assignee (Slack) | Alerts assigned team member | | 11 | Wait for SLA Check | Delays to near-SLA-breach point (e.g., 20 hours) | | 12 | Check Ticket Status | Looks up ticket status in sheet | | 13 | IF SLA Breach Near | Checks if unresolved; escalates if yes | | 14 | Escalate to Manager (Slack) | Notifies manager for urgent action | | 15 | End (Non-Complaint Path) | Terminates non-complaint branches | Setup Instructions Import Workflow Open n8n → Workflows → Import from Clipboard Paste the JSON workflow Configure Credentials | Integration | Details | | ----------------- | -------------------------------------------------- | | Instagram API | Access token from Facebook Developer Portal | | Claude AI | Anthropic API key for claude-3-5-sonnet-20241022 | | Google Sheets | Service account with spreadsheet access | | Slack | Webhook or OAuth app | Update Spreadsheet IDs Ensure your Google Sheets include: SupportTickets TeamMembers Set Triggers Webhook: /webhook/complaint-handler (for real-time Instagram notifications if set up) Schedule: Every 15 minutes Run a Test Use manual execution to confirm: Ticket creation in sheet Slack notifications SLA wait and escalation logic (simulate by shortening wait time) Google Sheets Structure SupportTickets | ticketId | commentText | user | createdAt | assignedTo | status | slaDue | issueType | severity | |--------------|-------------|----------|--------------------|--------------------|--------|--------------------|---------------|----------| | TKT-12345678 | Sample complaint text | user123 | 2023-10-01T12:00:00Z | john@team.com | Open | 2023-10-02T12:00:00Z | Product Issue | Medium | TeamMembers | name | email | |-----------|-------------------| | John Doe | john@team.com | | Jane Smith| jane@team.com | System Requirements | Requirement | Version/Access | | --------------------- | ---------------------------------------------- | | n8n | v1.50+ (AI integrations supported) | | Claude AI API | claude-3-5-sonnet-20241022 | | Instagram Graph API| Business account access token | | Google Sheets API | https://www.googleapis.com/auth/spreadsheets | | Slack Webhook | Required for notifications | Optional Enhancements Integrate Zendesk/Jira for professional ticketing instead of Google Sheets Add email notifications to customers acknowledging complaints Use sentiment thresholds for prioritizing high-severity tickets Connect Twilio for SMS escalations Enable multi-platform support (e.g., Twitter/Facebook comments) Add reporting dashboard via Google Data Studio Implement auto-resolution for simple complaints using AI responses Result: A single automated system that detects, tickets, assigns, and enforces SLAs on Instagram complaints — with full AI intelligence and zero manual work. Explore More AI Workflows: Get in touch with us for custom n8n automation!
Automatic Gmail unsubscribe detection with AI and Google Sheets contact management
Automatically detect unsubscribe replies in your outreach emails and clean your Google Sheets contact list; keeping your domain reputation and deliverability strong. --- 🎯 Who it’s for This template is designed for freelancers, lead generation specialists, and outreach managers; particularly those running email outreach campaigns for clients or personal lead-gen projects. If you send cold emails, manage multiple lead lists, or handle outreach at scale, this workflow helps you automatically manage unsubscribe requests to maintain healthy email deliverability and protect your domain reputation. --- ⚙️ How it works Trigger: The workflow starts when a new reply is received in your Gmail inbox. Intent Detection: The email text is analyzed using OpenAI to detect unsubscribe intent (“unsubscribe”, “remove me”, “opt out”, etc.). Normalization & Filtering: A Code node verifies the AI output for accuracy and ensures the result is standardized as either "unsubscribe" or "keep". Check & Update Sheets: If the contact requested removal, the workflow checks your Unsubscribe Sheet to see if they’re already listed. If not, the contact is added to the Unsubscribe Sheet and simultaneously removed from your Main Outreach Sheet. Optional Gmail Label: Adds an “Unsubscribe” tag in Gmail for quick visual tracking (optional customization). --- 🧩 Requirements To run this workflow, you’ll need: Gmail Credentials → for reading incoming replies and applying labels. Google Sheets Credentials → to manage both the “Main” and “Unsubscribe” spreadsheets. OpenAI API Key → used for detecting unsubscribe intent from message text. All credentials can be added through the n8n Credentials Manager. --- 🧠 How to Customize Polling Time: Adjust how often the Gmail Trigger checks for new replies (default: every 5 minutes). Sheets: Replace the linked Google Sheets IDs with your own. You can change sheet names and columns freely. Intent Rules: Modify the Code node to include additional unsubscribe phrases or alternate keywords. Optional Gmail Tagging: Enable or disable tagging for unsubscribed messages. Secondary Validation: Enable the second “If” check after the OpenAI node to double-confirm unsubscribe intent before moving contacts. --- 💡 Why this workflow matters By automatically managing unsubscribe requests, you: Respect recipients’ opt-out preferences Reduce spam complaints Protect your domain reputation and increase deliverability Save hours of manual list cleaning This is a must-have automation for anyone running cold email outreach, especially freelancers managing multiple client inboxes. --- 🪄 Quick Setup Tips Replace all "Gmail account" and "Google Service Account account" credential references with your actual credentials. Ensure your sheet has an EMAIL column for lookup. Test with a few mock replies before activating for production. Optional: Add a time-based trigger to run the sheet cleanup periodically.