Library / RAG & Knowledge Bases
RAG & Knowledge Bases
Answer Questions with Adaptive RAG on Gemini and Qdrant
When a chat message arrives, it classifies the question and applies a factual or analytical retrieval strategy over Qdrant before Gemini answers.
What it does
# 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
The steps
- Query Classification
- Switch
- Factual Strategy - Focus on Precision
- Analytical Strategy - Comprehensive Coverage
- Opinion Strategy - Diverse Perspectives
- Contextual Strategy - User Context Integration
- Chat
- Factual Prompt and Output
- Contextual Prompt and Output
- Opinion Prompt and Output
- Analytical Prompt and Output
- Gemini Classification
- Gemini Factual
- Gemini Analytical
30 steps in total.
Similar automations
RAG & Knowledge BasesAnswer Questions with Adaptive RAG Using Gemini and Qdrant30 stepsRAG & Knowledge BasesAdaptive RAG Answers with Gemini Query Classification47 stepsRAG & Knowledge BasesRAG System with Automatic Source Citations Using Qdrant24 stepsRAG & Knowledge BasesAnswer Questions with Llama RAG and Qdrant10 steps