-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval-harness.ts
More file actions
223 lines (205 loc) · 6.22 KB
/
Copy patheval-harness.ts
File metadata and controls
223 lines (205 loc) · 6.22 KB
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
/**
* Evaluation Harness for QMD Search
*
* Tests search quality with synthetic queries against known documents.
* Run: bun test/eval-harness.ts
*/
import { execSync } from "child_process";
// Test queries with expected documents and difficulty
const evalQueries: {
query: string;
expectedDoc: string; // Partial match on filename
difficulty: "easy" | "medium" | "hard";
description: string;
}[] = [
// EASY: Exact keyword matches
{
query: "API versioning",
expectedDoc: "api-design",
difficulty: "easy",
description: "Direct keyword match"
},
{
query: "Series A fundraising",
expectedDoc: "fundraising",
difficulty: "easy",
description: "Direct keyword match"
},
{
query: "CAP theorem",
expectedDoc: "distributed-systems",
difficulty: "easy",
description: "Direct keyword match"
},
{
query: "overfitting machine learning",
expectedDoc: "machine-learning",
difficulty: "easy",
description: "Direct keyword match"
},
{
query: "remote work VPN",
expectedDoc: "remote-work",
difficulty: "easy",
description: "Direct keyword match"
},
{
query: "Project Phoenix retrospective",
expectedDoc: "product-launch",
difficulty: "easy",
description: "Direct keyword match"
},
// MEDIUM: Semantic/conceptual queries
{
query: "how to structure REST endpoints",
expectedDoc: "api-design",
difficulty: "medium",
description: "Conceptual - no exact match"
},
{
query: "raising money for startup",
expectedDoc: "fundraising",
difficulty: "medium",
description: "Conceptual - synonyms"
},
{
query: "consistency vs availability tradeoffs",
expectedDoc: "distributed-systems",
difficulty: "medium",
description: "Conceptual understanding"
},
{
query: "how to prevent models from memorizing data",
expectedDoc: "machine-learning",
difficulty: "medium",
description: "Conceptual - overfitting"
},
{
query: "working from home guidelines",
expectedDoc: "remote-work",
difficulty: "medium",
description: "Synonym match"
},
{
query: "what went wrong with the launch",
expectedDoc: "product-launch",
difficulty: "medium",
description: "Conceptual query"
},
// HARD: Vague, partial memory, indirect
{
query: "nouns not verbs",
expectedDoc: "api-design",
difficulty: "hard",
description: "Partial phrase recall"
},
{
query: "Sequoia investor pitch",
expectedDoc: "fundraising",
difficulty: "hard",
description: "Indirect reference"
},
{
query: "Raft algorithm leader election",
expectedDoc: "distributed-systems",
difficulty: "hard",
description: "Specific detail in long doc"
},
{
query: "F1 score precision recall",
expectedDoc: "machine-learning",
difficulty: "hard",
description: "Technical detail"
},
{
query: "quarterly team gathering travel",
expectedDoc: "remote-work",
difficulty: "hard",
description: "Specific policy detail"
},
{
query: "beta program 47 bugs",
expectedDoc: "product-launch",
difficulty: "hard",
description: "Specific number recall"
},
];
interface SearchResult {
file: string;
score: number;
title: string;
}
function runSearch(query: string): SearchResult[] {
try {
const output = execSync(
`bun src/cli/qmd.ts search "${query.replace(/"/g, '\\"')}" --json -n 5 2>/dev/null`,
{ encoding: "utf-8", timeout: 30000 }
);
return JSON.parse(output);
} catch (e) {
return [];
}
}
function runQuery(query: string): SearchResult[] {
try {
const output = execSync(
`bun src/cli/qmd.ts query "${query.replace(/"/g, '\\"')}" --json -n 5 2>/dev/null`,
{ encoding: "utf-8", timeout: 60000 }
);
return JSON.parse(output);
} catch (e) {
return [];
}
}
function evaluate(mode: "search" | "query") {
const runFn = mode === "search" ? runSearch : runQuery;
const results = {
easy: { total: 0, hit1: 0, hit3: 0, hit5: 0 },
medium: { total: 0, hit1: 0, hit3: 0, hit5: 0 },
hard: { total: 0, hit1: 0, hit3: 0, hit5: 0 },
};
console.log(`\n=== Evaluating ${mode.toUpperCase()} mode ===\n`);
for (const { query, expectedDoc, difficulty, description } of evalQueries) {
const searchResults = runFn(query);
const ranks = searchResults
.map((r, i) => ({ rank: i + 1, matches: r.file.toLowerCase().includes(expectedDoc) }))
.filter(r => r.matches);
const firstHit = ranks.length > 0 ? ranks[0]!.rank : -1;
results[difficulty].total++;
if (firstHit === 1) results[difficulty].hit1++;
if (firstHit >= 1 && firstHit <= 3) results[difficulty].hit3++;
if (firstHit >= 1 && firstHit <= 5) results[difficulty].hit5++;
const status = firstHit === 1 ? "✓" : firstHit > 0 ? `@${firstHit}` : "✗";
console.log(`[${difficulty.padEnd(6)}] ${status.padEnd(3)} "${query}" → ${description}`);
}
console.log("\n--- Summary ---");
for (const [diff, r] of Object.entries(results)) {
const hit1Pct = ((r.hit1 / r.total) * 100).toFixed(0);
const hit3Pct = ((r.hit3 / r.total) * 100).toFixed(0);
const hit5Pct = ((r.hit5 / r.total) * 100).toFixed(0);
console.log(`${diff.padEnd(8)}: Hit@1=${hit1Pct}% Hit@3=${hit3Pct}% Hit@5=${hit5Pct}% (n=${r.total})`);
}
const total = evalQueries.length;
const totalHit1 = Object.values(results).reduce((a, r) => a + r.hit1, 0);
const totalHit3 = Object.values(results).reduce((a, r) => a + r.hit3, 0);
console.log(`\nOverall: Hit@1=${((totalHit1/total)*100).toFixed(0)}% Hit@3=${((totalHit3/total)*100).toFixed(0)}%`);
}
// Main
console.log("QMD Evaluation Harness");
console.log("=".repeat(50));
console.log(`Testing ${evalQueries.length} queries across 6 documents`);
// Check if eval-docs collection exists
try {
const status = execSync("bun src/cli/qmd.ts status --json 2>/dev/null", { encoding: "utf-8" });
if (!status.includes("eval-docs")) {
console.log("\n⚠️ eval-docs collection not found. Run:");
console.log(" qmd collection add test/eval-docs --name eval-docs");
console.log(" qmd embed");
process.exit(1);
}
} catch {
console.log("\n⚠️ Could not check status. Make sure qmd is working.");
}
// Run evaluations
evaluate("search");
evaluate("query");