When evaluating long-context language models, a common stress test is multi-needle retrieval: hide several target strings ("needles") inside a very long input and ask the model to recover all of them. A task is considered fully solved only if every needle is returned; partial recalls are measured by the fraction of needles found.
You are given a set of evaluation tasks across several context-length buckets (e.g., 8K, 32K, 128K, 1M tokens). Each task records:
context_length: integer number of tokens used for the task.expected: list of ground-truth needle strings the model should retrieve.predicted: list of needle strings the model actually returned.For each task, compute the match rate
(using set membership; duplicates in predicted are ignored). Then group tasks into the provided context-length buckets: a task with context length is assigned to the smallest bucket with . Tasks with larger than every bucket are dropped.
For each bucket, return the mean match rate (MMR) across the tasks assigned to it. If a bucket has no tasks, report 0.0 for that bucket.
evaluate_mrcr(tasks, buckets)
tasks: list of dicts, each with keys context_length (int), expected (list[str]), predicted (list[str]).buckets: list of ints, sorted ascending, giving the context-length buckets.Return a list of floats, same length as buckets, where entry is the mean match rate for bucket , rounded to 4 decimals.