The brute-force index·12 min
The full search call
0 / 1
# grade this stage (from your course directory)
npx theinference test --stage search --watchCompose the engine: search(query, corpus, dim, k) = topK(scoreAll(query, corpus, dim), k). One query vector in, k document indices out. This is your entire retrieval core — every later metric just runs this in a loop.
What to build
Your task
Implement search
Implement search(query, corpus, dim, k) in src/index.ts, returning a number[] of k doc indices, by composing the two functions you already wrote.
src/index.ts
export function search(query: Float32Array, corpus: Float32Array, dim: number, k: number): number[] {
return topK(scoreAll(query, corpus, dim), k)
}
How it's graded — integer-exact
adapter with atol=0, rtol=0 — for a fixed query, your top-10 indices must equal the reference (which uses the same well-separated query, so the boundary is stable).
You just built a search engine
A dozen lines of vector math and you can already retrieve. The next two chapters answer the only question that matters in production: is it any good? — and they answer it two different ways.