← All N8N workflows
AI & researchAgentChat TriggerEmbeddings Google GeminiExecute Workflow TriggerLM Chat Google Gemini

Adaptive RAG

Configured with Agent, Chat Trigger, Embeddings Google Gemini, Execute Workflow Trigger, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
AI & modelsQuery ClassificationAgentRoutingSwitchSwitchAI & modelsFactual Strategy -Focus on PrecisionAgentAI & modelsAnalytical Strategy -Comprehensive CoverageAgentAI & modelsOpinion Strategy -Diverse PerspectivesAgentAI & modelsContextual Strategy -User Context…AgentTriggerChatChat TriggerTransformFactual Prompt andOutputEdit FieldsTransformContextual Prompt andOutputEdit FieldsTransformOpinion Prompt andOutputEdit FieldsTransformAnalytical Prompt andOutputEdit FieldsAI & modelsGemini ClassificationLM Chat Google GeminiAI & modelsGemini FactualLM Chat Google GeminiAI & modelsGemini AnalyticalLM Chat Google GeminiData storeChat Buffer MemoryAnalyticalMemory Buffer WindowData storeChat Buffer MemoryFactualMemory Buffer WindowAI & modelsGemini OpinionLM Chat Google GeminiData storeChat Buffer MemoryOpinionMemory Buffer WindowAI & modelsGemini ContextualLM Chat Google GeminiData storeChat Buffer MemoryContextualMemory Buffer WindowAI & modelsEmbeddingsEmbeddings Google GeminiTransformConcatenate ContextSummarizeData storeRetrieve Documents fromVector StoreVector Store QdrantTransformSet Prompt and OutputEdit FieldsAI & modelsGemini AnswerLM Chat Google GeminiAI & modelsAnswerAgentData storeChat Buffer MemoryMemory Buffer WindowWeb / APIRespond to WebhookRespond To WebhookTriggerWhen Executed byAnother WorkflowExecute Workflow TriggerTransformCombined FieldsEdit Fields

Node categories in this workflow

  • AI & models
  • Routing
  • Trigger
  • Transform
  • Data store
  • Web / API

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
Query ClassificationAI & modelsAgentSee node parameters
SwitchRoutingSwitchSee node parameters
Factual Strategy - Focus on PrecisionAI & modelsAgentSee node parameters
Analytical Strategy - Comprehensive CoverageAI & modelsAgentSee node parameters
Opinion Strategy - Diverse PerspectivesAI & modelsAgentSee node parameters
Contextual Strategy - User Context IntegrationAI & modelsAgentSee node parameters
ChatTriggerChat TriggerSee node parameters
Factual Prompt and OutputTransformEdit FieldsSee node parameters
Contextual Prompt and OutputTransformEdit FieldsSee node parameters
Opinion Prompt and OutputTransformEdit FieldsSee node parameters
Analytical Prompt and OutputTransformEdit FieldsSee node parameters
Gemini ClassificationAI & modelsLM Chat Google GeminiSee node parameters
Gemini FactualAI & modelsLM Chat Google GeminiSee node parameters
Gemini AnalyticalAI & modelsLM Chat Google GeminiSee node parameters
Chat Buffer Memory AnalyticalData storeMemory Buffer WindowSee node parameters
Chat Buffer Memory FactualData storeMemory Buffer WindowSee node parameters
Gemini OpinionAI & modelsLM Chat Google GeminiSee node parameters
Chat Buffer Memory OpinionData storeMemory Buffer WindowSee node parameters
Gemini ContextualAI & modelsLM Chat Google GeminiSee node parameters
Chat Buffer Memory ContextualData storeMemory Buffer WindowSee node parameters
EmbeddingsAI & modelsEmbeddings Google GeminiSee node parameters
Concatenate ContextTransformSummarizeSee node parameters
Retrieve Documents from Vector StoreData storeVector Store QdrantSee node parameters
Set Prompt and OutputTransformEdit FieldsSee node parameters
Gemini AnswerAI & modelsLM Chat Google GeminiSee node parameters
AnswerAI & modelsAgentSee node parameters
Chat Buffer MemoryData storeMemory Buffer WindowSee node parameters
Respond to WebhookWeb / APIRespond To WebhookSee node parameters
When Executed by Another WorkflowTriggerExecute Workflow TriggerSee node parameters
Combined FieldsTransformEdit FieldsSee node parameters

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • googlePalmApi
  • qdrantApi

Workflow notes

Query Classification

Classify a query into one of four categories: Factual, Analytical, Opinion, or Contextual.

Returns: str: Query category

Factual Strategy - Focus on Precision

Retrieval strategy for factual queries focusing on precision.

Analytical Strategy - Comprehensive Coverage

