()
| 31 | console.log(''); |
| 32 | |
| 33 | async function run() { |
| 34 | const cg = CodeGraph.openSync(resolvedPath); |
| 35 | const results: EvalResult[] = []; |
| 36 | |
| 37 | for (const tc of testCases) { |
| 38 | const start = performance.now(); |
| 39 | |
| 40 | if (tc.api === 'searchNodes') { |
| 41 | const searchResults = cg.searchNodes(tc.query, { |
| 42 | limit: 10, |
| 43 | kinds: tc.kinds, |
| 44 | ...(tc.options as Record<string, unknown>), |
| 45 | }); |
| 46 | const latency = performance.now() - start; |
| 47 | const result = scoreSearchNodes(tc.id, tc.expectedSymbols, searchResults, latency); |
| 48 | results.push(result); |
| 49 | } else { |
| 50 | const subgraph = await cg.findRelevantContext(tc.query, { |
| 51 | searchLimit: 8, |
| 52 | traversalDepth: 3, |
| 53 | maxNodes: 80, |
| 54 | minScore: 0.2, |
| 55 | ...(tc.options as Record<string, unknown>), |
| 56 | }); |
| 57 | const latency = performance.now() - start; |
| 58 | const result = scoreFindRelevantContext(tc.id, tc.expectedSymbols, subgraph, latency); |
| 59 | results.push(result); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | cg.close(); |
| 64 | |
| 65 | // Print results table |
| 66 | const maxIdLen = Math.max(...results.map((r) => r.caseId.length)); |
| 67 | |
| 68 | for (const r of results) { |
| 69 | const status = r.pass ? '\x1b[32mPASS\x1b[0m' : '\x1b[31mFAIL\x1b[0m'; |
| 70 | const id = r.caseId.padEnd(maxIdLen); |
| 71 | const recall = `recall=${r.recall.toFixed(2)}`; |
| 72 | const extra = |
| 73 | r.edgeDensity !== undefined |
| 74 | ? `density=${r.edgeDensity.toFixed(2)}` |
| 75 | : `mrr=${r.mrr.toFixed(2)}`; |
| 76 | const latency = `${Math.round(r.latencyMs)}ms`; |
| 77 | |
| 78 | console.log(` ${id} ${status} ${recall} ${extra} ${latency}`); |
| 79 | |
| 80 | if (r.missedSymbols.length > 0) { |
| 81 | console.log(` ${' '.repeat(maxIdLen)} missed: ${r.missedSymbols.join(', ')}`); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Summary |
| 86 | const passed = results.filter((r) => r.pass).length; |
| 87 | const failed = results.length - passed; |
| 88 | const meanRecall = results.reduce((s, r) => s + r.recall, 0) / results.length; |
| 89 | const mrrResults = results.filter((r) => r.mrr > 0 || r.caseId.startsWith('search-')); |
| 90 | const meanMRR = |
no test coverage detected