| 3 | export const PASS_THRESHOLD = 0.5; |
| 4 | |
| 5 | export function scoreSearchNodes( |
| 6 | caseId: string, |
| 7 | expectedSymbols: string[], |
| 8 | results: Array<{ node: { name: string }; score: number }>, |
| 9 | latencyMs: number |
| 10 | ): EvalResult { |
| 11 | const expectedLower = expectedSymbols.map((s) => s.toLowerCase()); |
| 12 | const resultNames = results.map((r) => r.node.name.toLowerCase()); |
| 13 | |
| 14 | const found: string[] = []; |
| 15 | const missed: string[] = []; |
| 16 | let firstRank = 0; |
| 17 | |
| 18 | for (let i = 0; i < expectedLower.length; i++) { |
| 19 | const idx = resultNames.indexOf(expectedLower[i]); |
| 20 | if (idx !== -1) { |
| 21 | found.push(expectedSymbols[i]); |
| 22 | if (firstRank === 0) firstRank = idx + 1; |
| 23 | } else { |
| 24 | missed.push(expectedSymbols[i]); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | const recall = expectedSymbols.length > 0 ? found.length / expectedSymbols.length : 0; |
| 29 | const mrr = firstRank > 0 ? 1 / firstRank : 0; |
| 30 | |
| 31 | return { |
| 32 | caseId, |
| 33 | pass: recall >= PASS_THRESHOLD, |
| 34 | recall, |
| 35 | mrr, |
| 36 | foundSymbols: found, |
| 37 | missedSymbols: missed, |
| 38 | latencyMs, |
| 39 | }; |
| 40 | } |
| 41 | |
| 42 | export function scoreFindRelevantContext( |
| 43 | caseId: string, |