Retrieval strategy for analytical queries focusing on comprehensive coverage.

Opinion Strategy - Diverse Perspectives

Retrieval strategy for opinion queries focusing on diverse perspectives.

Contextual Strategy - User Context Integration

Retrieval strategy for contextual queries integrating user context.

Factual Strategy

Factual Strategy

Retrieve precise facts and figures.

Analytical Strategy

Analytical Strategy

Provide comprehensive coverage of a topics and exploring different aspects.

Opinion Strategy

Opinion Strategy

Gather diverse viewpoints on a subjective issue.

Contextual Strategy

Contextual Strategy

Incorporate user-specific context to fine-tune the retrieval.

Perform adaptive retrieval

Perform adaptive retrieval

Find document considering both query and context.

User query classification

User query classification

Classify the query into one of four categories: Factual, Analytical, Opinion, or Contextual.

Adaptive RAG Workflow

Adaptive RAG Workflow

This n8n workflow implements a version of the Adaptive Retrieval-Augmented Generation (RAG) approach. It classifies user queries and applies different retrieval and generation strategies based on the query type (Factual, Analytical, Opinion, or Contextual) to provide more relevant and tailored answers from a knowledge base stored in a Qdrant vector store.

How it Works

  1. Input Trigger:

    • The workflow can be initiated via the built-in Chat interface or triggered by another n8n workflow.
    • It expects inputs: user_query, chat_memory_key (for conversation history), and vector_store_id (specifying the Qdrant collection).
    • A Set node (Combined Fields) standardizes these inputs.
  2. Query Classification:

    • A Google Gemini agent (Query Classification) analyzes the user_query.
    • It classifies the query into one of four categories:
      • Factual: Seeking specific, verifiable information.
      • Analytical: Requiring comprehensive analysis or explanation.
      • Opinion: Asking about subjective matters or seeking diverse viewpoints.
      • Contextual: Depending on user-specific or implied context.
  3. Adaptive Strategy Routing:

    • A Switch node routes the workflow based on the classification result from the previous step.
  4. Strategy Implementation (Query Adaptation):

    • Depending on the route, a specific Google Gemini agent adapts the query or approach:
      • Factual Strategy: Rewrites the query for better precision, focusing on key entities (Factual Strategy - Focus on Precision).
      • Analytical Strategy: Breaks down the main query into multiple sub-questions to ensure comprehensive coverage (Analytical Strategy - Comprehensive Coverage).
      • Opinion Strategy: Identifies different potential perspectives or angles related to the query (Opinion Strategy - Diverse Perspectives).
      • Contextual Strategy: Infers implied context needed to answer the query effectively (Contextual Strategy - User Context Integration).
    • Each strategy path uses its own chat memory buffer for the adaptation step.
  5. Retrieval Prompt & Output Setup:

    • Based on the original query classification, a Set node (Factual/Analytical/Opinion/Contextual Prompt and Output, combined via connections to Set Prompt and Output) prepares:
      • The output from the strategy step (e.g., rewritten query, sub-questions, perspectives).
      • A tailored system prompt for the final answer generation agent, instructing it how to behave based on the query type (e.g., focus on precision for Factual, present diverse views for Opinion).
  6. Document Retrieval (RAG):

    • The Retrieve Documents from Vector Store node uses the adapted query/output from the strategy step to search the specified Qdrant collection (vector_store_id).
    • It retrieves the top relevant document chunks using Google Gemini embeddings.
  7. Context Preparation:

    • The content from the retrieved document chunks is concatenated (Concatenate Context) to form a single context block for the final answer generation.
  8. Answer Generation:

    • The final Answer agent (powered by Google Gemini) generates the response.
    • It uses:
      • The tailored system prompt set in step 5.
      • The concatenated context from retrieved documents (step 7).
      • The original user_query.
      • The shared chat history (Chat Buffer Memory using chat_memory_key).
  9. Response:

    • The generated answer is sent back to the user via the Respond to Webhook node.
⚠️ If using in Chat mode

⚠️ If using in Chat mode

Update the vector_store_id variable to the corresponding Qdrant ID needed to perform the documents retrieval.

Adaptive RAG

Adaptive RAG

Purpose and structure

This folder contains the Adaptive RAG workflow. Its executable nodes use agent, chatTrigger, embeddingsGoogleGemini, executeWorkflowTrigger, lmChatGoogleGemini, memoryBufferWindow, respondToWebhook, set, summarize, switch, vectorStoreQdrant. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

Chat, When Executed by Another Workflow

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Summarize/1829_Summarize_Respondtowebhook_Automation_Webhook.json MIT; preserve source notices.

Canvas section labels

These name areas of the original canvas; they do not include explanatory instructions.

  • Reply to the user integrating retrieval context

More in AI & research