Build your own RAG pipeline
The answer-span oracle·20 min

Rewrite & re-measure

0 / 1
# grade this stage (from your course directory)
npx theinference test --stage rewrite-recall --watch

Implement the deterministic rewrite and re-measure. Embed the rewritten queries, recompute recall@5, and confirm it does not drop versus the raw question — the honest, measurable version of "does rewriting help?"

What to build

Your task

Implement rewriteQuery

Implement rewriteQuery(question): normalize, strip punctuation, drop stopwords (the shipped stopword list), and join the remaining content words with single spaces. The rewrite-recall <k> command retrieves with both the raw and rewritten queries and prints {rawRecall, rewrittenRecall}.

src/retrieve.ts
export function rewriteQuery(question: string): string {
  // normalize -> strip non-alphanumeric -> split on spaces
  // -> drop STOPWORDS and empties -> join with " "
}
How the grader runs it
./your_program.sh rewrite-recall 5
# -> { rawRecall, rewrittenRecall }   (rewritten >= raw)
How it's graded

process mode, stdout_json_match. Both recall numbers must match the frozen reference exactly. The rewritten-query recall must not regress below the raw-query recall — that's the measurable claim.

Determinism is the contract

Your rewriteQuery must produce the exact reference string (the stopword list and normalization are shipped) so its embedding matches. A free-form rewrite would be ungradeable — that's the whole reason we don't use an LLM here.