FlowiseAI
English
English
  • Introduction
  • Get Started
  • Contribution Guide
    • Building Node
  • API Reference
    • Assistants
    • Attachments
    • Chat Message
    • Chatflows
    • Document Store
    • Feedback
    • Leads
    • Ping
    • Prediction
    • Tools
    • Upsert History
    • Variables
    • Vector Upsert
  • CLI Reference
    • User
  • Using Flowise
    • Agentflow V2
    • Agentflow V1 (Deprecating)
      • Multi-Agents
      • Sequential Agents
        • Video Tutorials
    • API
    • Analytic
      • Arize
      • Langfuse
      • Lunary
      • Opik
      • Phoenix
    • Document Stores
    • Embed
    • Monitoring
    • Streaming
    • Uploads
    • Variables
    • Workspaces
    • Evaluations
  • Configuration
    • Auth
      • Application
      • Flows
    • Databases
    • Deployment
      • AWS
      • Azure
      • Alibaba Cloud
      • Digital Ocean
      • Elestio
      • GCP
      • Hugging Face
      • Kubernetes using Helm
      • Railway
      • Render
      • Replit
      • RepoCloud
      • Sealos
      • Zeabur
    • Environment Variables
    • Rate Limit
    • Running Flowise behind company proxy
    • SSO
    • Running Flowise using Queue
    • Running in Production
  • Integrations
    • LangChain
      • Agents
        • Airtable Agent
        • AutoGPT
        • BabyAGI
        • CSV Agent
        • Conversational Agent
        • Conversational Retrieval Agent
        • MistralAI Tool Agent
        • OpenAI Assistant
          • Threads
        • OpenAI Function Agent
        • OpenAI Tool Agent
        • ReAct Agent Chat
        • ReAct Agent LLM
        • Tool Agent
        • XML Agent
      • Cache
        • InMemory Cache
        • InMemory Embedding Cache
        • Momento Cache
        • Redis Cache
        • Redis Embeddings Cache
        • Upstash Redis Cache
      • Chains
        • GET API Chain
        • OpenAPI Chain
        • POST API Chain
        • Conversation Chain
        • Conversational Retrieval QA Chain
        • LLM Chain
        • Multi Prompt Chain
        • Multi Retrieval QA Chain
        • Retrieval QA Chain
        • Sql Database Chain
        • Vectara QA Chain
        • VectorDB QA Chain
      • Chat Models
        • AWS ChatBedrock
        • Azure ChatOpenAI
        • NVIDIA NIM
        • ChatAnthropic
        • ChatCohere
        • Chat Fireworks
        • ChatGoogleGenerativeAI
        • Google VertexAI
        • ChatHuggingFace
        • ChatLocalAI
        • ChatMistralAI
        • IBM Watsonx
        • ChatOllama
        • ChatOpenAI
        • ChatTogetherAI
        • GroqChat
      • Document Loaders
        • Airtable
        • API Loader
        • Apify Website Content Crawler
        • BraveSearch Loader
        • Cheerio Web Scraper
        • Confluence
        • Csv File
        • Custom Document Loader
        • Document Store
        • Docx File
        • Epub File
        • Figma
        • File
        • FireCrawl
        • Folder
        • GitBook
        • Github
        • Google Drive
        • Google Sheets
        • Jira
        • Json File
        • Json Lines File
        • Microsoft Excel
        • Microsoft Powerpoint
        • Microsoft Word
        • Notion
        • PDF Files
        • Plain Text
        • Playwright Web Scraper
        • Puppeteer Web Scraper
        • S3 File Loader
        • SearchApi For Web Search
        • SerpApi For Web Search
        • Spider - web search & crawler
        • Text File
        • Unstructured File Loader
        • Unstructured Folder Loader
      • Embeddings
        • AWS Bedrock Embeddings
        • Azure OpenAI Embeddings
        • Cohere Embeddings
        • Google GenerativeAI Embeddings
        • Google VertexAI Embeddings
        • HuggingFace Inference Embeddings
        • LocalAI Embeddings
        • MistralAI Embeddings
        • Ollama Embeddings
        • OpenAI Embeddings
        • OpenAI Embeddings Custom
        • TogetherAI Embedding
        • VoyageAI Embeddings
      • LLMs
        • AWS Bedrock
        • Azure OpenAI
        • Cohere
        • GoogleVertex AI
        • HuggingFace Inference
        • Ollama
        • OpenAI
        • Replicate
      • Memory
        • Buffer Memory
        • Buffer Window Memory
        • Conversation Summary Memory
        • Conversation Summary Buffer Memory
        • DynamoDB Chat Memory
        • MongoDB Atlas Chat Memory
        • Redis-Backed Chat Memory
        • Upstash Redis-Backed Chat Memory
        • Zep Memory
      • Moderation
        • OpenAI Moderation
        • Simple Prompt Moderation
      • Output Parsers
        • CSV Output Parser
        • Custom List Output Parser
        • Structured Output Parser
        • Advanced Structured Output Parser
      • Prompts
        • Chat Prompt Template
        • Few Shot Prompt Template
        • Prompt Template
      • Record Managers
      • Retrievers
        • Extract Metadata Retriever
        • Custom Retriever
        • Cohere Rerank Retriever
        • Embeddings Filter Retriever
        • HyDE Retriever
        • LLM Filter Retriever
        • Multi Query Retriever
        • Prompt Retriever
        • Reciprocal Rank Fusion Retriever
        • Similarity Score Threshold Retriever
        • Vector Store Retriever
        • Voyage AI Rerank Retriever
      • Text Splitters
        • Character Text Splitter
        • Code Text Splitter
        • Html-To-Markdown Text Splitter
        • Markdown Text Splitter
        • Recursive Character Text Splitter
        • Token Text Splitter
      • Tools
        • BraveSearch API
        • Calculator
        • Chain Tool
        • Chatflow Tool
        • Custom Tool
        • Exa Search
        • Gmail
        • Google Calendar
        • Google Custom Search
        • Google Drive
        • Google Sheets
        • Microsoft Outlook
        • Microsoft Teams
        • OpenAPI Toolkit
        • Code Interpreter by E2B
        • Read File
        • Request Get
        • Request Post
        • Retriever Tool
        • SearchApi
        • SearXNG
        • Serp API
        • Serper
        • Tavily
        • Web Browser
        • Write File
      • Vector Stores
        • AstraDB
        • Chroma
        • Couchbase
        • Elastic
        • Faiss
        • In-Memory Vector Store
        • Milvus
        • MongoDB Atlas
        • OpenSearch
        • Pinecone
        • Postgres
        • Qdrant
        • Redis
        • SingleStore
        • Supabase
        • Upstash Vector
        • Vectara
        • Weaviate
        • Zep Collection - Open Source
        • Zep Collection - Cloud
    • LiteLLM Proxy
    • LlamaIndex
      • Agents
        • OpenAI Tool Agent
        • Anthropic Tool Agent
      • Chat Models
        • AzureChatOpenAI
        • ChatAnthropic
        • ChatMistral
        • ChatOllama
        • ChatOpenAI
        • ChatTogetherAI
        • ChatGroq
      • Embeddings
        • Azure OpenAI Embeddings
        • OpenAI Embedding
      • Engine
        • Query Engine
        • Simple Chat Engine
        • Context Chat Engine
        • Sub-Question Query Engine
      • Response Synthesizer
        • Refine
        • Compact And Refine
        • Simple Response Builder
        • Tree Summarize
      • Tools
        • Query Engine Tool
      • Vector Stores
        • Pinecone
        • SimpleStore
    • Utilities
      • Custom JS Function
      • Set/Get Variable
      • If Else
      • Sticky Note
    • External Integrations
      • Zapier Zaps
  • Migration Guide
    • Cloud Migration
    • v1.3.0 Migration Guide
    • v1.4.3 Migration Guide
    • v2.1.4 Migration Guide
  • Tutorials
    • RAG
    • Agentic RAG
    • SQL Agent
  • Use Cases
    • Calling Children Flows
    • Calling Webhook
    • Interacting with API
    • Multiple Documents QnA
    • SQL QnA
    • Upserting Data
    • Web Scrape QnA
  • Flowise
    • Flowise GitHub
    • Flowise Cloud
