Welcome back!

Resume reading from where you left off?

10 Types of RAG Cover Image
AI/ML

10 Types of RAG

Think of RAG like an open-book exam. Instead of guessing from memory, the AI looks at a library of books (your data) to find the right facts before it answers you.

By Pankaj Sonani from aigrama.net • 7 min read
#rag#ai#ml

Think of a standard Large Language Model (LLM) as a brilliant student taking a closed-book exam. It knows a lot, but it can still guess incorrectly or hallucinate when asked about specific, private, or highly recent data.

Retrieval-Augmented Generation (RAG) turns this into an open-book exam. Instead of guessing, the AI looks up relevant documents first, reads them, and then writes a precise answer.

However, a simple search doesn’t always cut it. Real-world user queries can be messy, vague, or complex. This guide breaks down 10 advanced RAG patterns, explaining why they exist, when to deploy them, and how they function under the hood.


The Strategic Blueprint: Why, When, and How

Before diving into the technical variations, let’s establish a clear architectural strategy:

  • Why upgrade your RAG pipeline? Basic setups fail when questions require connecting multiple facts, tracking conversation history, or reading charts. Advanced patterns make your application reliable enough for production.
  • When to scale up complexity? Do not build a complex agent if a simple vector search solves your problem. Scale your architecture only when user analytics show retrieval failures, outdated context, or poor synthesis.
  • How to implement safely? Start by setting up an evaluation framework (like Ragas or TruLens). Measure your current baseline accuracy, identify the exact bottleneck, and then pick the specific RAG variant below that addresses it.
  • What are your next steps? 1. Implement a evaluation framework on your current data.
  1. Identify if your failures are due to bad retrieval or bad generation.
  2. Choose one advanced pattern below (like RAG with Memory or Multi-Query) to patch the leak.

The 10 RAG Architectural Variants

1. Simple RAG (Naive RAG)

The baseline approach. It converts a user’s question into a mathematical vector, finds similar text chunks in a database, and passes them to the LLM as context.

graph LR
    Query[User Query] --> Embed[Generate Embedding]
    Embed --> DB[(Vector Database)]
    DB --> Context[Top-K Text Chunks]
    Context --> LLM[LLM Generation]
    Query --> LLM
    LLM --> Answer[Final Answer]
  • When to Use: Straightforward, fact-based Q&A over static, well-structured documents (e.g., reading a standard HR manual).
  • Example: An employee asks, “What is our parental leave policy?” The system finds the exact paragraph in the policy PDF and reads it to generate the answer.

2. RAG With Memory

Standard RAG treats every question as a brand-new interaction. Adding memory lets the system remember previous turns in a conversation so it can resolve pronouns like “it” or “that button.”

graph LR
    Query[Follow-up Query] --> ContextCheck{Has Chat History?}
    ContextCheck -->|Yes| Rewrite[Rewrite Query with History]
    Rewrite --> Search[Vector Search]
    ContextCheck -->|No| Search
    Search --> LLM[LLM Generation]
  • When to Use: Multi-turn conversational interfaces, support chatbots, or interactive troubleshooting assistants.
  • Example: * User: “How do I create a new project?” (Bot answers: “Click the blue button.”)
  • User: “What if it is grayed out?”
  • System: Rewrites the search query internally to “New project button grayed out” using conversation history.

3. Multi-Query RAG

Users don’t always know the right keywords to use. Multi-Query RAG uses an LLM to rewrite a single user prompt into multiple variations from different perspectives, running all of them simultaneously.

graph LR
    Query[Original Query] --> LLM1[LLM Query Re-writer]
    LLM1 --> Q1[Query Var A]
    LLM1 --> Q2[Query Var B]
    LLM1 --> Q3[Query Var C]
    Q1 & Q2 & Q3 --> DB[(Vector DB Search)]
    DB --> DeDup[Deduplicate & Combine Context]
    DeDup --> FinalLLM[Final LLM Generation]
  • When to Use: For complex, broad, or poorly phrased questions that require information spread across different documents.
  • Example: An analyst asks, “What are the growth drivers and risks for Anthropic?” The system splits this into three searches: growth drivers, market risks, and competitive advantages, blending the results together.

4. HyDE RAG (Hypothetical Document Embeddings)

