Skip to main content

Adaptive RAG strategy with query classification & retrieval (Gemini & Qdrant)

Workflow preview

Workflow preview
100%
Adaptive RAG strategy with query classification & retrieval (Gemini & Qdrant) preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

This n8n workflow implements a version of the Adaptive Retrieval Augmented Generation (RAG) framework. It recognizes that the best way to retrieve information often depends on the type of question ...

Best for

  • Internal Wiki automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, n8n-nodes-base.switch, @n8n/n8n-nodes-langchain.chattrigger, n8n-nodes-base.set, @n8n/n8n-nodes-langchain.lmchatgooglegemini, @n8n/n8n-nodes-langchain.memorybufferwindow, @n8n/n8n-nodes-langchain.embeddingsgooglegemini, n8n-nodes-base.stickynote

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by dmr.

Original n8n.io source

1.1 Workflow description

Title
Adaptive RAG strategy with query classification & retrieval (Gemini & Qdrant)
Workflow name
Adaptive RAG strategy with query classification & retrieval (Gemini & Qdrant)

This n8n workflow implements a version of the Adaptive Retrieval-Augmented Generation (RAG) framework. It recognizes that the best way to retrieve information often depends on the type of question asked. Instead of a one-size-fits-all approach, this workflow adapts its strategy based on the user's query intent.

🌟 How it Works

  1. Receive Query: Takes a user query as input (along with context like a chat session ID and Vector Store collection ID if used as sub-workflow).
  2. Classify Query: First, the workflow classifies the query into a predefined category. This template uses four examples:
    • Factual: For specific facts.
    • Analytical: For deeper explanations or comparisons.
    • Opinion: For subjective viewpoints.
    • Contextual: For questions relying on specific background.
  3. Select & Adapt Strategy: Based on the classification, it selects a corresponding strategy to prepare for information retrieval. The example strategies aim to:
    • Factual: Refine the query for precision.
    • Analytical: Break the query into sub-questions for broad coverage.
    • Opinion: Identify different viewpoints to look for.
    • Contextual: Incorporate implied or user-specific context.
  4. Retrieve Info: Uses the output of the selected strategy to search the specified knowledge base (Qdrant vector store - change as needed) for relevant documents.
  5. Generate Response: Constructs a response using the retrieved documents, guided by a prompt tailored to the original query type.

By adapting the retrieval strategy, this workflow aims to provide more relevant results tailored to the user's intent.

⚙️ Usage & Flexibility

  • Sub-Workflow: Designed to be called from other n8n workflows, passing user_query, chat_memory_key, and vector_store_id as inputs.
  • Chat Testing: Can also be triggered directly via the n8n Chat interface for easy testing and interaction.
  • Customizable Framework: The query categories (Factual, Analytical, etc.) and the associated retrieval strategies are examples. You can modify or replace them entirely to fit your specific domain or requirements.

🛠️ Requirements

  • Credentials: You will need API credentials configured in your n8n instance for:
    • Google Gemini (AI Models)
    • Qdrant (Vector Store)

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Query Classification

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.8

Block 2 - Switch

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

Block 3 - Factual Strategy - Focus on Precision

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.7

Block 4 - Analytical Strategy - Comprehensive Coverage

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.7

Block 5 - Opinion Strategy - Diverse Perspectives

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.7

Block 6 - Contextual Strategy - User Context Integration

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.7

Block 7 - Chat

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 8 - Factual Prompt and Output

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 9 - Contextual Prompt and Output

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 10 - Opinion Prompt and Output

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 11 - Analytical Prompt and Output

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 12 - Gemini Classification

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 13 - Gemini Factual

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 14 - Gemini Analytical

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 15 - Chat Buffer Memory Analytical

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 16 - Chat Buffer Memory Factual

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 17 - Gemini Opinion

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 18 - Chat Buffer Memory Opinion

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 19 - Gemini Contextual

Type / Role
@n8n/n8n-nodes-langchain.lmChatGoogleGemini - lmChatGoogleGemini
Config choices
Version 1

Block 20 - Chat Buffer Memory Contextual

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 21 - Embeddings

Type / Role
@n8n/n8n-nodes-langchain.embeddingsGoogleGemini - embeddingsGoogleGemini
Config choices
Version 1

Block 22 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 23 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 24 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Showing the first 24 of 39 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Adaptive RAG strategy with query classification & retrieval (Gemini & Qdrant)
Complexity advanced
Nodes 39
Categories Internal Wiki, AI RAG
Author dmr
Published 07 Apr 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/3459/3459.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Adaptive RAG strategy with query classification & retrieval (Gemini & Qdrant) do?

This n8n workflow implements a version of the Adaptive Retrieval Augmented Generation (RAG) framework. It recognizes that the best way to retrieve information often depends on the type of question ...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Internal Wiki, AI RAG use case.