Sense and Sensitivity: Examining the Influence of Semantic Recall on Long Context Code Understanding

· Source: cs.SE updates on arXiv.org · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Expert, extended

Summary

A study investigated Large Language Model (LLM) reasoning over code within large repositories, distinguishing between lexical (verbatim) and semantic (functional understanding) code recall. Researchers introduced SemTrace, a novel technique to isolate and measure semantic code recall, and a method to quantify semantic recall sensitivity in existing benchmarks. Evaluating 10 state-of-the-art LLMs, including GPT 4.1 and open-source models up to 236B parameters, revealed a significant "lost-in-the-middle" effect in code reasoning. Accuracy on SemTrace plummeted up to 94.07% for top models when relevant code was mid-context. Lexical recall showed models excel at function retrieval but struggle with line-by-line recall. A disconnect between lexical and semantic recall was observed, implying distinct underlying mechanisms. Current code reasoning benchmarks, like CruxEval, exhibited low semantic recall sensitivity, potentially underestimating LLM challenges in leveraging in-context information. GPT 4.1's near-perfect SemTrace performance on 2-3 digit tasks degraded significantly on 4-6 digit tasks, showing a re-emerging LIM effect.

Key takeaway

For AI Engineers deploying LLMs for complex code reasoning or debugging in large repositories, you must account for the "lost-in-the-middle" effect and the distinction between lexical and semantic recall. Current LLMs, including GPT 4.1, show significant degradation in semantic understanding for mid-context code, even with large context windows. You should rigorously evaluate models using high semantic recall sensitivity benchmarks like SemTrace and consider strategies to ensure critical code snippets are not buried in the middle of long prompts to avoid substantial accuracy drops.

Key insights

LLMs exhibit a "lost-in-the-middle" effect for semantic code recall, hindering long-context code reasoning.

Principles

Method

SemTrace isolates semantic code recall using randomized, independent assignment statements. Semantic recall sensitivity is measured by performance degradation on intentionally incomplete code.

In practice

Topics

Best for: Research Scientist, AI Scientist, Machine Learning Engineer, AI Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by cs.SE updates on arXiv.org.