Use this sophisticated n8n workflow to deploy a high-performance, cost-optimized RAG solution. It leverages multiple OpenAI models to handle complex reasoning and vector store retrieval efficiently.
Download this n8n workflow template and start using it instantly.
AI developers looking for advanced n8n templates for RAG.
Users who need to implement custom knowledge bases using vector stores.
Anyone seeking to reduce operational costs associated with powerful LLMs like GPT-4 in production RAG systems.
Technical users deploying custom language models and AI agents via an n8n workflow.
This powerful n8n workflow demonstrates a crucial technique for cost optimization in Retrieval-Augmented Generation (RAG) applications. It is split into two logical flows: a Data Loading flow and a Retriever flow. The core value of this n8n template lies in its intelligent use of two separate OpenAI models. The initial AI Agent reasoning and tool selection utilize a more powerful, 'Expensive model' (e.g., GPT-4) for high-quality decision-making. However, the heavy lifting of answering the query based on retrieved documents—which is called frequently—is delegated to a 'Cheap Model' (e.g., GPT-4-mini or similar low-cost model). This strategic separation significantly reduces token consumption costs while maintaining high quality results for the entire n8n workflow. The flow starts with an n8n trigger for data upload and uses a separate n8n trigger for the chat interface.
This n8n workflow operates in two distinct phases:
Upload your file here n8n trigger, which is a Form Trigger that accepts PDF or CSV files.Default Data Loader n8n node, which prepares the documents.Embeddings OpenAI n8n node generates vector representations (embeddings) for the loaded documents.Insert Data to Store n8n node stores these embeddings and corresponding documents into a temporary in-memory vector store, indexed by vectorstorekey.When chat message received n8n trigger, designed specifically for chat interfaces.AI Agent n8n node. This agent uses the designated Expensive model for reasoning and deciding which tools to use.Answer questions with a vector store tool, which is customized to access the local data.Query Data Tool n8n node.Answer questions with a vector store tool is itself powered by the Cheap Model. This means the expensive n8n node handles the high-level reasoning, but the actual retrieval and text generation from the context uses the low-cost n8n model, delivering massive savings on per-query execution.To deploy this comprehensive n8n workflow, follow these steps:
Embeddings OpenAI, Expensive model, and Cheap Model n8n nodes require an active OpenAI API key credential (ID '14' in the provided JSON).Upload your file here n8n trigger and provide your document(s) (PDF or CSV).When chat message received n8n trigger and start asking questions about the document content. The overall n8n workflow is now active and ready to use. Upload your file here (n8n trigger): A Form Trigger that initiates the data loading pipeline. It is configured to accept .pdf and .csv files.
Embeddings OpenAI: Generates high-dimensional vector embeddings for the documents using the OpenAI service, essential for RAG.
Insert Data to Store: A LangChain vectorStoreInMemory n8n node. This stores the document chunks and their embeddings in a temporary, in-memory location for quick retrieval using the key vectorstorekey.
When chat message received (n8n trigger): A Chat Trigger that listens for incoming messages, kicking off the Q&A process. This is the primary n8n trigger for the retrieval flow.
Expensive model (LangChain LM): Uses a powerful model (gpt-4.1 placeholder) to provide high-quality reasoning to the AI Agent for complex tool use and planning.
AI Agent: The central decision-making n8n node. It determines when and how to use the available tools, driven by the Expensive model.
Answer questions with a vector store (LangChain Tool): A custom tool exposed to the AI Agent. Crucially, this tool's internal retrieval and response generation uses the designated Cheap Model (gpt-4.1-mini placeholder), enabling the cost-saving strategy of this specific n8n workflow.
Query Data Tool: Retrieves relevant document snippets from the in-memory vector store based on the user query embedding.
Generate dynamic, SEO-optimized content strategies (Markdown) using a powerful n8n workflow. Integrate human approval via gotoHuman and automatically save the reviewed documents to Google Docs using the Google Drive n8n node.

Use this powerful n8n workflow to automatically capture article links shared via Telegram, leveraging GPT-4o to generate highlights and tags before saving the structured content directly into your Notion knowledge base.

Use this comprehensive n8n workflow to automatically migrate old Salesforce ContentDocument files to AWS S3 storage, minimizing data storage costs and cleaning up your CRM instance.

Automate logging Hotmart sales events (purchases, refunds, protests) directly to Google Sheets using a custom n8n workflow. Perfect for e-commerce tracking and analysis.

Use this robust n8n workflow to automatically sync your saved Mastodon bookmarks to Raindrop.io, ensuring no link is lost. This powerful n8n node configuration handles incremental updates and pagination.

Use this comprehensive n8n workflow to automatically capture Telegram messages, voice notes, and audio files. It uses OpenAI for transcription and DeepSeek AI Agents for intelligent summarization, storing the results in Notion.








































