"use client"; import { BarChart3, Check, Lightbulb, X } from "lucide-react"; import Link from "next/link"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useMemo, useState } from "react"; import { docParts, METHODS, type QuestionSummary } from "@/lib/types"; import { BarBreakdown } from "./charts"; import { QuestionPicker, useQuestion } from "./QuestionPicker"; import { Banner, Card, Pill } from "./ui"; const METRIC_KEY: Record = { bm25: "1_bm25", dense: "2_dense", hybrid: "3_hybrid_rrf", routed: "4_dense_routed", reranked: "5_dense_routed_reranked", }; export function CompareMethods({ questions, metrics }: { questions: QuestionSummary[]; metrics: Record> }) { const params = useSearchParams(); const router = useRouter(); const pathname = usePathname(); const fromUrl = params.has("q") ? Number(params.get("q")) : NaN; const interesting = useMemo(() => { const keywordMiss = questions.filter((q) => q.rank.reranked === 1 && q.rank.bm25 === null).slice(0, 3); const routingHelps = questions.filter((q) => q.rank.dense === null && q.rank.reranked !== null && q.rank.reranked <= 3).slice(0, 2); return [...keywordMiss.map((q) => ({ q, why: "BM25 misses, reranker #1" })), ...routingHelps.map((q) => ({ q, why: "dense misses, routing finds it" }))]; }, [questions]); const [qi, setQi] = useState(Number.isInteger(fromUrl) && fromUrl >= 0 && fromUrl < questions.length ? fromUrl : interesting[0]?.q.i ?? 0); const { detail } = useQuestion(qi); const choose = (i: number) => { setQi(i); router.replace(`${pathname}?q=${i}`, { scroll: false }); }; return ( <> same question · 5 retrieval steps} meta="Each column is one step of the ladder. A green row is a page the financial analysts marked as the evidence." >
Questions that show the difference: {interesting.map(({ q, why }) => ( ))}
{!detail && Loading the question…} {detail && (
{METHODS.map((m) => { const hits = detail.methods[m.key].slice(0, 5); const rank = detail.methods[m.key].findIndex((h) => h.gold) + 1; const final = m.key === "reranked"; return (

{m.note}

{m.label}

{rank > 0 ? ( evidence at rank {rank} ) : ( not in top 10 )}
    {hits.map((h, k) => { const p = detail.pages[String(h.row)]; const { company, period } = docParts(p.doc); return (
  1. {k + 1} {period} · p.{p.page + 1} {company}
  2. ); })}
); })}
)} } action={Recall@1 · first result is the evidence}> ({ label: m.short, value: metrics[METRIC_KEY[m.key]]["R@1"], highlight: m.key === "reranked" }))} max={0.5} />

How often the very first page is the analysts' evidence page. The final pipeline gets it right on its first try for{" "} {Math.round(metrics["5_dense_routed_reranked"]["R@1"] * 150)} of 150 questions, against {Math.round(metrics["1_bm25"]["R@1"] * 150)} for keyword search.

); }