TL;DR
RepoQA is the first benchmark designed specifically to test long-context code understanding in Large Language Models (LLMs). By asking models to find a target function in a 16k-token codebase given only a high-level natural language description, it moves beyond simple keyword matching and synthetic retrieval. Evaluating 33 models reveals that while proprietary models lead, top open-weights models are close behind—and surprisingly, removing code comments actually helps most models understand code better.
What Problem Does This Paper Address?
Context windows in LLMs have exploded to tens or hundreds of thousands of tokens. To measure long-context retrieval, researchers often rely on synthetic tests like "Needle in a Haystack" (NIAH), where an LLM retrieves a specific sentence placed inside a sea of text.
However, NIAH only tests shallow surface-level matching rather than deep semantic comprehension. In software engineering, code benchmarks like RepoBench or SWE-bench focus either on short-context code generation or full-blown agentic problem-solving. There was no dedicated, standardized way to measure whether an LLM can actually read, navigate, and comprehend an entire long-context code repository.
Methods
The authors introduce the Searching Needle Function (SNF) task:
- Task Prompt: An LLM is given an instruction, a 16k-token code context, a structured functional specification, and a repeated instruction reminder.
- Specification without Spoilers: Using GPT-4-Turbo, the benchmark generates a 4-part description (purpose, input, output, procedure) for a target function. Crucially, the prompt forbids naming the function or its variables to prevent the LLM from cheating via keyword search.
- Evaluation Pipeline: The retrieved code block is extracted, validated for syntax using Tree-sitter, and matched against all candidate functions in the context using a smoothed BLEU score. A retrieval is marked successful only if the target needle is both the closest candidate and clears a strict BLEU similarity threshold ($\ge 0.8$).
[System Instruction]
↓
[16k-token Codebase Context] ← (Target needle function placed at 10%–100% depth)
↓
[Natural Language Spec] ← (No function/variable names allowed)
↓
[Repeated Instruction] → Model Output → Tree-sitter + BLEU Match vs. Target
Datasets
The authors introduce the RepoQA benchmark:
- Scope: 500 code search tasks constructed from 50 popular GitHub repositories ($\ge 100$ stars) across five languages: Python, C++, Java, TypeScript, and Rust (10 repos each).
- Setup: Source files are topologically sorted by dependency order and chunked to sample 10 evenly distributed needle functions across depths ranging from 10% to 100%.
- Unlike synthetic benchmarks (NIAH, RULER) or agent-heavy benchmarks (SWE-bench), RepoQA relies on real-world multi-file repositories specifically prepared for direct long-context evaluation.
Key Insights and Ideas
- Code comments can hurt performance: Counterintuitively, stripping natural language comments improved retrieval accuracy for almost every model (e.g., GPT-4-Turbo jumped from 76.4% to 92.6%). LLMs comprehend programmatic logic more effectively when not distracted by potentially noisy or redundant natural-language commentary.
- Language popularity shapes accuracy: Models consistently scored highest in Java and TypeScript, followed by Python, C++, and Rust. This mirrors pretraining data volume (e.g., in The Stack v2), showing that code comprehension correlates strongly with language representation in training corpora.
- Llama 3 is secretly a long-context model: Despite an official 8k training context, Meta-Llama-3-70B-Instruct achieved 82.2% accuracy on the 16k task using simple, training-free dynamic RoPE scaling.
Key Results
The authors evaluated 33 LLMs on RepoQA with a 16k context window:
- Proprietary Leaders: Claude-3-Opus, Gemini-1.5-Pro, and GPT-4o tied for the top spot at 90.6% accuracy, closely followed by Gemini-1.5-Flash at 90.0%.
- Open-Weights Competitiveness: DeepSeek-V2-Chat (83.4%) and Llama-3-70B-Instruct (82.2%) outperformed proprietary alternatives like Claude-3-Haiku (81.8%) and GPT-4-Turbo (76.4%).
- Model Size Matters (Mostly): Larger models generally won within each family, with rare exceptions (CodeLlama-13B scored 42.6%, outperforming CodeLlama-34B at 41.6%).
- Smaller/Base Models Struggle: Smaller models (like Mistral-7B-v0.1 at 11.0% and deepseek-coder-6.7b at 10.6%) degraded significantly under long-context code retrieval.
Limitations and Future Work
- Context Size Limit: The benchmark evaluation focused on a 16k-token window to accommodate most available models, leaving million-token context evaluations for future work.
- Single-Hop Search: SNF requires finding a single function. Future extensions plan to test multi-hop reasoning (e.g., tracing function call graphs or dependencies across files).
- Language Scope: Currently limited to five programming languages; the authors plan to expand to more languages and broader complex task scenarios.
Summary updated