Instead of searching with a short, raw question, HyDE asks an LLM to write a fake, “hypothetical” ideal answer first. The system then uses the embedding of that detailed fake answer to look up real documents that look similar.

graph LR
    Query[User Question] --> LLM[LLM Generates Fake Answer]
    LLM --> FakeDoc[Hypothetical Document]
    FakeDoc --> Embed[Embed Fake Doc]
    Embed --> DB[(Vector DB Search)]
    DB --> RealDoc[Retrieve Real Documents]
    RealDoc --> FinalLLM[Final LLM Generation]
  • When to Use: When user queries are too short or casual, making direct semantic matching with formal documentation difficult.
  • Example: A doctor asks, “Latest treatments for melanoma?” The LLM writes a fake scientific abstract containing terms like “immune checkpoint inhibitors” and “mRNA vaccines.” This fake text matches real medical research papers much better than the short question would.

5. Adaptive RAG

A dynamic system that uses a fast router model to evaluate incoming questions. It decides whether the question is simple (needs Naive RAG), complex (needs advanced multi-step RAG), or requires no lookup at all.

graph LR
    Query[User Query] --> Router{Router LLM Classifies}
    Router -->|Simple| Naive[Simple RAG Pipeline]
    Router -->|Complex| Multi[Advanced Multi-Step Pipeline]
    Router -->|No Lookup| Direct[Direct LLM Response]
  • When to Use: High-traffic production applications where you need to balance speed, API costs, and response quality.
  • Example: If a user asks, “What is the office Wi-Fi?”, the router sends it straight to a single static FAQ document. If they ask for a deep financial comparison across quarters, it fires up a heavy multi-query pipeline.

6. Corrective RAG (CRAG)

CRAG acts as a self-correcting quality gate. After retrieving text blocks, a lightweight evaluator checks if they are actually relevant. If they are junk, the system bypasses the database and triggers a web search instead.

graph LR
    Retrieve[Retrieve Documents] --> Eval{Are they relevant?}
    Eval -->|Yes| LLM[Generate Answer]
    Eval -->|No/Poor| Web[Trigger Web Search API]
    Web --> NewContext[Use Web Context]
    NewContext --> LLM
  • When to Use: When your primary documentation database is prone to being outdated, incomplete, or messy.
  • Example: A user asks about a feature launched yesterday. The internal manual yields irrelevant chunks. CRAG notices the poor relevance score, searches the company’s live product blog online, and returns the correct answer.

7. Self-RAG

Self-RAG fine-tunes an LLM to generate internal “reflection tokens.” The model constantly grades itself: Do I need to look something up? Is this retrieved text accurate? Did I hallucinate my response?

graph LR
    LLM[Self-RAG LLM] --> Token1{Need Retrieval?}
    Token1 -->|Yes| Fetch[Retrieve & Evaluate Chunks]
    Fetch --> Token2{Is it accurate?}
    Token2 -->|Yes| Output[Output Confidently]
  • When to Use: High-stakes environments (medical, legal, financial) where hallucinations are completely unacceptable and you have the data to fine-tune models.
  • Example: A clinical tool searches for drug interactions. The model tags its own sentences with tokens like <Fully Supported> or <Partially Supported>, allowing the UI to flag exactly how reliable a piece of advice is.

8. Agentic RAG

Turns your RAG system into an autonomous loop. You give the AI a goal and a toolbox (vector search, web search, code interpreters, SQL databases). The AI plans its own steps, executes tools, inspects the results, and adjusts until it finishes the task.

graph LR
    Goal[High-Level Goal] --> Loop[Agent Loop: Plan -> Act -> Observe]
    Loop --> Tool1[Vector DB Tool]
    Loop --> Tool2[SQL Exec Tool]
    Loop --> Tool3[Calculator]
    Loop --> Target[Goal Achieved?]
    Target --> Answer[Final Synthesized Answer]
  • When to Use: For multi-step research operations, calculations, or data-gathering tasks across completely different data sources.
  • Example: “How many items did we sell in Texas last quarter, and should we reorder based on current warehouse inventory?” The agent writes a SQL query to check sales, pulls a PDF manual to check warehouse thresholds, runs a calculator, and delivers a final recommendation.

