File size: 9,825 Bytes
5e17e07 6c0127c 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 6c0127c ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 6c0127c 5e17e07 ac50275 5e17e07 6c0127c ac50275 5e17e07 6c0127c 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 6c0127c ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 6c0127c 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 6c0127c 5e17e07 ac50275 5e17e07 ac50275 5e17e07 ac50275 6c0127c 5e17e07 ac50275 5e17e07 ac50275 5e17e07 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | import type { RRFResult, RerankedResult, FinalResult } from '../types';
import { InfoTooltip } from './PipelineView';
interface FusionColumnState {
rrf: { status: 'idle' | 'done'; data?: { merged: RRFResult[] } };
rerank: { status: 'idle' | 'running' | 'done'; data?: { before: RRFResult[]; after: RerankedResult[] } };
finalResults?: FinalResult[];
}
interface FusionColumnProps {
state: FusionColumnState;
accent: string;
info: string;
}
function Spinner({ color }: { color: string }) {
return (
<span style={{
display: 'inline-block',
width: '14px',
height: '14px',
border: '2px solid var(--border)',
borderTopColor: color,
borderRadius: '50%',
animation: 'spin 0.7s linear infinite',
}} />
);
}
function SectionHeader({ label, color, badge }: { label: string; color: string; badge?: string }) {
return (
<div style={{
fontSize: '0.68rem',
fontWeight: 700,
fontFamily: 'system-ui, -apple-system, sans-serif',
color,
textTransform: 'uppercase',
letterSpacing: '0.06em',
marginBottom: '0.35rem',
display: 'flex',
alignItems: 'center',
gap: '0.4rem',
}}>
{label}
{badge && (
<span style={{ color: 'var(--text-muted)', fontWeight: 400, fontSize: '0.65rem' }}>{badge}</span>
)}
</div>
);
}
function RRFRow({ result, rank }: { result: RRFResult; rank: number }) {
return (
<div style={{
display: 'flex',
alignItems: 'center',
gap: '0.4rem',
padding: '0.3rem 0.5rem',
background: 'var(--bg-card)',
border: '1px solid var(--border)',
borderRadius: '5px',
marginBottom: '0.2rem',
fontSize: '0.72rem',
}}>
<span style={{
fontFamily: "'SF Mono', 'Fira Code', 'Cascadia Code', monospace",
color: 'var(--text-muted)',
fontSize: '0.65rem',
minWidth: '18px',
}}>
#{rank}
</span>
<span style={{
flex: 1,
fontFamily: 'system-ui, -apple-system, sans-serif',
color: 'var(--text)',
fontWeight: 500,
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}}>
{result.title}
</span>
<span style={{
fontFamily: "'SF Mono', 'Fira Code', 'Cascadia Code', monospace",
fontSize: '0.65rem',
color: '#2e7d32',
fontWeight: 700,
flexShrink: 0,
}}>
{result.score.toFixed(4)}
</span>
</div>
);
}
// Rank badge: shows rank # with color coding for movement
function RankBadge({ label, rank, color }: { label: string; rank: number; color: string }) {
return (
<span style={{
display: 'inline-flex',
alignItems: 'center',
gap: '0.15rem',
fontFamily: "'SF Mono', 'Fira Code', 'Cascadia Code', monospace",
fontSize: '0.6rem',
color,
fontWeight: 600,
}}>
<span style={{ color: 'var(--text-muted)', fontWeight: 400, fontSize: '0.55rem' }}>{label}</span>
#{rank}
</span>
);
}
interface RankJourneyRow {
docId: string;
title: string;
rrfRank?: number;
rerankRank?: number;
finalRank?: number;
}
// Shows each doc's rank journey: RRF #N → Reranker #N → Final #N
function RankJourney({ before, after, finalResults }: {
before: RRFResult[];
after: RerankedResult[];
finalResults?: FinalResult[];
}) {
const topLimit = 5;
const topBefore = before.slice(0, topLimit);
const topFinal = (finalResults ?? []).slice(0, topLimit);
const rerankOrder = [...after].sort((a, b) => b.rerankScore - a.rerankScore);
const titleMap = new Map<string, string>([
...before.map((result) => [result.docId, result.title] as const),
...after.map((result) => [result.docId, result.title] as const),
...topFinal.map((result) => [result.docId, result.title] as const),
]);
const rrfRankMap = new Map(before.map((result, index) => [result.docId, index + 1]));
const rerankRankMap = new Map(rerankOrder.map((r, i) => [r.docId, i + 1]));
const finalRankMap = new Map((finalResults ?? []).map((result, index) => [result.docId, index + 1]));
const rowMap = new Map<string, RankJourneyRow>();
for (const result of [...topBefore, ...topFinal]) {
const existing = rowMap.get(result.docId);
rowMap.set(result.docId, {
docId: result.docId,
title: titleMap.get(result.docId) ?? result.title,
rrfRank: rrfRankMap.get(result.docId),
rerankRank: rerankRankMap.get(result.docId),
finalRank: finalRankMap.get(result.docId),
...existing,
});
}
const rows = [...rowMap.values()]
.sort((a, b) =>
(a.finalRank ?? Number.POSITIVE_INFINITY) - (b.finalRank ?? Number.POSITIVE_INFINITY) ||
(a.rrfRank ?? Number.POSITIVE_INFINITY) - (b.rrfRank ?? Number.POSITIVE_INFINITY) ||
(a.rerankRank ?? Number.POSITIVE_INFINITY) - (b.rerankRank ?? Number.POSITIVE_INFINITY),
)
.slice(0, topLimit);
return (
<div>
{rows.map((row) => {
return (
<div key={row.docId} style={{
padding: '0.3rem 0.5rem',
background: 'var(--bg-card)',
border: '1px solid var(--border)',
borderRadius: '5px',
marginBottom: '0.2rem',
fontSize: '0.7rem',
}}>
<div style={{
fontFamily: 'system-ui, -apple-system, sans-serif',
color: 'var(--text)',
fontWeight: 500,
marginBottom: '0.2rem',
}}>
{row.title}
</div>
<div style={{
display: 'flex',
alignItems: 'center',
gap: '0.3rem',
}}>
{row.rrfRank !== undefined && (
<>
<RankBadge label="RRF" rank={row.rrfRank} color="var(--text-secondary)" />
<span style={{ color: 'var(--text-muted)', fontSize: '0.55rem' }}>{'\u2192'}</span>
</>
)}
{row.rerankRank !== undefined && (
<>
<RankBadge label="Reranker" rank={row.rerankRank} color="#f57f17" />
<span style={{ color: 'var(--text-muted)', fontSize: '0.55rem' }}>{'\u2192'}</span>
</>
)}
{row.finalRank !== undefined ? (
<RankBadge label="Final" rank={row.finalRank} color="#1b5e20" />
) : (
<span style={{
fontSize: '0.55rem',
color: 'var(--text-muted)',
fontStyle: 'italic',
}}>
blending...
</span>
)}
</div>
</div>
);
})}
<div style={{
fontSize: '0.62rem',
fontFamily: 'system-ui, -apple-system, sans-serif',
color: 'var(--text-muted)',
marginTop: '0.3rem',
fontStyle: 'italic',
lineHeight: 1.4,
}}>
Final ranking blends reranker scores with retrieval position.
</div>
</div>
);
}
export default function FusionColumn({ state, accent, info }: FusionColumnProps) {
const rrfDone = state.rrf.status === 'done';
const rerankRunning = state.rerank.status === 'running';
const rerankDone = state.rerank.status === 'done';
const isIdle = !rrfDone && !rerankRunning && !rerankDone;
return (
<div style={{ opacity: isIdle ? 0.45 : 1, transition: 'opacity 0.3s' }}>
<div style={{
display: 'flex',
alignItems: 'center',
gap: '0.4rem',
marginBottom: '0.75rem',
paddingBottom: '0.5rem',
borderBottom: '1px solid var(--stage-divider)',
}}>
<span style={{
width: '3px',
height: '14px',
borderRadius: '2px',
background: accent,
flexShrink: 0,
}} />
<h3 style={{
margin: 0,
fontSize: '0.78rem',
fontFamily: 'system-ui, -apple-system, sans-serif',
fontWeight: 700,
color: accent,
textTransform: 'uppercase',
letterSpacing: '0.05em',
}}>
Fusion & Reranking
</h3>
{rerankRunning && <Spinner color={accent} />}
<InfoTooltip text={info} />
</div>
{isIdle && (
<p style={{ fontFamily: 'system-ui, -apple-system, sans-serif', fontSize: '0.75rem', color: 'var(--text-muted)', margin: 0 }}>
Awaiting search...
</p>
)}
{rrfDone && state.rrf.data && (
<div style={{ marginBottom: '0.7rem' }}>
<SectionHeader
label="RRF Fusion"
color="#558b2f"
badge={`(${state.rrf.data.merged.length} docs)`}
/>
{state.rrf.data.merged.slice(0, 5).map((r, i) => (
<RRFRow key={r.docId} result={r} rank={i + 1} />
))}
{state.rrf.data.merged.length > 5 && (
<div style={{ fontSize: '0.68rem', color: 'var(--text-muted)', fontFamily: 'system-ui, -apple-system, sans-serif', paddingLeft: '0.25rem' }}>
+{state.rrf.data.merged.length - 5} more
</div>
)}
</div>
)}
{rerankRunning && !rerankDone && (
<p style={{ fontFamily: 'system-ui, -apple-system, sans-serif', fontSize: '0.75rem', color: 'var(--text-secondary)', margin: '0 0 0.6rem 0', fontStyle: 'italic' }}>
Reranking with cross-encoder...
</p>
)}
{rerankDone && state.rerank.data && (
<div>
<SectionHeader label="Rank Journey" color="#33691e" />
<RankJourney
before={state.rerank.data.before}
after={state.rerank.data.after}
finalResults={state.finalResults}
/>
</div>
)}
</div>
);
}
|