Build a PDF-Based RAG System with OpenAI, Pinecone and Cohere Reranking - n8n Workflow

Implement a powerful Retrieval Augmented Generation (RAG) system using this advanced n8n workflow. Ingest PDFs into Pinecone via an n8n trigger, utilize OpenAI embeddings, and enhance answer quality with Cohere reranking for a high-performance chat agent.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • AI Developers and Engineers seeking ready-to-use n8n templates for RAG.

  • Businesses needing to index internal documentation (PDFs) for AI-powered search.

  • Technical users interested in leveraging specialized n8n node capabilities like vector databases and reranking.

  • Data scientists looking to operationalize LangChain logic using a low-code n8n environment.

Overview

Retrieval Augmented Generation (RAG) is essential for grounding LLMs in specific, up-to-date knowledge. This complex n8n workflow provides a complete, two-part system to manage a custom knowledge base. The first part handles data ingestion: a simple form n8n trigger allows users to upload PDF documents, which are then split, embedded using the Embeddings OpenAI n8n node, and stored in a Pinecone vector database index. The second part is a sophisticated chat agent, utilizing a dedicated chat n8n trigger. This agent uses the Pinecone VectorDB as a tool, retrieving highly relevant context. Crucially, it incorporates the Reranker Cohere n8n node to re-rank the initial search results, significantly boosting the final accuracy and relevance of the AI's response. This n8n workflow demonstrates the power of integrating multiple best-of-breed AI services into one cohesive automation solution.

How it Works

This powerful n8n workflow operates in two distinct phases, each initiated by a specific n8n trigger:

Phase 1: Data Ingestion (PDF to Vector Store)


  1. Start: The process begins with the 'On form submission' n8n trigger, requiring a PDF file upload.

  2. Load and Split: The uploaded binary file is processed by the Default Data Loader n8n node, then chunked into manageable pieces by the Recursive Character Text Splitter n8n node.

  3. Embed: The chunks are converted into vector representations using the Embeddings OpenAI n8n node.

  4. Insert: The resulting vectors are inserted into the specified Pinecone Vector Store using the 'Pinecone Vector Store' n8n node, completing the knowledge indexing process.

Phase 2: Query and Response (RAG Agent)


  1. Query Trigger: The 'When chat message received' n8n trigger initiates the query process.

  2. Agent Orchestration: The message is passed to the AI Agent n8n node, which uses a specific system prompt (to answer strictly based on the provided knowledge). It is connected to the Simple Memory n8n node for conversation context and the OpenAI Chat Model n8n node (using GPT-4.1) as the brain.

  3. Retrieval: The AI Agent utilizes the 'VectorDB' n8n node (configured for retrieval as a tool) to query the Pinecone index, retrieving the top 20 relevant documents.

  4. Reranking: The Reranker Cohere n8n node is connected to the VectorDB tool. It processes the initial top 20 results and uses Cohere's advanced semantic understanding to select the most relevant documents, ensuring high-quality context for the LLM.

  5. Response: The agent synthesizes the answer based on the highly relevant, reranked documents and the user's query, providing a grounded response.

Installation Guide

To deploy this comprehensive RAG n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON data and import it directly into your n8n instance via the 'New' menu -> 'Import from JSON'.

  2. Credential Setup: This n8n workflow requires three distinct credentials set up for the specialized n8n node components:

OpenAI API: Required for the 'Embeddings OpenAI' and 'OpenAI Chat Model' n8n nodes. Ensure your API key is configured with access to embedding and chat models (e.g., text-embedding-ada-002, gpt-4).
Pinecone API: Required for both the 'Pinecone Vector Store' (ingestion) and 'VectorDB' (retrieval) n8n nodes. Ensure the target index name ('n8n' in the provided n8n templates) exists in your Pinecone environment.
* Cohere API: Required for the 'Reranker Cohere' n8n node to perform semantic reranking.

  1. Activate Triggers: After setting credentials, activate the n8n workflow. The 'On form submission' n8n trigger and 'When chat message received' n8n trigger will generate unique public URLs for file ingestion and chat interaction, respectively.

Node Details

This advanced n8n workflow leverages several specialized n8n node components:


  • On form submission (n8n trigger): The initial entry point for the ingestion pipeline.

- Function: Listens for a file upload, specifically accepting .pdf types.
- Key Configuration: Set up as a file upload form.


  • When chat message received (n8n trigger): The entry point for the query pipeline.

- Function: Initializes the RAG chat session.


  • Pinecone Vector Store (Ingestion n8n node):

- Function: Handles the insertion of vector data into the specified Pinecone index.
- Key Configuration: Mode: insert; Target Index: n8n.


  • Embeddings OpenAI (n8n node):

- Function: Generates vector embeddings for both the ingested PDF chunks (during insertion) and the user query (during retrieval).
- Key Configuration: Utilizes the OpenAI embedding model.


  • Recursive Character Text Splitter (n8n node):

- Function: Breaks down the content of the PDF into smaller, manageable document chunks suitable for embedding.


  • VectorDB (Retrieval n8n node):

- Function: Acts as the knowledge retrieval tool for the AI Agent. This specialized Pinecone n8n node performs vector similarity search.
- Key Configuration: Mode: retrieve-as-tool; TopK: 20; Use Reranker: true.


  • Reranker Cohere (n8n node):

- Function: Refines the documents retrieved by the VectorDB tool, dramatically improving contextual relevance before presentation to the LLM. This high-value n8n node ensures optimal RAG performance.


  • AI Agent (n8n node):

- Function: The core orchestration component, connecting the Chat Model, Memory, and the VectorDB tool to execute the RAG logic.
- Key Configuration: System Message is set to enforce grounded responses based solely on the provided VectorDB context.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by

Indonesian AI & Automation Enthusiast. Automating life using n8n.

Featured*