Adaptive RAG Architecture with Google Gemini and Qdrant - n8n Workflow

Implement an Adaptive RAG system using this advanced n8n workflow. Classify user queries (Factual, Analytical, Opinion, Contextual) and customize retrieval strategies with Google Gemini, Qdrant, and specific n8n node configurations.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Who is this for?

Overview

This comprehensive n8n workflow provides a blueprint for building advanced Retrieval-Augmented Generation (RAG) systems that move beyond standard keyword matching. The primary challenge this n8n template solves is that not all queries are equal; a factual question requires precision, while an analytical query needs breadth. By classifying the incoming user query (using the Query Classification n8n node powered by Google Gemini) into one of four categories (Factual, Analytical, Opinion, Contextual), the system dynamically selects an optimal retrieval strategy. This powerful adaptive approach ensures that the documents retrieved from the Qdrant vector database are maximally relevant to the user's intent, resulting in highly accurate and context-aware responses. This specific n8n workflow serves as an excellent reference for anyone looking to deploy production-ready, context-sensitive AI agents.

How it Works

The operation of this complex n8n workflow is divided into four main stages, starting immediately after the initial n8n trigger:


  1. Input and Standardization: The n8n workflow is triggered via an incoming chat webhook or an external execution. The Combined Fields n8n node ensures that the userquery, chatmemorykey, and vectorstore_id (the Qdrant collection ID) are standardized for subsequent processing.

  2. Adaptive Strategy Selection: The Query Classification n8n node, powered by Google Gemini, analyzes the user query and classifies it (e.g., 'Factual', 'Analytical'). A Switch n8n node then directs the flow to one of four specialized paths.

  3. Query Adaptation and Retrieval: Within the selected path, another Gemini agent reformulates or breaks down the query (e.g., generating sub-questions for an Analytical query). This adapted output, combined with a task-specific system prompt, is then passed to the Retrieve Documents from Vector Store n8n node, which uses Gemini embeddings to search the Qdrant database. The resulting documents are concatenated.

  4. Final Response Generation: The final Answer agent uses the specific system prompt (set according to the original classification), the retrieved context, the original user query, and the ongoing conversation history (via Chat Buffer Memory) to generate the definitive response. This response is then immediately returned to the user via the Respond to Webhook n8n node.

Installation Guide

To utilize this sophisticated n8n workflow, follow these setup steps:


  1. Import: Copy the provided n8n workflow JSON and import it into your n8n instance.

  2. Credentials: This n8n template requires two primary credentials:

Google Gemini (PaLM) API: Set up your Gemini API key and link it to all Google Gemini n8n node instances (Gemini Classification, Gemini Answer, etc.).
Qdrant API: Configure credentials for your Qdrant instance. This is required for the Retrieve Documents from Vector Store n8n node.

  1. Configuration: Update the vectorstoreid variable within the Combined Fields n8n node, or ensure it is passed correctly via the n8n trigger, to match the ID of the Qdrant collection containing your documents.

  2. Activation: Once credentials are set, activate the n8n workflow. If using the Chat n8n trigger, copy the webhook URL for integration.

Node Details

This n8n workflow leverages various advanced n8n node types to achieve the Adaptive RAG logic:

Chat / Execute Workflow Trigger (n8n trigger): Initiates the entire process. Provides the initial userquery and session keys.
Combined Fields (Set n8n node): Standardizes input variables (user
query, chatmemorykey, vectorstoreid) from the n8n trigger for consistent data flow.
Query Classification (Gemini Agent n8n node): Function: Classifies the raw query into Factual, Analytical, Opinion, or Contextual. Key Configuration: Uses a highly constrained system message to return only the category name.
Switch (Core Logic n8n node): Function: Routes the workflow based on the classification output provided by the previous n8n node.
Factual/Analytical/Opinion/Contextual Strategy (Gemini Agent n8n node): Function: Dynamically adapts the original query based on the category (e.g., query rewriting, sub-question generation). Each strategy uses its own memory buffer.
Retrieve Documents from Vector Store (Qdrant n8n node): Function: Executes the vector search using the adapted query output and Google Gemini embeddings. Key Configuration: Targets the collection specified by vectorstoreid and retrieves topK: 10 documents.
Concatenate Context (Summarize n8n node): Function: Aggregates the pageContent from all retrieved documents into a single block of context, separated by a distinct marker (---\n\n).
Answer (Gemini Agent n8n node): Function: The final generation step. It utilizes the concatenated context and a category-specific system prompt (defined by a preceding Set n8n node) to produce the final, comprehensive response.

Related n8n Workflows

Free

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

software dev | business automation specialist

Featured*