9. Multimodal RAG

Breaks the text barrier by embedding charts, images, and diagrams alongside text into a single mathematical space.

graph LR
    Query[Text or Image Query] --> MultiEmbed[Multimodal Embedding]
    MultiEmbed --> MultiDB[(Multimodal Database)]
    MultiDB --> ImagesText[Retrieve Charts & Chunks]
    ImagesText --> MultiLLM[Vision-LLM Generation]
  • When to Use: When critical context is locked inside blueprints, financial charts, user manuals, or medical scans.
  • Example: An auto mechanic uploads a photo of a cracked engine component. The system matches the image directly to a diagram in a repair manual and highlights the exact repair instructions.

10. Graph RAG

Instead of slicing text into isolated blocks, Graph RAG extracts entities (people, places, concepts) and maps out their relationships to construct a structural knowledge graph.

graph LR
    Docs[Raw Documents] --> GraphBuilder[Extract Entities & Links]
    GraphBuilder --> KG[(Knowledge Graph Database)]
    Query[Global Summary Query] --> KG
    KG --> SubGraphs[Retrieve Connected Nodes]
    SubGraphs --> LLM[Synthesize Holistic Report]
  • When to Use: Global summarization tasks, uncovering hidden connections across massive document collections, or answering thematic questions.
  • Example: An investigative journalist asks, “Summarize how Politician X is connected to luxury real estate in London.” The graph connects shell companies, transaction records, and associates to map out the entire network instantly.

Real-World Implementation: Building an Adaptive Router

If you are running an Astro application with JavaScript/TypeScript on your backend or API routes, here is a practical example of how you can build an Adaptive RAG Router.

This script analyzes an incoming query and dynamically chooses between a lightweight local vector search or a heavier multi-query fallback pipeline.

// src/pages/api/rag-router.js
import { OpenAI } from "openai";

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

// A mock classification helper using LLM structured outputs
async function classifyQuery(query) {
  const response = await openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [
      {
        role: "system",
        content: "Classify the user query as 'SIMPLE' (straightforward question) or 'COMPLEX' (requires multi-step synthesis, comparison, or broad research)."
      },
      { role: "user", content: query }
    ],
    temperature: 0
  });

  const analysis = response.choices[0].message.content;
  return analysis.includes("COMPLEX") ? "complex" : "simple";
}

// Simulated execution paths
async function runSimpleRAG(query) {
  return `[Simple RAG Path] Safely retrieved direct response for: "${query}"`;
}

async function runMultiQueryRAG(query) {
  return `[Multi-Query RAG Path] Expanded, aggregated, and synthesized results for complex topic: "${query}"`;
}

// Main API Handler for Astro Server-Side Routes
export async function POST({ request }) {
  try {
    const { query } = await request.json();
    
    if (!query) {
      return new Response(JSON.stringify({ error: "Missing query parameter" }), { status: 400 });
    }

    // Step 1: Dynamic Routing
    const routingStrategy = await classifyQuery(query);

    // Step 2: Route Execution
    let result = "";
    if (routingStrategy === "complex") {
      result = await runMultiQueryRAG(query);
    } else {
      result = await runSimpleRAG(query);
    }

    return new Response(JSON.stringify({ strategyUsed: routingStrategy, data: result }), {
      status: 200,
      headers: { "Content-Type": "application/json" }
    });

  } catch (error) {
    return new Response(JSON.stringify({ error: error.message }), { status: 500 });
  }
}

Summary Matrix

RAG VariantBest FeatureBest Used For…
Simple RAGEasy to buildSimple FAQs
With MemoryRemembers conversationChatbots & Support
Multi-QueryRewrites questionsComplex topics
HyDEImagines answers firstShort questions / Abstract data
AdaptiveSwitches path by complexitySaving speed & money
Corrective (CRAG)Uses internet backupQuickly changing data
Self-RAGDouble-checks itselfHighly accurate fields (Medical/Legal)
AgenticUses tools and plansHeavy multi-step math/logic tasks
MultimodalReads images and audioCharts, diagrams, and media files
Graph RAGConnects dots across documentsBig data summaries & relationships
Enjoyed this article?

Subscribe & Follow

Get notified of new technical articles on AI/ML, Java, Python, and system architecture.