Adaptive RAG Chat Agent with Gemini and Qdrant - n8n Workflow

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.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • n8n Automation Specialists looking to build advanced, context-aware AI applications.

  • AI/ML Engineers needing a scalable framework for adaptive RAG deployment.

  • Technical teams requiring nuanced answers from complex knowledge bases stored in Qdrant.

  • Users searching for sophisticated n8n templates for large language model orchestration.

Overview

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.

How it Works

This n8n workflow initiates either via a Chat trigger or by an upstream n8n workflow execution, accepting the user query and session context.


  1. Input Consolidation: The Combined Fields n8n node standardizes the input variables (user query, chat memory key, and Qdrant vector store ID) coming from the initial n8n trigger.

  2. Query Classification: The 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.

  3. Adaptive Routing: The 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.

  4. Strategy Implementation: One of the four dedicated LangChain Agent n8n nodes (e.g., 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.

  5. Prompt Preparation: Dedicated 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.

  6. Document Retrieval (RAG): The 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.

  7. Context Assembly: The Concatenate Context n8n node combines the retrieved document snippets into a single, comprehensive context block.

  8. Final Answer Generation: The final Answer LangChain Agent n8n node, leveraging the tailored prompt, the retrieved context, and the shared Chat Buffer Memory, generates the final, context-aware response.

  9. Response: The answer is delivered back to the user via the Respond to Webhook n8n node.

Installation Guide

To utilize this adaptive RAG n8n template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and import it directly into your n8n instance via the 'Workflows' > 'New' > 'Import from JSON' option.

  2. Set Up Credentials:

Google Gemini: You must establish credentials for Google Gemini (API Key) and link them to the LangChain Agent/Chat nodes (Gemini Classification, Gemini Answer, and all strategy nodes).
Qdrant: Configure your Qdrant credentials and link them to the Retrieve Documents from Vector Store n8n node.

  1. Configure Vector Store ID: Open the Combined Fields n8n node. In the 'vectorstoreid' assignment, replace with the actual collection name in your Qdrant instance that holds your knowledge base documents.

  2. Activate the n8n Workflow: Ensure the workflow is active and ready to process requests either through the Chat n8n trigger or by calling the workflow externally.

Node Details

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.

Related n8n Workflows

Free

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

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