Mermaid Flowchart: How RAG Works
A Mermaid flowchart explaining Retrieval-Augmented Generation — from user question through retrieval to final answer.
Starter Prompt
Create a Mermaid flowchart that explains how RAG (Retrieval-Augmented Generation) works, from user question to final answer.
Expanded Prompt
Create a Mermaid flowchart that explains how RAG (Retrieval-Augmented Generation) works for a beginner-friendly AI course.
Goal
Build a clear flow diagram that shows how a user question is answered using both a large language model and external documents or knowledge sources.
Steps to Include
- User asks a question
- Question is converted into an embedding
- Vector database searches for similar content
- Relevant documents or chunks are retrieved
- Decision point: Was relevant context found?
If Yes:
- Add retrieved context to the prompt
- Send prompt to the LLM
- LLM generates an answer
- Answer is returned to the user
If No:
- Ask the LLM to answer from general knowledge
- Optionally warn the user that no supporting documents were found
- Answer is returned to the user
Mermaid Requirements
- Use
flowchart TD(top-down layout) - Use clear, short node labels
- Label the Yes and No branches on the decision point
- Use
classDefstyling to visually distinguish the decision node if helpful
Design Goals
- Easy to read and follow
- Suitable for a beginner AI course or slide deck
- Clear about what happens before and after retrieval
Output Instructions
Return only the Mermaid code block. No explanation before or after.
Tips for Refining
- “Render this as an HTML artifact with the diagram displayed inline”
- “Add color to the Yes and No branches”
- “Add a step for re-ranking retrieved chunks before sending to the LLM”
- “Make a left-right (LR) layout version”