Build your own semantic search
Is it any good? (qrels, MRR, nDCG)·8 min

IDCG

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

IDCG is the DCG of the ideal ranking — all relevant docs sorted to the very top. It is the largest DCG you could achieve, and it's what you divide by to turn a raw DCG into a 0–1 score (next step). Compute it by sorting the relevance values descending and DCG-ing them.

What to build

Your task

Implement idcgAtK

Implement idcgAtK(rels, k) in src/metrics.ts — rels is the multiset of all relevant docs' relevance values; sort it descending and dcgAtK it.

src/metrics.ts
export function idcgAtK(rels: number[], k: number): number {
  // dcgAtK(rels sorted descending, k)
}
How it's graded

adapter — allclose vs reference on a hand-built relevance list, atol=1e-6. Reuse the dcgAtK you just wrote on the sorted list.

Binary relevance keeps it simple

With binary relevance (every relevant doc has value 1), sorting descending just front-loads all the 1s. So IDCG@k for a query with m relevant docs is Σ_{i=0..min(m,k)-1} 1/log₂(i+2) — the best you could possibly score.