RAG Pipeline Viz
A stage-by-stage visualisation of a Retrieval-Augmented Generation pipeline: Query → Embed → Retrieve → Rank → Augment → Generate. A single cursor advances through the stages; optional accent-coloured tokens flow along the edge between the current and next stage to show data moving downstream.
Current stage: Query. Step 1 of 6.
RAG pipelinestep 01 / 06
- QueryUser question
- EmbedVector encoder
- RetrieveVector DB lookup
- RankCross-encoder rerank
- AugmentBuild context prompt
- GenerateLLM response
Customize
Cursor
0
Layout
horizontal
Playback
Installation
npx shadcn@latest add https://craftbits.dev/r/rag-pipeline-viz.jsonUsage
import { RAGPipelineViz } from "@craft-bits/core";
<RAGPipelineViz />Override stages to teach a custom pipeline — e.g. an agentic loop:
<RAGPipelineViz
stages={[
{ id: "plan", label: "Plan", description: "Pick a tool" },
{ id: "act", label: "Act", description: "Run the tool" },
{ id: "verify", label: "Verify", description: "Check output" },
{ id: "answer", label: "Answer", description: "Reply to user" },
]}
/>Drive playback from outside the component:
const [step, setStep] = useState(0);
<RAGPipelineViz
currentStage={step}
onCurrentStageChange={setStep}
playing={false}
/>Understanding the component
- One cursor through the whole pipeline. A single
currentStageindex drives the active highlight, the past/future styling, and the edge that carries flowing tokens — there is no per-stage state machine. - Stages are cards; edges are arrows. Each stage renders as a bordered card with an icon, label, and optional description. Edges between adjacent stages share a rail and arrow-head glyph; the active edge lights up in
--cb-accent. - Tokens flow only on the active edge. Three accent dots travel along the rail between the current stage and the next, staggered by 50ms each. They use
SPRINGS.snapso they feel like discrete packets, not a continuous wave. SPRINGS.smoothfor the stage cursor. The active card scales to1.02and brightens via a smooth spring from@craft-bits/core/motion— the cursor settles on each stage rather than snapping.- Reduced-motion fallback. With
prefers-reduced-motion: reduce, the pipeline renders fully lit on mount, autoplay pauses, and the flowing-token dots are suppressed. - Two orientations, same component.
horizontalflows left → right (default);verticalstacks top → bottom with arrows pointing down.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
stages | readonly RAGPipelineStage[] | Query → Embed → Retrieve → Rank → Augment → Generate | Pipeline stages in order. |
currentStage | number | — | Controlled active index. Pair with onCurrentStageChange. |
defaultCurrentStage | number | 0 | Uncontrolled initial active stage. |
onCurrentStageChange | (stage) => void | — | Fires on autoplay tick and manual scrub. |
playing | boolean | — | Controlled play state. Pair with onPlayingChange. |
defaultPlaying | boolean | true | Uncontrolled initial play state. |
onPlayingChange | (playing) => void | — | Fires when play / pause flips. |
playSpeed | number | 1200 | Milliseconds between stage advances. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Layout direction. |
showTokens | boolean | true | Render flowing-token dots on the active edge. |
transition | Transition | SPRINGS.smooth | Spring for the stage cursor. |
className | string | — | Merged onto the root <div> via cn(). |
Accessibility
- The root is
role="figure"witharia-labelledbypointing at the "RAG pipeline" heading andaria-describedbyat a visually-hiddenaria-live="polite"summary. - The summary announces the current stage and step counter whenever the cursor advances.
- Stages are rendered in a semantic
<ol>witharia-current="step"on the active card. - The play / pause button uses
aria-pressed; the label flips between "Play pipeline" and "Pause pipeline". - The scrubber is a native
<input type="range">with anaria-labelso keyboard arrows nudge the cursor and screen readers narrate the value. - Color is never the only signal — stage labels, descriptions, and the step counter are all textual.
prefers-reduced-motion: reducerenders the pipeline fully lit on mount, suppresses flowing tokens, and disables autoplay.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/systems/RAGPipelineViz.tsx). Stripped the lesson-specific four-stage state machine (query / retrieval / reranking / context), document score bars, precision-gauge sub-component, retrieval-mode toggle, narration heuristics, and the bespoke document set. Generalised to an arbitrarystages: RAGPipelineStage[]array with controlled / uncontrolled state pairs and added orientation + flowing-token visualisation.