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.
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.
| Node | Category | Type | Operation |
|---|---|---|---|
| Query Classification | AI & models | Agent | See node parameters |
| Switch | Routing | Switch | See node parameters |
| Factual Strategy - Focus on Precision | AI & models | Agent | See node parameters |
| Analytical Strategy - Comprehensive Coverage | AI & models | Agent | See node parameters |
| Opinion Strategy - Diverse Perspectives | AI & models | Agent | See node parameters |
| Contextual Strategy - User Context Integration | AI & models | Agent | See node parameters |
| Chat | Trigger | Chat Trigger | See node parameters |
| Factual Prompt and Output | Transform | Edit Fields | See node parameters |
| Contextual Prompt and Output | Transform | Edit Fields | See node parameters |
| Opinion Prompt and Output | Transform | Edit Fields | See node parameters |
| Analytical Prompt and Output | Transform | Edit Fields | See node parameters |
| Gemini Classification | AI & models | LM Chat Google Gemini | See node parameters |
| Gemini Factual | AI & models | LM Chat Google Gemini | See node parameters |
| Gemini Analytical | AI & models | LM Chat Google Gemini | See node parameters |
| Chat Buffer Memory Analytical | Data store | Memory Buffer Window | See node parameters |
| Chat Buffer Memory Factual | Data store | Memory Buffer Window | See node parameters |
| Gemini Opinion | AI & models | LM Chat Google Gemini | See node parameters |
| Chat Buffer Memory Opinion | Data store | Memory Buffer Window | See node parameters |
| Gemini Contextual | AI & models | LM Chat Google Gemini | See node parameters |
| Chat Buffer Memory Contextual | Data store | Memory Buffer Window | See node parameters |
| Embeddings | AI & models | Embeddings Google Gemini | See node parameters |
| Concatenate Context | Transform | Summarize | See node parameters |
| Retrieve Documents from Vector Store | Data store | Vector Store Qdrant | See node parameters |
| Set Prompt and Output | Transform | Edit Fields | See node parameters |
| Gemini Answer | AI & models | LM Chat Google Gemini | See node parameters |
| Answer | AI & models | Agent | See node parameters |
| Chat Buffer Memory | Data store | Memory Buffer Window | See node parameters |
| Respond to Webhook | Web / API | Respond To Webhook | See node parameters |
| When Executed by Another Workflow | Trigger | Execute Workflow Trigger | See node parameters |
| Combined Fields | Transform | Edit Fields | See node parameters |
Setup
- Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
- Connect your own credentials through n8n’s credential store. Replace
REPLACE_WITH_*values with your resource identifiers. - Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
- 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
googlePalmApiqdrantApi
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
-
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), andvector_store_id(specifying the Qdrant collection). - A
Setnode (Combined Fields) standardizes these inputs.
-
Query Classification:
- A Google Gemini agent (
Query Classification) analyzes theuser_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.
- A Google Gemini agent (
-
Adaptive Strategy Routing:
- A
Switchnode routes the workflow based on the classification result from the previous step.
- A
-
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).
- Factual Strategy: Rewrites the query for better precision, focusing on key entities (
- Each strategy path uses its own chat memory buffer for the adaptation step.
- Depending on the route, a specific Google Gemini agent adapts the query or approach:
-
Retrieval Prompt & Output Setup:
- Based on the original query classification, a
Setnode (Factual/Analytical/Opinion/Contextual Prompt and Output, combined via connections toSet 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).
- Based on the original query classification, a
-
Document Retrieval (RAG):
- The
Retrieve Documents from Vector Storenode 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.
- The
-
Context Preparation:
- The content from the retrieved document chunks is concatenated (
Concatenate Context) to form a single context block for the final answer generation.
- The content from the retrieved document chunks is concatenated (
-
Answer Generation:
- The final
Answeragent (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 Memoryusingchat_memory_key).
- The final
-
Response:
- The generated answer is sent back to the user via the
Respond to Webhooknode.
- The generated answer is sent back to the user via the
⚠️ 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