SLICE: Semantic Language-Indexed Code Extraction with Backward Slicing for Repository-Scale Code Generation
Abstract
Large language models (LLMs) frequently generate syntactically correct but functionally flawed code when operating at repository scale, with failure rates increasing on cross-file dependencies. Existing retrieval-augmented approaches rely on textual similarity or structural patterns that fail to capture semantic intent. We present SLICE (Semantic Language-Indexed Code Extraction), a novel framework that reduces hallucinations by combining semantic understanding with structural dependency analysis. SLICE constructs knowledge graphs from abstract syntax trees where each node is enriched with natural language descriptions generated via few-shot learning, enabling semantic search that understands code functionality rather than syntax. Crucially, SLICE integrates backward program slicing to automatically retrieve not just relevant code, but also its dependencies, ensuring complete executable context. SLICE was Evaluated on EvoCodeBench across three state-of-the-art models (Claude-3.7-Sonnet, GPT-4.1-mini, DeepSeek-V3), achieving Pass@1 scores of 14.54\%, 14.90\%, and 15.63\% respectively—representing 48-67\% improvements over no-retrieval baselines and 32-48\% over BM25. Compared to GraphCoder, the state-of-the-art graph-based retriever, SLICE delivers consistent 3-4 percentage point absolute gains. These improvements demonstrate that combining semantic descriptions with dependency-aware retrieval is essential for reliable repository-level code generation.