{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rag-pipeline-visualizer",
  "title": "Rag Pipeline Visualizer",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-react/blocks/rag-pipeline-visualizer/RagPipelineVisualizer.tsx",
      "content": "'use client'\n\nimport * as React from 'react'\nimport {\n  BookOpen,\n  Bot,\n  Check,\n  ChevronRight,\n  Code2,\n  Copy,\n  Cpu,\n  Database,\n  FileCode,\n  Filter,\n  Layers,\n  Play,\n  RefreshCw,\n  Search,\n  ShieldCheck,\n  SlidersHorizontal,\n  Sparkles,\n  Terminal,\n  ThumbsDown,\n  ThumbsUp,\n  Workflow,\n  Zap,\n} from 'lucide-react'\nimport { Badge } from '@/components/ui/badge'\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'\nimport { Input } from '@/components/ui/input'\nimport { Progress } from '@/components/ui/progress'\nimport { Separator } from '@/components/ui/separator'\nimport { Slider } from '@/components/ui/slider'\nimport { Switch } from '@/components/ui/switch'\nimport { cn } from '@/lib/utils'\n\nexport interface RagPipelineVisualizerProps {\n  className?: string\n}\n\ninterface PipelineStage {\n  id: number\n  name: string\n  subtitle: string\n  latency: string\n  durationMs: number\n  status: 'completed' | 'active' | 'queued' | 'bypassed'\n  icon: React.ElementType\n  tag: string\n  details: {\n    description: string\n    metrics: { label: string; value: string }[]\n    codeOrData?: { title: string; content: string }\n  }\n}\n\ninterface RetrievedChunk {\n  id: string\n  citationIndex: number\n  relevanceScore: number\n  rerankBoost: number\n  cosineScore: number\n  bm25Score: number\n  documentPath: string\n  namespace: string\n  chunkOffset: string\n  tokenCount: number\n  updatedAgo: string\n  title: string\n  snippetPrefix: string\n  highlightedText: string\n  snippetSuffix: string\n  fullSnippet: string\n}\n\nconst presetQueries = [\n  'How do I configure OKLCH color palettes in Tailwind v4 with UIPKGE?',\n  'Cross-Encoder vs Bi-Encoder reranker score calibration',\n  'HyDE prompt expansion for zero-shot semantic retrieval',\n  'Pinecone HNSW index tuning: efSearch & M parameter tradeoffs',\n]\n\nconst allChunks: RetrievedChunk[] = [\n  {\n    id: 'chunk-1',\n    citationIndex: 1,\n    relevanceScore: 0.942,\n    rerankBoost: 0.142,\n    cosineScore: 0.8,\n    bm25Score: 0.785,\n    documentPath: 'docs/styling/tailwind-v4-oklch.md',\n    namespace: 'docs',\n    chunkOffset: 'Chunk #3 · Lines 42–78',\n    tokenCount: 384,\n    updatedAgo: '2 hours ago',\n    title: 'Tailwind v4 OKLCH Architecture & @theme Configuration',\n    snippetPrefix: 'Tailwind CSS v4 introduces native CSS-first token configuration with ',\n    highlightedText:\n      '@theme inline and OKLCH color spaces. In contrast to RGB/HSL, OKLCH ensures perceptually uniform lightness across hues',\n    snippetSuffix:\n      ', preventing contrast degradation in dark mode variants while preserving single-source token truth.',\n    fullSnippet:\n      'Tailwind CSS v4 introduces native CSS-first token configuration with `@theme inline` and OKLCH color spaces. In contrast to RGB/HSL, OKLCH ensures perceptually uniform lightness across hues, preventing contrast degradation in dark mode variants while preserving single-source token truth.',\n  },\n  {\n    id: 'chunk-2',\n    citationIndex: 2,\n    relevanceScore: 0.887,\n    rerankBoost: 0.095,\n    cosineScore: 0.792,\n    bm25Score: 0.71,\n    documentPath: 'docs/tokens/color-derivation.md',\n    namespace: 'docs',\n    chunkOffset: 'Chunk #1 · Lines 1–36',\n    tokenCount: 412,\n    updatedAgo: '1 day ago',\n    title: 'Color Tokens Derivation & Contrast Calibration',\n    snippetPrefix: 'Deriving consistent dark-mode contrasts requires ',\n    highlightedText:\n      'anchoring chroma and shifting lightness along the OKLCH L-axis. Use --color-primary: oklch(0.65 0.22 260) for vibrant interactive states',\n    snippetSuffix:\n      ' and calibrate border contrast with `--color-border: oklch(0.28 0.01 260)` for WCAG AA compliance across both frameworks.',\n    fullSnippet:\n      'Deriving consistent dark-mode contrasts requires anchoring chroma and shifting lightness along the OKLCH L-axis. Use `--color-primary: oklch(0.65 0.22 260)` for vibrant interactive states and calibrate border contrast with `--color-border: oklch(0.28 0.01 260)` for WCAG AA compliance across both frameworks.',\n  },\n  {\n    id: 'chunk-3',\n    citationIndex: 3,\n    relevanceScore: 0.824,\n    rerankBoost: 0.048,\n    cosineScore: 0.776,\n    bm25Score: 0.65,\n    documentPath: 'blog/2026/design-systems-monorepo.md',\n    namespace: 'blog',\n    chunkOffset: 'Chunk #5 · Lines 112–164',\n    tokenCount: 526,\n    updatedAgo: '3 days ago',\n    title: 'Dual-Framework Component Registry Architecture',\n    snippetPrefix: 'When architecting a dual-framework registry (Vue + React), ',\n    highlightedText:\n      'shared design tokens must compile cleanly without runtime overhead. We leverage CSS custom properties to mirror CVA component variants',\n    snippetSuffix: ' across both frameworks with zero extra runtime.',\n    fullSnippet:\n      'When architecting a dual-framework registry (Vue + React), shared design tokens must compile cleanly without runtime overhead. We leverage modern CSS custom properties and PostCSS pipelines to mirror CVA component variants across both frameworks with zero extra runtime.',\n  },\n]\n\nexport function RagPipelineVisualizer({ className }: RagPipelineVisualizerProps) {\n  const [currentQuery, setCurrentQuery] = React.useState(\n    'How do I configure OKLCH color palettes in Tailwind v4 with UIPKGE?',\n  )\n  const [topK, setTopK] = React.useState(3)\n  const [rerankerEnabled, setRerankerEnabled] = React.useState(true)\n  const [selectedStageId, setSelectedStageId] = React.useState<number>(3)\n  const [isExecuting, setIsExecuting] = React.useState(false)\n  const [copiedChunkId, setCopiedChunkId] = React.useState<string | null>(null)\n  const [copiedResponse, setCopiedResponse] = React.useState(false)\n  const [copiedTrace, setCopiedTrace] = React.useState(false)\n  const [activeCitationHover, setActiveCitationHover] = React.useState<number | null>(null)\n  const [showTraceJson, setShowTraceJson] = React.useState(false)\n  const [userFeedback, setUserFeedback] = React.useState<'up' | 'down' | null>(null)\n\n  const stages = React.useMemo<PipelineStage[]>(\n    () => [\n      {\n        id: 1,\n        name: '1. User Query & HyDE Expansion',\n        subtitle: 'Query rewritten with hypothetical document embedding · 42ms',\n        latency: '42ms',\n        durationMs: 42,\n        status: 'completed',\n        icon: Sparkles,\n        tag: 'Prompt Rewriting',\n        details: {\n          description:\n            'Generates a synthetic hypothetical answer using Claude 3.5 Haiku to bridge vocabulary mismatch between conversational queries and technical documentation.',\n          metrics: [\n            { label: 'Expansion Model', value: 'Claude 3.5 Haiku' },\n            { label: 'Latency', value: '42ms' },\n            { label: 'Prompt Tokens', value: '48 tokens' },\n            { label: 'Hypothesis Length', value: '112 tokens' },\n          ],\n          codeOrData: {\n            title: 'Generated Hypothetical Document (HyDE)',\n            content:\n              'Tailwind CSS v4 defines color tokens using CSS variables inside `@theme inline` with `oklch(L C H)` functions. In dual-framework component registries like UIPKGE, OKLCH ensures uniform perceptual lightness across hue shifts in light and dark variants without breaking WCAG AA contrast.',\n          },\n        },\n      },\n      {\n        id: 2,\n        name: '2. Hybrid Dense + Sparse Search',\n        subtitle: 'Dense Cosine + BM25 Lexical search across 480k chunks · 64ms',\n        latency: '64ms',\n        durationMs: 64,\n        status: 'completed',\n        icon: Database,\n        tag: 'Reciprocal Rank Fusion',\n        details: {\n          description:\n            'Performs vector similarity search on 1536-dim embeddings combined with sparse BM25 keyword matching across 482,910 document chunks.',\n          metrics: [\n            { label: 'Vector Index', value: 'Pinecone Serverless (HNSW)' },\n            { label: 'Dimension', value: '1536-dim (text-embedding-3-small)' },\n            { label: 'Fusion Weight', value: 'α = 0.70 Dense + 0.30 Sparse' },\n            { label: 'Candidate Pool', value: '20 Candidate Chunks' },\n          ],\n          codeOrData: {\n            title: 'Dense Vector Projection (32-float slice)',\n            content:\n              '[-0.048, 0.135, 0.092, -0.018, 0.245, -0.110, 0.049, 0.174, -0.082, 0.001, 0.325, -0.059, 0.097, 0.191, -0.149, 0.068, -0.024, 0.212, 0.082, -0.094, 0.121, -0.037, 0.156, 0.031, -0.172, 0.099, 0.056, -0.078, 0.195, -0.013, 0.072, 0.141]',\n          },\n        },\n      },\n      {\n        id: 3,\n        name: '3. Cross-Encoder Reranker',\n        subtitle: rerankerEnabled\n          ? 'Cohere Rerank v3: re-scores Top 20 -> Top 3 · 28ms'\n          : 'Bypassed (Using raw hybrid search ranking) · 0ms',\n        latency: rerankerEnabled ? '28ms' : '0ms',\n        durationMs: rerankerEnabled ? 28 : 0,\n        status: rerankerEnabled ? 'completed' : 'bypassed',\n        icon: Filter,\n        tag: rerankerEnabled ? 'Cross-Attention Re-Scoring' : 'Bypassed',\n        details: {\n          description: rerankerEnabled\n            ? 'Applies deep transformer cross-attention to score query-document pairs simultaneously, eliminating false-positive semantic matches.'\n            : 'Reranker is currently bypassed. Chunks are ordered purely by initial hybrid reciprocal rank scores.',\n          metrics: [\n            { label: 'Model', value: 'cohere-rerank-v3.0-multilingual' },\n            { label: 'Top-K Retained', value: `Top ${topK} of 20` },\n            { label: 'Relevance Cutoff', value: '≥ 0.800 score' },\n            { label: 'Max Rank Shift', value: '+3 positions (Chunk #3)' },\n          ],\n          codeOrData: {\n            title: 'Reranker Score Calibration Delta',\n            content:\n              'Chunk #1: 0.800 (Cosine) -> 0.942 (Rerank)  [+0.142 boost]\\nChunk #2: 0.792 (Cosine) -> 0.887 (Rerank)  [+0.095 boost]\\nChunk #3: 0.776 (Cosine) -> 0.824 (Rerank)  [+0.048 boost]\\n17 candidates pruned below 0.800 relevance threshold',\n          },\n        },\n      },\n      {\n        id: 4,\n        name: '4. Context Window Assembly',\n        subtitle: '1,248 tokens packed, 98% prompt density · 8ms',\n        latency: '8ms',\n        durationMs: 8,\n        status: 'completed',\n        icon: Layers,\n        tag: 'Token Packaging',\n        details: {\n          description:\n            'Deduplicates overlapping chunk boundaries, injects citation boundary anchors `[1]`, `[2]`, `[3]`, and formats system directives for zero-hallucination grounding.',\n          metrics: [\n            { label: 'Window Budget', value: '1,248 / 8,192 tokens (15.2%)' },\n            { label: 'Prompt Density', value: '98.4% relevance tokens' },\n            { label: 'Chunks Packaged', value: `${Math.min(topK, 3)} chunks` },\n            { label: 'Delimiter Format', value: '<context_document_id>' },\n          ],\n          codeOrData: {\n            title: 'Assembled Prompt Context Envelope',\n            content:\n              '<system>\\nYou are a Lead Design Systems Architect. Synthesize answers strictly from provided context chunks.\\nAlways ground every technical claim with an inline citation key [1], [2], or [3].\\n</system>\\n\\n<context>\\n[1] doc: docs/styling/tailwind-v4-oklch.md (score: 0.942)\\n[2] doc: docs/tokens/color-derivation.md (score: 0.887)\\n[3] doc: blog/2026/design-systems-monorepo.md (score: 0.824)\\n</context>',\n          },\n        },\n      },\n      {\n        id: 5,\n        name: '5. LLM Synthesis & Grounding',\n        subtitle: 'Claude 3.5 Sonnet streaming generation · 820ms',\n        latency: '820ms',\n        durationMs: 820,\n        status: 'completed',\n        icon: Bot,\n        tag: 'Streaming Synthesis',\n        details: {\n          description:\n            'Generates final structured markdown answer with streaming tokens, verifies every claim against citation sources, and produces grounded output.',\n          metrics: [\n            { label: 'Model', value: 'claude-3-5-sonnet-20241022' },\n            { label: 'Time to First Token', value: '180ms' },\n            { label: 'Generation Speed', value: '68.2 tokens/sec' },\n            { label: 'Grounding Verification', value: '100% (3/3 facts grounded)' },\n          ],\n          codeOrData: {\n            title: 'Telemetry & Cost Summary',\n            content:\n              'Prompt Tokens: 1,248 ($0.00374)\\nCompletion Tokens: 214 ($0.00064)\\nTotal Cost: $0.00438\\nHallucination Detection: 0 violations detected',\n          },\n        },\n      },\n    ],\n    [rerankerEnabled, topK],\n  )\n\n  const displayedChunks = React.useMemo(() => {\n    const count = Math.min(Math.max(1, topK), allChunks.length)\n    return allChunks.slice(0, count)\n  }, [topK])\n\n  const currentStage = stages.find((s) => s.id === selectedStageId) ?? stages[0]\n\n  const totalPipelineLatency = React.useMemo(() => {\n    const sum = stages.reduce((acc, s) => acc + s.durationMs, 0)\n    return `${sum}ms`\n  }, [stages])\n\n  const traceJson = React.useMemo(() => {\n    return JSON.stringify(\n      {\n        traceId: 'trc_rag_948201a4',\n        pipeline: 'enterprise_knowledge_rag_v3',\n        timestamp: new Date().toISOString(),\n        query: currentQuery,\n        config: {\n          embeddingModel: 'text-embedding-3-small',\n          dimensions: 1536,\n          vectorDb: 'Pinecone Serverless',\n          topK: topK,\n          reranker: rerankerEnabled ? 'cohere-rerank-v3' : 'none',\n          alphaFusion: 0.7,\n        },\n        stages: stages.map((s) => ({\n          id: s.id,\n          name: s.name,\n          durationMs: s.durationMs,\n          status: s.status,\n        })),\n        retrievedChunks: displayedChunks.map((c) => ({\n          citation: c.citationIndex,\n          docPath: c.documentPath,\n          relevance: rerankerEnabled ? c.relevanceScore : c.cosineScore,\n          rerankBoost: rerankerEnabled ? c.rerankBoost : 0,\n          tokenCount: c.tokenCount,\n        })),\n        synthesis: {\n          model: 'claude-3-5-sonnet-20241022',\n          promptTokens: 1248,\n          completionTokens: 214,\n          groundedFactRatio: 1.0,\n          latencyMs: 820,\n        },\n      },\n      null,\n      2,\n    )\n  }, [currentQuery, topK, rerankerEnabled, stages, displayedChunks])\n\n  const handleRunPipeline = () => {\n    if (isExecuting) return\n    setIsExecuting(true)\n    setSelectedStageId(1)\n\n    setTimeout(() => {\n      setSelectedStageId(2)\n    }, 200)\n\n    setTimeout(() => {\n      setSelectedStageId(3)\n    }, 450)\n\n    setTimeout(() => {\n      setSelectedStageId(4)\n    }, 700)\n\n    setTimeout(() => {\n      setSelectedStageId(5)\n      setIsExecuting(false)\n    }, 950)\n  }\n\n  const handleSelectPreset = (preset: string) => {\n    setCurrentQuery(preset)\n    handleRunPipeline()\n  }\n\n  const handleCopyChunk = (id: string, text: string) => {\n    navigator.clipboard.writeText(text)\n    setCopiedChunkId(id)\n    setTimeout(() => {\n      setCopiedChunkId(null)\n    }, 2000)\n  }\n\n  const handleCopyResponse = (text: string) => {\n    navigator.clipboard.writeText(text)\n    setCopiedResponse(true)\n    setTimeout(() => {\n      setCopiedResponse(false)\n    }, 2000)\n  }\n\n  const handleCopyTrace = () => {\n    navigator.clipboard.writeText(traceJson)\n    setCopiedTrace(true)\n    setTimeout(() => {\n      setCopiedTrace(false)\n    }, 2000)\n  }\n\n  return (\n    <div className={cn('w-full space-y-6 font-sans', className)}>\n      {/* 1. Pipeline Header */}\n      <Card className=\"border-border bg-card shadow-xs\">\n        <CardHeader className=\"pb-4\">\n          <div className=\"flex flex-col gap-4 md:flex-row md:items-center md:justify-between\">\n            <div className=\"space-y-1.5\">\n              <div className=\"flex flex-wrap items-center gap-2\">\n                <div className=\"bg-primary/10 text-primary flex size-8 items-center justify-center rounded-lg\">\n                  <Workflow className=\"size-4.5\" />\n                </div>\n                <h2 className=\"text-foreground text-lg font-semibold tracking-tight sm:text-xl\">\n                  enterprise_knowledge_rag_v3\n                </h2>\n                <Badge variant=\"outline\" className=\"border-success/30 bg-success/10 text-success\">\n                  <span className=\"bg-success mr-1.5 size-1.5 rounded-full motion-safe:animate-pulse\" />\n                  Pipeline Active\n                </Badge>\n                <Badge variant=\"secondary\" className=\"font-mono text-xs\">\n                  p99 {totalPipelineLatency}\n                </Badge>\n              </div>\n              <p className=\"text-muted-foreground text-sm\">\n                Production Retrieval-Augmented Generation pipeline with HyDE query rewriting, hybrid reciprocal rank\n                fusion, and cross-encoder validation.\n              </p>\n            </div>\n\n            <div className=\"flex flex-wrap items-center gap-2\">\n              <Button\n                variant=\"outline\"\n                size=\"sm\"\n                className=\"gap-1.5 shadow-xs\"\n                onClick={() => setShowTraceJson(!showTraceJson)}\n              >\n                <FileCode className=\"size-4\" />\n                <span>{showTraceJson ? 'Hide Trace' : 'Export Trace JSON'}</span>\n              </Button>\n              <Button size=\"sm\" className=\"gap-1.5 shadow-xs\" disabled={isExecuting} onClick={handleRunPipeline}>\n                {isExecuting ? (\n                  <RefreshCw className=\"size-4 motion-safe:animate-spin\" />\n                ) : (\n                  <Play className=\"size-4 fill-current\" />\n                )}\n                <span>{isExecuting ? 'Executing Pipeline...' : 'Test Query Pipeline'}</span>\n              </Button>\n            </div>\n          </div>\n\n          {/* Pipeline Metadata Specs Bar */}\n          <div className=\"border-border mt-4 grid grid-cols-2 gap-2 border-t pt-4 text-xs sm:grid-cols-4\">\n            <div className=\"text-muted-foreground flex items-center gap-2\">\n              <Cpu className=\"text-primary size-3.5 shrink-0\" />\n              <span className=\"truncate\">\n                <strong className=\"text-foreground font-medium\">Embedding:</strong> OpenAI text-embedding-3-small ·\n                1536-dim\n              </span>\n            </div>\n            <div className=\"text-muted-foreground flex items-center gap-2\">\n              <Database className=\"text-primary size-3.5 shrink-0\" />\n              <span className=\"truncate\">\n                <strong className=\"text-foreground font-medium\">Vector DB:</strong> Pinecone Serverless · HNSW\n              </span>\n            </div>\n            <div className=\"text-muted-foreground flex items-center gap-2\">\n              <Layers className=\"text-primary size-3.5 shrink-0\" />\n              <span className=\"truncate\">\n                <strong className=\"text-foreground font-medium\">Index Space:</strong> 482,910 chunks · 4 namespaces\n              </span>\n            </div>\n            <div className=\"text-muted-foreground flex items-center gap-2\">\n              <ShieldCheck className=\"text-success size-3.5 shrink-0\" />\n              <span className=\"truncate\">\n                <strong className=\"text-foreground font-medium\">Grounding:</strong> 100% strict context citation\n              </span>\n            </div>\n          </div>\n        </CardHeader>\n      </Card>\n\n      {/* Optional Trace JSON Drawer */}\n      {showTraceJson && (\n        <Card className=\"border-border bg-card/95 shadow-xs\">\n          <CardHeader className=\"pb-2\">\n            <div className=\"flex items-center justify-between\">\n              <div className=\"flex items-center gap-2\">\n                <Terminal className=\"text-primary size-4\" />\n                <CardTitle className=\"text-sm font-medium\">OpenTelemetry Pipeline Execution Trace</CardTitle>\n              </div>\n              <Button variant=\"ghost\" size=\"xs\" className=\"gap-1\" onClick={handleCopyTrace}>\n                {copiedTrace ? <Check className=\"text-success size-3.5\" /> : <Copy className=\"size-3.5\" />}\n                <span>{copiedTrace ? 'Copied JSON' : 'Copy Trace'}</span>\n              </Button>\n            </div>\n          </CardHeader>\n          <CardContent>\n            <pre className=\"bg-muted/70 text-foreground max-h-64 overflow-x-auto rounded-md p-3 font-mono text-xs\">\n              {traceJson}\n            </pre>\n          </CardContent>\n        </Card>\n      )}\n\n      {/* 2. Query Input & Runtime Controls Bar */}\n      <Card className=\"border-border bg-card shadow-xs\">\n        <CardContent className=\"space-y-4 p-4 sm:p-6\">\n          <div className=\"space-y-2\">\n            <div className=\"flex items-center justify-between\">\n              <label\n                htmlFor=\"rag-query-input-react\"\n                className=\"text-muted-foreground text-xs font-semibold tracking-wider uppercase\"\n              >\n                Interactive Test Query\n              </label>\n              <span className=\"text-muted-foreground text-xs\">Press Enter or click Test Query to simulate</span>\n            </div>\n\n            <div className=\"relative flex items-center\">\n              <Input\n                id=\"rag-query-input-react\"\n                value={currentQuery}\n                onChange={(e) => setCurrentQuery(e.target.value)}\n                onKeyDown={(e) => {\n                  if (e.key === 'Enter') handleRunPipeline()\n                }}\n                className=\"pr-20 text-sm font-medium shadow-xs\"\n                placeholder=\"Enter search prompt or technical query...\"\n                prefixIcon={<Search className=\"text-muted-foreground size-4\" />}\n              />\n              <Button size=\"xs\" className=\"absolute right-1.5 gap-1\" disabled={isExecuting} onClick={handleRunPipeline}>\n                <Zap className=\"size-3\" />\n                <span>Run</span>\n              </Button>\n            </div>\n          </div>\n\n          {/* Query Presets Chips */}\n          <div className=\"flex flex-wrap items-center gap-1.5\">\n            <span className=\"text-muted-foreground text-xs font-medium\">Presets:</span>\n            {presetQueries.map((preset) => (\n              <button\n                key={preset}\n                type=\"button\"\n                className={cn(\n                  'focus-visible:ring-ring min-h-6 cursor-pointer rounded-full border px-2.5 py-0.5 text-xs transition-colors focus-visible:ring-2 focus-visible:outline-hidden',\n                  currentQuery === preset\n                    ? 'border-primary bg-primary/10 text-primary font-medium'\n                    : 'border-border bg-muted/40 text-muted-foreground hover:bg-muted hover:text-foreground',\n                )}\n                onClick={() => handleSelectPreset(preset)}\n              >\n                {preset}\n              </button>\n            ))}\n          </div>\n\n          <Separator />\n\n          {/* Controls Toolbar: Top-K Slider + Reranker Switch + Metrics */}\n          <div className=\"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3\">\n            {/* Top-K Slider */}\n            <div className=\"space-y-2\">\n              <div className=\"flex items-center justify-between\">\n                <div className=\"flex items-center gap-1.5\">\n                  <SlidersHorizontal className=\"text-primary size-3.5\" />\n                  <span className=\"text-foreground text-xs font-medium\">Top-K Chunks</span>\n                </div>\n                <Badge variant=\"secondary\" className=\"font-mono text-xs\">\n                  Top {topK} Chunks\n                </Badge>\n              </div>\n              <Slider\n                value={[topK]}\n                min={1}\n                max={3}\n                step={1}\n                tooltip={false}\n                className=\"w-full\"\n                onValueChange={(val) => setTopK(val[0])}\n              />\n              <div className=\"text-muted-foreground flex justify-between font-mono text-xs\">\n                <span>k=1</span>\n                <span>k=2</span>\n                <span>k=3</span>\n              </div>\n            </div>\n\n            {/* Reranker Toggle */}\n            <div className=\"border-border/80 bg-muted/20 flex flex-col justify-between space-y-2 rounded-lg border p-3\">\n              <div className=\"flex items-center justify-between\">\n                <div className=\"space-y-0.5\">\n                  <div className=\"flex items-center gap-1.5\">\n                    <Filter className=\"text-primary size-3.5\" />\n                    <span className=\"text-foreground text-xs font-semibold\">Cohere Rerank v3</span>\n                  </div>\n                  <p className=\"text-muted-foreground text-xs\">Cross-encoder contextual re-scoring</p>\n                </div>\n                <Switch checked={rerankerEnabled} onCheckedChange={setRerankerEnabled} />\n              </div>\n              <div className=\"flex items-center gap-2\">\n                <Badge\n                  variant={rerankerEnabled ? 'outline' : 'secondary'}\n                  className={cn(\n                    'font-mono text-xs',\n                    rerankerEnabled ? 'border-success/30 bg-success/10 text-success' : 'text-muted-foreground',\n                  )}\n                >\n                  {rerankerEnabled ? 'Active (+0.142 boost)' : 'Bypassed (Cosine only)'}\n                </Badge>\n              </div>\n            </div>\n\n            {/* Pipeline Telemetry Overview */}\n            <div className=\"border-border/80 bg-muted/20 flex flex-col justify-between space-y-1.5 rounded-lg border p-3 sm:col-span-2 lg:col-span-1\">\n              <div className=\"flex items-center justify-between\">\n                <span className=\"text-foreground text-xs font-semibold\">Execution Latency</span>\n                <span className=\"text-primary font-mono text-xs font-medium\">{totalPipelineLatency} total</span>\n              </div>\n              <div className=\"space-y-1\">\n                <div className=\"text-muted-foreground flex justify-between text-xs\">\n                  <span>Dense + BM25</span>\n                  <span className=\"font-mono\">106ms</span>\n                </div>\n                <Progress value={15} className=\"h-1.5\" />\n              </div>\n              <div className=\"space-y-1\">\n                <div className=\"text-muted-foreground flex justify-between text-xs\">\n                  <span>LLM Synthesis</span>\n                  <span className=\"font-mono\">820ms (85%)</span>\n                </div>\n                <Progress value={85} className=\"h-1.5\" />\n              </div>\n            </div>\n          </div>\n        </CardContent>\n      </Card>\n\n      {/* 3. Interactive RAG 5-Stage Architecture Flow */}\n      <div className=\"space-y-3\">\n        <div className=\"flex items-center justify-between\">\n          <div>\n            <h3 className=\"text-foreground text-xs font-semibold tracking-wider uppercase\">\n              RAG Pipeline Execution Graph\n            </h3>\n            <p className=\"text-muted-foreground text-xs\">\n              Click any stage node to inspect low-level telemetry, prompt variables, and intermediate embeddings.\n            </p>\n          </div>\n          <Badge variant=\"outline\" className=\"font-mono text-xs\">\n            5 Connected Stages\n          </Badge>\n        </div>\n\n        {/* 5-Stage Connected Cards */}\n        <div className=\"grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-5\">\n          {stages.map((stage) => {\n            const Icon = stage.icon\n            const isSelected = selectedStageId === stage.id\n            return (\n              <div\n                key={stage.id}\n                className={cn(\n                  'group focus-visible:ring-ring relative flex cursor-pointer flex-col justify-between rounded-lg border p-3.5 transition-colors focus-visible:ring-2 focus-visible:outline-hidden',\n                  isSelected\n                    ? 'border-primary bg-primary/5 ring-primary/40 shadow-xs ring-1'\n                    : 'border-border bg-card hover:border-primary/40 hover:bg-muted/30',\n                )}\n                tabIndex={0}\n                role=\"button\"\n                aria-pressed={isSelected}\n                onClick={() => setSelectedStageId(stage.id)}\n                onKeyDown={(e) => {\n                  if (e.key === 'Enter' || e.key === ' ') {\n                    e.preventDefault()\n                    setSelectedStageId(stage.id)\n                  }\n                }}\n              >\n                <div className=\"space-y-2\">\n                  <div className=\"flex items-center justify-between\">\n                    <div\n                      className={cn(\n                        'flex size-7 items-center justify-center rounded-md text-xs font-semibold',\n                        isSelected\n                          ? 'bg-primary text-primary-foreground'\n                          : 'bg-muted text-foreground group-hover:bg-primary/20 group-hover:text-primary',\n                      )}\n                    >\n                      <Icon className=\"size-3.5\" />\n                    </div>\n                    <Badge\n                      variant=\"secondary\"\n                      className={cn(\n                        'font-mono text-xs',\n                        stage.status === 'bypassed' && 'text-muted-foreground line-through opacity-70',\n                      )}\n                    >\n                      {stage.latency}\n                    </Badge>\n                  </div>\n\n                  <div>\n                    <p className=\"text-foreground text-xs leading-tight font-semibold\">{stage.name}</p>\n                    <p className=\"text-muted-foreground mt-1 line-clamp-2 text-xs leading-relaxed\">{stage.subtitle}</p>\n                  </div>\n                </div>\n\n                <div className=\"border-border/60 text-muted-foreground mt-3 flex items-center justify-between border-t pt-2 text-xs\">\n                  <span className=\"truncate font-medium\">{stage.tag}</span>\n                  <ChevronRight\n                    className={cn(\n                      'size-3.5 transition-transform',\n                      isSelected ? 'text-primary translate-x-0.5' : 'text-muted-foreground',\n                    )}\n                  />\n                </div>\n              </div>\n            )\n          })}\n        </div>\n\n        {/* Stage Detail Drill-down Panel */}\n        <Card className=\"border-border bg-card/60 shadow-xs\">\n          <CardHeader className=\"pb-3\">\n            <div className=\"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between\">\n              <div className=\"flex items-center gap-2\">\n                <div className=\"bg-primary/10 text-primary flex size-7 items-center justify-center rounded-md\">\n                  {React.createElement(currentStage.icon, { className: 'size-4' })}\n                </div>\n                <div>\n                  <CardTitle className=\"text-foreground text-sm font-semibold\">\n                    {currentStage.name} — Inspector\n                  </CardTitle>\n                  <CardDescription className=\"text-xs\">{currentStage.details.description}</CardDescription>\n                </div>\n              </div>\n              <Badge variant=\"outline\" className=\"w-fit font-mono text-xs\">\n                Stage {currentStage.id} of 5 · {currentStage.latency}\n              </Badge>\n            </div>\n          </CardHeader>\n          <CardContent className=\"space-y-4 pt-0\">\n            {/* Metrics Grid for Stage */}\n            <div className=\"grid grid-cols-2 gap-2 sm:grid-cols-4\">\n              {currentStage.details.metrics.map((metric) => (\n                <div key={metric.label} className=\"border-border/80 bg-muted/40 rounded-md border p-2.5\">\n                  <p className=\"text-muted-foreground text-xs\">{metric.label}</p>\n                  <p className=\"text-foreground mt-0.5 truncate font-mono text-xs font-semibold\">{metric.value}</p>\n                </div>\n              ))}\n            </div>\n\n            {/* Code or Data Artifact Preview */}\n            {currentStage.details.codeOrData && (\n              <div className=\"space-y-1.5\">\n                <div className=\"text-muted-foreground flex items-center justify-between text-xs font-medium\">\n                  <span className=\"flex items-center gap-1.5\">\n                    <Code2 className=\"text-primary size-3.5\" />\n                    {currentStage.details.codeOrData.title}\n                  </span>\n                  <span className=\"font-mono text-xs\">read-only buffer</span>\n                </div>\n                <pre className=\"bg-muted/80 text-foreground max-h-40 overflow-x-auto rounded-md p-3 font-mono text-xs leading-relaxed whitespace-pre-wrap\">\n                  {currentStage.details.codeOrData.content}\n                </pre>\n              </div>\n            )}\n          </CardContent>\n        </Card>\n      </div>\n\n      {/* 4. Retrieved Context Chunks Inspector */}\n      <div className=\"space-y-3\">\n        <div className=\"flex items-center justify-between\">\n          <div>\n            <h3 className=\"text-foreground text-xs font-semibold tracking-wider uppercase\">\n              Retrieved Context Chunks ({displayedChunks.length} Active Chunks)\n            </h3>\n            <p className=\"text-muted-foreground text-xs\">\n              Ranked by cross-encoder relevance score. Keyword spans matching user intent are highlighted.\n            </p>\n          </div>\n          <div className=\"flex items-center gap-2\">\n            <Badge variant=\"secondary\" className=\"font-mono text-xs\">\n              Fusion: Dense (70%) + Sparse (30%)\n            </Badge>\n          </div>\n        </div>\n\n        <div className=\"space-y-3\">\n          {displayedChunks.map((chunk) => (\n            <Card\n              key={chunk.id}\n              className={cn(\n                'border-border bg-card shadow-xs transition-colors',\n                activeCitationHover === chunk.citationIndex && 'border-primary/80 ring-primary/20 bg-primary/5 ring-2',\n              )}\n            >\n              <CardHeader className=\"p-4 pb-2\">\n                <div className=\"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between\">\n                  <div className=\"flex flex-wrap items-center gap-2\">\n                    {/* Citation Badge Pill */}\n                    <span\n                      className={cn(\n                        'flex size-6 items-center justify-center rounded-md font-mono text-xs font-bold transition-colors',\n                        activeCitationHover === chunk.citationIndex\n                          ? 'bg-primary text-primary-foreground'\n                          : 'bg-muted text-foreground',\n                      )}\n                    >\n                      [{chunk.citationIndex}]\n                    </span>\n\n                    {/* Relevancy Score Badge */}\n                    <Badge\n                      variant=\"outline\"\n                      className={cn(\n                        'font-mono text-xs font-semibold',\n                        chunk.relevanceScore >= 0.9\n                          ? 'border-success/30 bg-success/10 text-success'\n                          : chunk.relevanceScore >= 0.85\n                            ? 'border-success/30 bg-success/10 text-success'\n                            : 'border-info/30 bg-info/10 text-info',\n                      )}\n                    >\n                      Score: {rerankerEnabled ? chunk.relevanceScore.toFixed(3) : chunk.cosineScore.toFixed(3)}\n                    </Badge>\n\n                    {/* Rerank Delta Badge */}\n                    {rerankerEnabled && (\n                      <Badge variant=\"secondary\" className=\"text-muted-foreground font-mono text-xs\">\n                        +{chunk.rerankBoost.toFixed(3)} boost (Rank #{chunk.citationIndex})\n                      </Badge>\n                    )}\n\n                    {/* Document Path */}\n                    <span className=\"text-foreground font-mono text-xs font-medium\">{chunk.documentPath}</span>\n                  </div>\n\n                  {/* Metadata & Copy Action */}\n                  <div className=\"flex items-center gap-2\">\n                    <span className=\"text-muted-foreground hidden font-mono text-xs sm:inline\">\n                      {chunk.chunkOffset} · {chunk.tokenCount} tok\n                    </span>\n                    <Button\n                      variant=\"ghost\"\n                      size=\"xs\"\n                      className=\"text-muted-foreground hover:text-foreground gap-1\"\n                      onClick={() => handleCopyChunk(chunk.id, chunk.fullSnippet)}\n                    >\n                      {copiedChunkId === chunk.id ? (\n                        <Check className=\"text-success size-3\" />\n                      ) : (\n                        <Copy className=\"size-3\" />\n                      )}\n                      <span className=\"text-xs\">{copiedChunkId === chunk.id ? 'Copied' : 'Copy'}</span>\n                    </Button>\n                  </div>\n                </div>\n              </CardHeader>\n\n              <CardContent className=\"p-4 pt-2\">\n                {/* Chunk Text with Highlighted Spans */}\n                <div className=\"border-border/70 bg-muted/40 text-foreground rounded-md border p-3 font-mono text-xs leading-relaxed\">\n                  <span>{chunk.snippetPrefix}</span>\n                  <mark className=\"bg-primary/20 text-primary dark:bg-primary/30 rounded px-1 py-0.5 font-semibold\">\n                    {chunk.highlightedText}\n                  </mark>\n                  <span>{chunk.snippetSuffix}</span>\n                </div>\n\n                {/* Scoring Breakdown Sub-bar */}\n                <div className=\"text-muted-foreground mt-2.5 flex flex-wrap items-center justify-between gap-2 text-xs\">\n                  <div className=\"flex flex-wrap items-center gap-3 font-mono\">\n                    <span>\n                      Dense Cosine:{' '}\n                      <strong className=\"text-foreground font-semibold\">{chunk.cosineScore.toFixed(3)}</strong>\n                    </span>\n                    <span>\n                      Sparse BM25:{' '}\n                      <strong className=\"text-foreground font-semibold\">{chunk.bm25Score.toFixed(3)}</strong>\n                    </span>\n                    {rerankerEnabled && (\n                      <span>\n                        Cross-Encoder:{' '}\n                        <strong className=\"text-success font-semibold\">{chunk.relevanceScore.toFixed(3)}</strong>\n                      </span>\n                    )}\n                  </div>\n                  <span className=\"text-muted-foreground text-xs\">Updated {chunk.updatedAgo}</span>\n                </div>\n              </CardContent>\n            </Card>\n          ))}\n        </div>\n      </div>\n\n      {/* 5. Final Synthesized Output Card with Citations */}\n      <Card className=\"border-border bg-card shadow-xs\">\n        <CardHeader className=\"pb-3\">\n          <div className=\"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between\">\n            <div className=\"flex items-center gap-2\">\n              <div className=\"bg-primary text-primary-foreground flex size-7 items-center justify-center rounded-md\">\n                <Sparkles className=\"size-4\" />\n              </div>\n              <div>\n                <CardTitle className=\"text-foreground text-base font-semibold\">Synthesized Grounded Response</CardTitle>\n                <CardDescription className=\"text-xs\">\n                  Generated via Claude 3.5 Sonnet streaming with verified inline citations.\n                </CardDescription>\n              </div>\n            </div>\n\n            <div className=\"flex flex-wrap items-center gap-2\">\n              <Badge variant=\"outline\" className=\"border-success/30 bg-success/10 text-success font-mono text-xs\">\n                <ShieldCheck className=\"mr-1 size-3\" />\n                100% Grounded · 0 Hallucinations\n              </Badge>\n              <Badge variant=\"secondary\" className=\"font-mono text-xs\">\n                820ms (TTFT 180ms)\n              </Badge>\n            </div>\n          </div>\n        </CardHeader>\n\n        <CardContent className=\"space-y-4\">\n          {/* Markdown Formatted Synthesized Body */}\n          <div className=\"border-border/80 bg-muted/20 text-foreground space-y-3 rounded-lg border p-4 text-sm leading-relaxed sm:p-5\">\n            <p className=\"text-foreground font-medium\">\n              To configure OKLCH color palettes in Tailwind CSS v4 with UIPKGE:\n            </p>\n\n            <ol className=\"text-foreground/90 list-decimal space-y-2.5 pl-5 text-sm\">\n              <li className=\"leading-relaxed\">\n                <strong>Define Theme Tokens in CSS:</strong> Use{' '}\n                <code className=\"bg-muted text-foreground rounded px-1.5 py-0.5 font-mono text-xs\">@theme inline</code>{' '}\n                in your root stylesheet to declare single-source-of-truth OKLCH variables\n                <button\n                  type=\"button\"\n                  className=\"bg-primary/10 py-0.2 text-primary hover:bg-primary hover:text-primary-foreground mx-1 inline-flex min-h-6 cursor-pointer items-center rounded px-1 font-mono text-xs font-bold transition-colors\"\n                  onMouseEnter={() => setActiveCitationHover(1)}\n                  onMouseLeave={() => setActiveCitationHover(null)}\n                >\n                  [1]\n                </button>\n                . Unlike legacy RGB/HSL, OKLCH ensures perceptually uniform lightness across hue shifts\n                <button\n                  type=\"button\"\n                  className=\"bg-primary/10 py-0.2 text-primary hover:bg-primary hover:text-primary-foreground mx-1 inline-flex min-h-6 cursor-pointer items-center rounded px-1 font-mono text-xs font-bold transition-colors\"\n                  onMouseEnter={() => setActiveCitationHover(1)}\n                  onMouseLeave={() => setActiveCitationHover(null)}\n                >\n                  [1]\n                </button>\n                .\n              </li>\n\n              <li className=\"leading-relaxed\">\n                <strong>Calibrate Dark Mode Contrasts:</strong> Anchor chroma and shift lightness along the OKLCH L-axis\n                (e.g.,{' '}\n                <code className=\"bg-muted rounded px-1.5 py-0.5 font-mono text-xs\">\n                  --color-primary: oklch(0.65 0.22 260)\n                </code>{' '}\n                and{' '}\n                <code className=\"bg-muted rounded px-1.5 py-0.5 font-mono text-xs\">\n                  --color-border: oklch(0.28 0.01 260)\n                </code>\n                ) to maintain WCAG AA compliance across both light and dark modes\n                <button\n                  type=\"button\"\n                  className=\"bg-primary/10 py-0.2 text-primary hover:bg-primary hover:text-primary-foreground mx-1 inline-flex min-h-6 cursor-pointer items-center rounded px-1 font-mono text-xs font-bold transition-colors\"\n                  onMouseEnter={() => setActiveCitationHover(2)}\n                  onMouseLeave={() => setActiveCitationHover(null)}\n                >\n                  [2]\n                </button>\n                .\n              </li>\n\n              <li className=\"leading-relaxed\">\n                <strong>Maintain Dual-Framework CVA Parity:</strong> Wire CSS tokens directly through Class Variance\n                Authority (<code className=\"bg-muted rounded px-1.5 py-0.5 font-mono text-xs\">cva()</code>) variants so\n                that both Vue and React registry components share identical token namespaces with zero runtime bundle\n                overhead\n                <button\n                  type=\"button\"\n                  className=\"bg-primary/10 py-0.2 text-primary hover:bg-primary hover:text-primary-foreground mx-1 inline-flex min-h-6 cursor-pointer items-center rounded px-1 font-mono text-xs font-bold transition-colors\"\n                  onMouseEnter={() => setActiveCitationHover(3)}\n                  onMouseLeave={() => setActiveCitationHover(null)}\n                >\n                  [3]\n                </button>\n                .\n              </li>\n            </ol>\n\n            {/* Streaming cursor pulse */}\n            <div className=\"text-muted-foreground flex items-center gap-1.5 pt-1 font-mono text-xs\">\n              <span className=\"bg-success size-2 rounded-full motion-safe:animate-ping\" />\n              <span>Generation Complete · 214 tokens streamed</span>\n            </div>\n          </div>\n\n          {/* Citation Footnotes Bar */}\n          <div className=\"border-border/70 bg-muted/40 space-y-1.5 rounded-md border p-3 text-xs\">\n            <span className=\"text-foreground flex items-center gap-1.5 font-semibold\">\n              <BookOpen className=\"text-primary size-3.5\" />\n              Referenced Citations (Hover citation to locate chunk):\n            </span>\n            <div className=\"grid grid-cols-1 gap-1.5 sm:grid-cols-3\">\n              {displayedChunks.map((chunk) => (\n                <div\n                  key={chunk.id}\n                  className={cn(\n                    'flex cursor-pointer items-center justify-between rounded border p-1.5 font-mono text-xs transition-colors',\n                    activeCitationHover === chunk.citationIndex\n                      ? 'border-primary bg-primary/10 text-primary'\n                      : 'border-border/60 bg-card text-muted-foreground hover:bg-muted',\n                  )}\n                  onMouseEnter={() => setActiveCitationHover(chunk.citationIndex)}\n                  onMouseLeave={() => setActiveCitationHover(null)}\n                >\n                  <span className=\"truncate\">\n                    [{chunk.citationIndex}] {chunk.documentPath.split('/').pop()}\n                  </span>\n                  <span className=\"font-semibold\">{chunk.relevanceScore.toFixed(3)}</span>\n                </div>\n              ))}\n            </div>\n          </div>\n\n          {/* Telemetry Footer & Action Buttons */}\n          <div className=\"border-border text-muted-foreground flex flex-col gap-3 border-t pt-2 text-xs sm:flex-row sm:items-center sm:justify-between\">\n            <div className=\"flex flex-wrap items-center gap-3 font-mono\">\n              <span>\n                Input: <strong className=\"text-foreground\">1,248 tok</strong>\n              </span>\n              <span>\n                Output: <strong className=\"text-foreground\">214 tok</strong>\n              </span>\n              <span>\n                Cost: <strong className=\"text-foreground\">$0.00438</strong>\n              </span>\n              <span>\n                Grounding: <strong className=\"text-success\">99.4%</strong>\n              </span>\n            </div>\n\n            <div className=\"flex items-center gap-2\">\n              <div className=\"border-border bg-card flex items-center rounded-md border p-0.5\">\n                <Button\n                  aria-label=\"Thumbs up\"\n                  variant=\"ghost\"\n                  size=\"xs\"\n                  className={cn('px-2', userFeedback === 'up' && 'text-success')}\n                  onClick={() => setUserFeedback(userFeedback === 'up' ? null : 'up')}\n                >\n                  <ThumbsUp className=\"size-3.5\" />\n                </Button>\n                <Separator orientation=\"vertical\" className=\"h-4\" />\n                <Button\n                  aria-label=\"Thumbs down\"\n                  variant=\"ghost\"\n                  size=\"xs\"\n                  className={cn('px-2', userFeedback === 'down' && 'text-destructive')}\n                  onClick={() => setUserFeedback(userFeedback === 'down' ? null : 'down')}\n                >\n                  <ThumbsDown className=\"size-3.5\" />\n                </Button>\n              </div>\n\n              <Button variant=\"outline\" size=\"xs\" className=\"gap-1\" onClick={handleRunPipeline}>\n                <RefreshCw className=\"size-3\" />\n                <span>Regenerate</span>\n              </Button>\n\n              <Button\n                size=\"xs\"\n                className=\"gap-1\"\n                onClick={() =>\n                  handleCopyResponse(\n                    'To configure OKLCH color palettes in Tailwind CSS v4 with UIPKGE: 1. Define Theme Tokens in CSS (@theme inline)... 2. Calibrate Dark Mode Contrasts... 3. Maintain Dual-Framework CVA Parity...',\n                  )\n                }\n              >\n                {copiedResponse ? <Check className=\"size-3\" /> : <Copy className=\"size-3\" />}\n                <span>{copiedResponse ? 'Copied' : 'Copy Answer'}</span>\n              </Button>\n            </div>\n          </div>\n        </CardContent>\n      </Card>\n    </div>\n  )\n}\n\nexport default RagPipelineVisualizer\n",
      "type": "registry:block",
      "target": "~/components/blocks/RagPipelineVisualizer.tsx"
    }
  ],
  "dependencies": [
    "lucide-react"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://uipkge.dev/r/react/badge.json",
    "https://uipkge.dev/r/react/button.json",
    "https://uipkge.dev/r/react/card.json",
    "https://uipkge.dev/r/react/input.json",
    "https://uipkge.dev/r/react/progress.json",
    "https://uipkge.dev/r/react/separator.json",
    "https://uipkge.dev/r/react/slider.json",
    "https://uipkge.dev/r/react/switch.json"
  ],
  "description": "LlamaIndex and LangChain style Retrieval-Augmented Generation (RAG) pipeline debugger and chunk retrieval inspector. Features 5-stage interactive DAG flow, HyDE expansion preview, hybrid dense/sparse search telemetry, cross-encoder reranking, and grounded response synthesis.",
  "categories": [
    "ai",
    "dashboard",
    "database",
    "app"
  ]
}