Powered by GitBook
On this page
  • Overview
  • Step 1: Setting Up the Start Node
  • Step 2: Adding Query Validation
  • Step 3: Creating the General Response Branch
  • Step 4: Setting Up Query Generation
  • Step 5: Configuring the Vector Database Retriever
  • Step 6: Adding Document Relevance Check
  • Step 7: Creating the Final Response Generator
  • Step 8: Implementing Self-Correction
  • Step 9: Adding the Loop Back Mechanism
  • Complete Flow Structure
  • Testing Your Flow
Edit on GitHub
  1. Tutorials

Agentic RAG

PreviousRAGNextSQL Agent

Last updated 3 hours ago

Agentic RAG is an agent based approach to perform in an orchestrated fashion. It may involve retrieving data from various document sources, comparing summaries, and implementing an automatic self-correction mechanism.

In this tutorial, we'll explore how to build a self-correcting RAG system that checks the relevance of retrieved data and automatically re-generates the query if the results are not relevant.

Overview

The Agentic RAG flow implements a multi-step process that:

  1. Validates and categorizes incoming queries

  2. Generates optimized search queries for vector database retrieval

  3. Evaluates the relevance of retrieved documents

  4. Self-corrects by regenerating queries when results are not relevant

  5. Provides contextual responses based on retrieved information

