Skip to content
TuffTasks, docs and chat for teams and AI agents

Observability

Retrieval Inspector

RAG chunk inspector with a draggable similarity cutoff strip — switch Hybrid, Vector or Keyword scoring, expand matched passages, and pin or exclude chunks against a token budget.

2 variantsMIT

Preview

Retrieval inspector

“prorated refund policy for annual plans”

4 of 6 kept
1,300 / 1,500 tok·cutoff 0.72
Similarity cutoffDrag to filter chunks
0.000.501.00
  1. 0.92

    Annual plans canceled within 14 days of renewal qualify for a prorated refund minus any metered overage charges billed in the current cycle.

    Vector0.94Keyword0.89340 tok
  2. 0.82
  3. 0.80
  4. 0.73
  5. 0.66
  6. 0.40
Threshold applies on next turn

Installation

Copies the component into components/ui and installs its dependencies and theme tokens.

pnpm dlx shadcn@latest add https://tuffui.com/r/retrieval-inspector.json

Usage

Pass your own data and wire the callbacks to your agent runtime.

import { RetrievalInspector } from "@/components/ui/retrieval-inspector";

export function RagDebugCard({ search, onUpdateContext }: Props) {
  return (
    <RetrievalInspector
      query={search.query}
      chunks={search.candidates}
      tokenBudget={1500}
      onApply={(ids, threshold, mode) =>
        onUpdateContext({ chunkIds: ids, threshold, mode })
      }
    />
  );
}

Props

PropTypeDefaultDescription
query*string—The search query that retrieved these candidate chunks.
chunks*RetrievalChunk[]—Candidate passages with vector and keyword scores and token counts.
mode"hybrid" | "vector" | "keyword"—Controlled scoring mode.
defaultMode"hybrid" | "vector" | "keyword""hybrid"Initial scoring mode when uncontrolled.
onModeChange(mode: RetrievalMode) => void—Called when the user switches between Hybrid, Vector and Keyword.
thresholdnumber—Controlled minimum score (0..1) required to include a chunk.
defaultThresholdnumber0.72Initial similarity cutoff when uncontrolled.
onThresholdChange(threshold: number) => void—Called as the user drags or nudges the similarity cutoff handle.
tokenBudgetnumber—Optional context budget; warns when kept chunks exceed it.
onApply(includedIds: string[], threshold: number, mode: RetrievalMode) => void—Shows the primary action button and fires with the active chunk IDs.
titleReactNode"Retrieval inspector"Header title.
subtitleReactNode—Secondary line under the title. Defaults to the quoted query.
classNamestring—Extra classes for the outer Shell.
type RetrievalMode = "hybrid" | "vector" | "keyword";

type RetrievalChunk = {
  id: string;
  source: string;
  section?: string;
  excerpt: string;
  vectorScore: number;   // 0..1
  keywordScore: number;  // 0..1
  tokens: number;
  highlights?: string[];
};