Deploy an adaptive RAG system using this advanced n8n workflow. It classifies user queries (Factual, Analytical, Opinion) and tailors retrieval strategies with Google Gemini and Qdrant, ensuring high accuracy. This n8n template is ideal for complex knowledge bases.
Download this n8n workflow template and start using it instantly.
Traditional RAG pipelines often use a one-size-fits-all retrieval approach, which can perform poorly when faced with diverse query types (e.g., factual vs. analytical). This specialized n8n workflow solves this challenge by implementing an Adaptive RAG system. The core innovation of this n8n template is using a powerful Google Gemini model to classify the incoming query (Factual, Analytical, Opinion, or Contextual) and then applying a corresponding, optimized retrieval strategy. For instance, a factual query is enhanced for precision, while an analytical query is broken down into sub-questions for comprehensive retrieval. This entire process is orchestrated efficiently within the n8n environment, utilizing the Qdrant vector database for storage, making this a highly valuable n8n workflow for deploying smart, tailored AI agents.
This n8n workflow initiates either via a Chat trigger or by an upstream n8n workflow execution, accepting the user query and session context.
Combined Fields n8n node standardizes the input variables (user query, chat memory key, and Qdrant vector store ID) coming from the initial n8n trigger.Query Classification n8n node (powered by Gemini) analyzes the user’s request, categorizing it as Factual, Analytical, Opinion, or Contextual using a carefully defined system prompt.Switch n8n node directs the subsequent execution path to one of four retrieval strategies based on the classification output. This is the heart of the adaptive logic in this n8n workflow.Factual Strategy - Focus on Precision) uses a Gemini model to adapt the query. For example, the analytical branch generates three comprehensive sub-questions, and the contextual branch infers implied user context. Each branch utilizes its own Chat Buffer Memory n8n node for intermediate conversational context.Set n8n nodes prepare both the adapted query/output and a tailored system prompt specifically designed for the final answer generation based on the query type (e.g., instructing the model to 'present diverse perspectives' for Opinion queries). These merge into Set Prompt and Output.Retrieve Documents from Vector Store n8n node uses the adapted query/sub-questions, coupled with Gemini Embeddings, to fetch the top 10 relevant document chunks from the specified Qdrant collection.Concatenate Context n8n node combines the retrieved document snippets into a single, comprehensive context block.Answer LangChain Agent n8n node, leveraging the tailored prompt, the retrieved context, and the shared Chat Buffer Memory, generates the final, context-aware response.Respond to Webhook n8n node.To utilize this adaptive RAG n8n template, follow these steps:
Gemini Classification, Gemini Answer, and all strategy nodes). Retrieve Documents from Vector Store n8n node.Combined Fields n8n node. In the 'vectorstoreid' assignment, replace with the actual collection name in your Qdrant instance that holds your knowledge base documents.Chat n8n trigger or by calling the workflow externally. Chat / When Executed by Another Workflow (n8n trigger): Serves as the initiation point for the n8n workflow, accepting the user query and session context.
Query Classification (LangChain Agent): Uses Google Gemini to classify the input into one of four categories (Factual, Analytical, Opinion, Contextual). This crucial n8n node determines the downstream strategy.
Switch (n8n node): Routes the execution based on the classification result, enabling the adaptive behavior of the n8n workflow.
Factual/Analytical/Opinion/Contextual Strategy (LangChain Agent): Four separate n8n nodes, each using Gemini to strategically adapt the user query for optimal retrieval. For example, the Analytical strategy generates sub-questions.
Gemini Embeddings (n8n node): Provides the necessary embedding model (models/text-embedding-004) for the Qdrant retrieval step.
Retrieve Documents from Vector Store (Qdrant): Performs the similarity search using the adapted query and specified vectorstoreid, fetching relevant document chunks.
Chat Buffer Memory (n8n node): Ensures continuity by managing conversation history across multiple turns for both intermediate query adaptation and the final answer generation.
Answer (LangChain Agent): The final n8n node in the generation phase. It combines the tailored system prompt, chat history, and retrieved context to produce the final, high-quality answer.
Automate daily email digests using this powerful n8n workflow. Summarize labeled Gmail messages with OpenAI (GPT-4o Mini) and send a consolidated, formatted HTML report.

Learn how to build a robust n8n workflow for web scraping, AI data extraction with Claude, vector embedding generation using Ollama, and persistence in a Qdrant vector database. This n8n workflow template is perfect for RAG systems.

Use this powerful n8n workflow to automate web scraping with Bright Data, process and structure data using the Gemini AI agent, and create RAG-ready vector datasets in Pinecone.

Use this powerful n8n workflow to automatically generate animated podcast videos from scratch, leveraging OpenAI (GPT/DALL-E) for content, Hedra for video synthesis, and Google Drive for storage.

Generate animated illustrations by chaining Midjourney image generation with Kling video creation using this powerful, automated n8n workflow. Integrate AI APIs and manage asynchronous tasks effortlessly with key n8n node logic.

Use this complex n8n workflow to automate the entire process of generating narrated stories, creating custom images with Midjourney, animating them with Kling, and assembling the final video using Creatomate API.

Founder & Systems Architect | Quantra Labs Engineering scalable solutions across AI, Blockchain, and Fintech.