Step 1: Setting Up the Start Node

Begin by adding a Start node to your canvas. This serves as the entry point for your agent flow.

Configuration:

  • Input Type: Select "Chat Input" to accept user questions

  • Flow State: Add a state variable with key "query" and empty value

The Start node initializes the flow state with an empty query variable that will be updated throughout the process.

Step 2: Adding Query Validation

Add a Condition Agent node and connect it to the Start node.

Configuration:

  • Instructions: "Check if user is asking about AI related topic, or just general query"

  • Input: {{ question }} (references the user's input)

  • Scenarios:

    • Scenario 1: "AI Related"

    • Scenario 2: "General"

This node acts as a router, determining whether the query requires specialized AI knowledge or can be answered generally.

Step 3: Creating the General Response Branch

For non-AI related queries, add an LLM node connected to output 1 of the condition agent.

This provides direct responses for general queries without requiring document retrieval. You can also replace with Direct Reply node to return a predefined answer.

Step 4: Setting Up Query Generation

For AI-related queries, add an LLM node connected to output 0 of the condition agent - which is the scenario for "AI-related".

Configuration:

  • Messages: Add a system message:

    Given the user question and history, construct a short string that can be used for searching vector database. Only generate the query, no meta comments, no explanation
    
    Example:
    Question: what are the events happening today?
    Query: today's event
    
    Example:
    Question: how about the address?
    Query: business address of the shop
    
    Question: {{ question }}
    Query:
  • Update Flow State: Set key "query" with value {{ output }}. This will update the value of "query" to the output from this LLM node.

This node transforms the user's natural language question into an optimized search query for the vector database.

Step 5: Configuring the Vector Database Retriever

Add a Retriever node and connect it to the "Generate Query" LLM.

Configuration:

  • Knowledge (Document Stores): Select your pre-configured document store (e.g., "ai paper")

  • Retriever Query: {{ $flow.state.query }} (uses the "query" value from shared state)

This node searches your vector database using the optimized query and returns relevant documents.

Step 6: Adding Document Relevance Check

Add another Condition Agent node connected to the Retriever.

Configuration:

  • Instructions: "Determine if the document is relevant to user question. User question is {{ question }}"

  • Input: {{ retrieverAgentflow_0 }} (references the retrieved documents from Step 5)

  • Scenarios:

    • Scenario 1: "Relevant"

    • Scenario 2: "Irrelevant"

This evaluates whether the retrieved documents actually contain information relevant to the user's question.

Step 7: Creating the Final Response Generator

For relevant documents, add an LLM node connected to output 0 of the relevance checker - which is when the scenario "Relevant" is matched.

Configuration:

  • Input Message:

    Given the question: {{ question }}
    And the findings: {{ retrieverAgentflow_0 }}
    Output the final response

This node creates the final answer by combining the user's question with the relevant retrieved documents.

Step 8: Implementing Self-Correction

For irrelevant documents, add an LLM node connected to output 1 of the relevance checker - for the second scenario - "Irrelevant".

Configuration:

  • Messages: Add system message: "You are a helpful assistant that can transform the query to produce a better question."

  • Input Message:

    Look at the input and try to reason about the underlying semantic intent / meaning.
    Here is the initial question: {{ $flow.state.query }}
    Formulate an improved question:
  • Update Flow State: Set key "query" with value {{ output }}

This node analyzes why the initial query didn't return relevant results and generates an improved version.

Step 9: Adding the Loop Back Mechanism

Add a Loop node connected to the "Regenerate Question" LLM.

Configuration:

  • Loop Back To: Select "retrieverAgentflow_0-Retriever Vector DB"

  • Max Loop Count: Set to 5 (prevents infinite loops)

This creates a feedback loop that allows the system to retry with improved queries when initial results are not satisfactory.

Complete Flow Structure

Summary:

  1. Start → Check if query valid

  2. Check if query valid (AI Related) → Generate Query

  3. Check if query valid (General) → General Answer

  4. Generate Query → Retriever Vector DB

  5. Retriever Vector DB → Check if docs relevant

  6. Check if docs relevant (Relevant) → Generate Response

  7. Check if docs relevant (Irrelevant) → Regenerate Question

  8. Regenerate Question → Loop back to Retriever

Testing Your Flow

Test your flow with various types of questions:

  • AI-related queries: "What are the latest developments in machine learning?"

  • General queries: "What's the weather like today?"

  • Complex queries that might require refinement: "How does that new technique work?"

This Agentic RAG provides a robust, self-improving system for document-based question answering that can handle both simple and complex queries while maintaining high accuracy through iterative refinement.

RAG
99KB
Agentic RAG V2.json