The EmbeddingGemma reports quote two headline numbers, Mean(Task) and Mean(Type), over a benchmark whose retrieval tasks are scored by nDCG@10. Implement the retrieval metric end to end from embeddings and the two aggregations.
retrieval_ndcg(Q, D, qrels, k=10)
Q is (m, d), D is (n, d), qrels[i] is the set of relevant document indices for query i (binary relevance). Rank the documents by cosine similarity (lower index on ties), compute over the ranked list, divide by the ideal DCG with relevant documents at the top, and return the mean over queries rounded to 4 decimals. A query with no relevant documents scores 0.mean_task(results)
results is a list of (task_name, task_type, score). The plain mean of the scores, rounded to 4 decimals.mean_type(results)
truncation_curve(Q, D, qrels, dims, k=10)
dim in dims, keep the first dim coordinates of Q and D (re-normalization is implicit in the cosine) and return the list of (dim, retrieval_ndcg) pairs.np.argsort(-scores, kind="stable") ranks descending with the lower index first.