Adaptive RAG in n8n: Classify & Tailor Intelligent AI Responses

This Adaptive RAG workflow in n8n intelligently classifies user queries into Factual, Analytical, Opinion, or Contextual types, applying bespoke strategies to fetch tailored answers from a Qdrant vector store. It solves the problem of generic AI responses by harnessing query-specific adaptive retrieval and generation for more relevant insights.
agent
switch
lmChatGoogleGemini
+9
Workflow Identifier: 1080
NODES in Use: agent, switch, lmChatGoogleGemini, memoryBufferWindow, embeddingsGoogleGemini, set, summarize, vectorStoreQdrant, respondToWebhook, executeWorkflowTrigger, stickyNote, chatTrigger
Automate query classification with n8n and Qdrant

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Workflow Does

This workflow sorts questions into four types: Factual, Analytical, Opinion, and Contextual.
It uses Google Gemini AI to classify questions and picks a special way to answer each one.
The workflow finds matching documents in Qdrant and then writes a clear answer.
The result is faster and more accurate answers without manual sorting.


Who Should Use This Workflow

People who get many different types of questions daily.
Teams needing precise, detailed, or opinion-rich answers from documents.

Those who want to save time and avoid mistakes from manual sorting.
Users looking for smart AI that adjusts answers based on question type.


Tools and Services Used

  • n8n: Automation platform to build and run the workflow.
  • Google Gemini API: Classifies questions and generates answers.
  • Qdrant Vector Store: Stores embedded documents and finds related content.
  • Chat Buffer Memory in n8n: Keeps conversation history for better answers.
  • self-host n8n: Optionally run n8n on your own server.

Beginner Step-by-Step: How to Use This Workflow in n8n

Importing the Workflow

  1. Download the workflow file using the Download button on this page.
  2. Open n8n editor and click “Import from File.”
  3. Select the downloaded workflow file to add it.

Setup After Import

  1. Add credentials for Google Gemini API in the n8n settings.
  2. Make sure the Qdrant collection ID is set properly in the workflow.
  3. Set any emails, folders, or other IDs if your setup requires.
  4. Check prompt text in strategy nodes if you want custom answers.

Testing and Activation

  1. Run the workflow once with a test question to verify it works.
  2. Make sure question classification returns one of the four types correctly.
  3. Activate the workflow toggle in n8n to start usage in production.

Inputs, Processing, and Output

Inputs

  • User Query: The question text to answer.
  • Chat Memory Key: Optional key to keep track of conversation.
  • Vector Store ID: ID of the Qdrant collection storing documents.

Processing Steps

  • The Query Classification node uses AI to assign one of four question types.
  • Based on the type, the Switch node sends the query to one of four custom strategies.
  • Each strategy refines the query differently for better document search and answer creation.
  • The workflow uses Google Gemini embeddings to find top 10 related documents from Qdrant.
  • Document content is joined together to form a knowledge base for the final answer.
  • The Answer node combines the refined query, documents, and chat history to write a reply.

Outputs

The workflow sends back a clear, helpful answer matching the question type through a Webhook node.


Common Failures and How to Fix Them

  • No documents found: Check that the vector_store_id matches a valid Qdrant collection with data.
  • Wrong query category: Make sure the classification prompt returns exact words “Factual,” “Analytical,” “Opinion,” or “Contextual.”
  • Answers missing chat context: Confirm the chat_memory_key is provided and consistent.
  • Webhook response errors: Verify response format and client endpoint are correct.

Customization Ideas

  • Change classification categories in the Query Classification node prompt.
  • Adjust how many documents to get by changing topK in the retrieval node.
  • Tweak strategy node prompts to change query adaptation style.
  • Switch Qdrant to another vector database supported by n8n.
  • Modify chat memory window size for more or less conversation history.

Production Checklist

  • Confirm Google Gemini API credentials work and have permissions.
  • Test classification with sample questions for expected categories.
  • Verify Qdrant collection has indexed documents and correct ID.
  • Run tests on each query type path separately.
  • Check conversation memory persists with given keys.
  • Test workflow triggers through both Chat node and external workflows.

Deployment Tips

After testing, enable the workflow with the toggle in n8n.
Use the Webhook node URL to connect chatbots or API clients.

Watch error logs for failures or slow steps.
Keep notes on strategy steps inside n8n for future maintenance.


Example Prompts

Here is an example of the classification prompt used in the Query Classification node:


You are an AI assistant classifying queries into one of four categories: Factual, Analytical, Opinion, or Contextual. Return only the category name exactly.

This helps the AI select proper answer strategies in the workflow.


Summary of Benefits

✓ Saves 10-15 hours weekly from manual sorting and research.
✓ Gives precise, clear answers tailored to question types.
✓ Keeps conversation history for more natural replies.
✓ Works with your existing Qdrant knowledge base.
✓ Easy to activate and test in n8n.

Automate query classification with n8n and Qdrant

Visit through Desktop to Interact with the Workflow.

Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.
Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.

Frequently Asked Questions

The workflow uses a Google Gemini AI agent in the Query Classification node to assign each query to one of four types: Factual, Analytical, Opinion, or Contextual.
Check that the vector_store_id matches a populated Qdrant collection and that the Retrieve Documents node is configured properly.
Yes, adjusting the contextWindowLength parameter in the Chat Buffer Memory nodes changes how much chat history is used.
Yes, n8n supports other vector stores which can replace Qdrant by updating the document retrieval node accordingly.

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.