Manuscript Offprint

arXiv:2610.39519

Lost in the Latent Space: How Code Embeddings Represent Functional Intent and Implementation Fidelity

Lu Sun, Yuheng Huang, Lei Ma, Zhijie Wang

Lu Sun*, Yuheng Huang*✉, Lei Ma*†, Zhijie Wang‡

  • The University of Tokyo, Tokyo, Japan † University of Alberta, Edmonton, AB, Canada

‡ Concordia University, Montreal, QC, Canada

{7779117185, yuhenghuang42}@g.ecc.u-tokyo.ac.jp, ma.lei@acm.org, zhijie.wang@concordia.ca

Abstract—Code embedding models have become a key building block for many software engineering applications, yet their internal representations remain poorly understood. Existing evaluations tend to focus on downstream task performance, offering limited insight into whether a single embedding can support both functional abstraction and implementation-sensitive analysis. To address this gap, we present a large-scale empirical study of 14 state-of-the-art code embedding models. We evaluate their representational behavior through three complementary analyses: supervised probing for functional abstraction and implementation fidelity, zero-shot retrieval experiments to assess geometric similarity, and controlled perturbation experiments that measure embedding responses to semantics-preserving code transformations. The results reveal a consistent abstraction-fidelity tension: models that better preserve stylistic and structural signals tend to do so at the expense of semantic generalization, while models with similar retrieval performance can nevertheless respond very differently to the same implementation changes. Overall, our findings suggest that a single universal code representation remains out of reach, motivating more representation-aware evaluation, selection, and deployment of code embedding models in software engineering.

Index Terms—Code Embedding Models, Representation Learning, Empirical Study

I. INTRODUCTION

Embedding models 1^{1} have become a fundamental component of many Software Engineering (SE) approaches for comparing, retrieving, and prioritizing software artifacts at scale [1]–[6]. By mapping source code, requirements, commits, bug reports, or other artifacts into continuous vector representations, these models enable efficient search and analysis over large software repositories. They have become a core component of many SE tasks, including vulnerability detection [2], [7], [8], clone detection [9], defect prediction [10], code search [11], and impact analysis [12]. In these applications, the quality of the embedding space directly influences which relationships among software artifacts can be identified by downstream classifiers [2], [7], [9], [10], ranking algorithms [3], [13], [14], or human analysts [15]–[17].

Yuheng Huang is the corresponding author

The emergence of Large Language Models (LLMs) did not diminish the need for dedicated embedding models. Although LLMs provide powerful reasoning capabilities over code and natural language, their inference cost, latency, and context limitations make them unsuitable for many downstream or specialized SE tasks that require reasoning over large software repositories or external knowledge sources [13], [14], [18]. Lightweight embedding models thereby complement LLMs by efficiently searching and retrieval [1], [3], [13], [14], downstream prediction and ranking tasks [2], [4], [7], [10], and similarity-based analysis [19]–[22].

Similar to LLMs, embedding models are also intended to be general-purpose so that they can complement LLM-centric systems and be capable of supporting a diverse range of tasks. Rather than being optimized for a single downstream task, they aim to learn a representation space in which similar data points are mapped to nearby vectors while dissimilar ones remain distinguishable. Therefore, the same embedding space can support a wide range of downstream applications. From a deployment perspective, reusing a single embedding model across multiple workflows further reduces computational cost and simplifies system design. These practical benefits have been demonstrated by the success of general-purpose embedding models in natural language processing [23]–[26]. Consequently, recent code-embedding work increasingly embraces this design paradigm by building general-purpose code embedding models, e.g., multi-task retrieval models [27], [28].

However, we argue that existing evidence is insufficient to determine when this reuse assumption is reliable for SE applications. Previous studies assess code embeddings on individual downstream tasks [4], [19], [21], [29], [30], demonstrating task-specific effectiveness while providing only limited insight into whether a single embedding space can simultaneously preserve the diverse forms of software information required across tasks in the LLM era. Intuitively, an embedding is a compressed representation of a software artifact, preserving information useful for one notion of similarity but potentially reducing its ability to represent others. This raises a fundamental question:

1^{1}Throughout this paper, the term embedding model refers to a neural network model trained to produce vector representations of data, rather than the embedding layer of a large language model.

To what extent can a single code embedding model serve as a reusable building block for software engineering applications, and how do its representational trade-offs constrain that role?

To answer this core research question, we study code embedding models along two complementary dimensions that capture recurring requirements in SE workflows. The first is high-level functional abstraction: the extent to which an embedding groups artifacts that implement the same requirement, solve the same problem, or exhibit similar algorithmic behavior despite differences in implementation. The second is implementation fidelity: the extent to which a representation faithfully preserves information about how a program is implemented. A high-fidelity representation retains naming conventions, formatting choices, syntactic idioms, structural organization, and other implementation-level regularities. This information is essential for tasks such as predicting compilability from invalid code, identifying implementation conventions, analyzing provenance, and reasoning about project-specific development patterns.

We evaluate these dimensions through three diverse analyses. First, we conduct lightweight probing experiments on frozen embeddings to determine whether functional and implementation-level information can be recovered from the learned representations. Second, we evaluate retrieval behavior directly, since many practical applications rely on the embedding geometry space's neighborhood structure rather than a trained downstream classifier. Finally, we conduct a controlled perturbation analysis to explain the geometry behind these differences. We apply semantics-preserving code transformations as counterfactual interventions, each modifying a specific implementation characteristic while preserving the program's intended behavior. By measuring embedding displacements under these controlled transformations, we characterize each model's invariance profile, identifying which implementation variations are treated as irrelevant and which remain geometrically distinguishable. Collectively, these analyses provide a systematic characterization of the trade-offs embodied by modern code embedding models and offer practical guidance for selecting embedding models for different SE applications.

In summary, our contributions are as follows:

• A Representation-Aware Evaluation Framework: We introduce a systematic evaluation suite comprising four distinct sub-tasks across multiple programming languages. This benchmark is explicitly designed to isolate and evaluate the models through two operational axes: functional intent abstraction and form-level fidelity.

• A Large-Scale Empirical Study: We conduct a systematic evaluation of 14 SOTA embedding models, spanning both general-purpose and code-specific approaches. Our analysis provides insight into their representational preferences and abstraction behaviors, and reveals a consistent trade-off between stylistic fidelity and semantic abstraction.

• A Semantic-Preserving Perturbation Study: We design an unsupervised perturbation study using functionality-preserving code transformations to examine the models' underlying invariance behavior. By tracking the resulting geometric shifts, we identify which forms of local implementation variation are absorbed by the representation and which are preserved as distinct geometric signals.

To support future research, we make our code and datasets, including our independently collected AtCoder corpus, publicly available at Anonymous Git [31]. The repository also provides preliminary results on CodeSearchNet [3] and BigCloneBench [32], together with additional uncertainty and robustness analyses of the observed correlations.

References (64)