A code retrieval method and device for AI programming and related equipment

By constructing a two-layer embedding vector model and optimizing the parameters of the lightweight adaptation layer using user interaction feedback, the problems of low accuracy and high cross-domain adaptation costs in existing code retrieval systems in professional scenarios are solved, realizing a low-cost, flexible code retrieval model that is adaptive and continuously evolving.

CN121502362BActive Publication Date: 2026-07-07KEDA ZHILING (BEIJING) TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
KEDA ZHILING (BEIJING) TECHNOLOGY CO LTD
Filing Date
2025-12-11
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

Existing code retrieval systems have low accuracy in professional scenarios, cannot utilize user interaction feedback for self-optimization, and traditional fine-tuning methods are costly and time-consuming, making it difficult to adapt to the rapid evolution of code repositories. Furthermore, they are prone to forgetting old knowledge when applied across different domains.

Method used

A two-layer embedding vector model is constructed, including a basic semantic encoding layer with frozen parameters and multiple independent lightweight adaptation layers. Implicit feedback data generated by user interaction is monitored, positive and negative samples are extracted through preset rules, the parameters of the lightweight adaptation layers are optimized using a contrastive loss function, and elastic weight constraints are applied to achieve self-optimization and cross-domain adaptation of the model.

Benefits of technology

It enables code retrieval that retains old knowledge and adapts to new domains under low cost and flexibility, improves the accuracy and adaptability of the model in professional scenarios, solves the problems of high cost and easy forgetting in cross-domain adaptation in existing technologies, and realizes the zero-label continuous self-evolution of the code retrieval model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121502362B_ABST
    Figure CN121502362B_ABST
Patent Text Reader

Abstract

The application provides a code retrieval method and device for AI programming and related equipment. A double-layer embedding vector model is constructed, including a parameter frozen basic semantic coding layer and a plurality of independent lightweight adaptive layers coexisting. Implicit feedback data generated by user interaction in the target code library is monitored to extract positive and negative sample pairs, and difficult negative samples are mined based on the current model to form a training sample set. When the cumulative number of samples reaches a preset trigger threshold, at least one lightweight adaptive layer parameter is updated and optimized using a preset contrast loss function, and an elastic weight constraint is applied to the key parameter to obtain an updated double-layer embedding vector model. The updated model is subjected to multidimensional performance evaluation, and when the evaluation result meets the preset release condition, the model is deployed to the code retrieval service. The problems of difficulty in cross-domain adaptation, high adaptation cost and easy catastrophic forgetting in the prior art are effectively solved, and zero-labeled self-evolution of the model is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a code retrieval method, apparatus and related equipment for AI programming. Background Technology

[0002] As software development expands in scale, code retrieval has become a core part of developers' work.

[0003] Existing mainstream code retrieval systems (such as GitHub Copilot and Sourcegraph) primarily rely on general-purpose pre-trained code understanding models for interactive retrieval. However, these general-purpose models use fixed weights and lack specific semantic knowledge about projects or industries (such as finance and healthcare), leading to decreased accuracy in professional code retrieval scenarios. Furthermore, existing models are mostly statically deployed and cannot leverage natural user interactions (such as clicking, copying, and skipping) during the search process for self-optimization, resulting in a significant waste of implicit user feedback signals. Traditional offline fine-tuning methods require large amounts of manually labeled data and expensive GPU computing power, and are time-consuming, making them ill-suited to the rapid evolution of codebases. Moreover, when performing full-parameter fine-tuning for new domains, these traditional code understanding models often forget knowledge from older domains, resulting in the same fine-tuned model providing code retrieval services for multiple domains.

[0004] In view of this, the industry urgently needs a code retrieval technology that can effectively retain old knowledge when adapting to new fields, so as to efficiently support AI programming. Summary of the Invention

[0005] In view of this, embodiments of this application provide a code retrieval method, apparatus, and related equipment for AI programming, to at least partially or completely solve the above-mentioned problems.

[0006] In a first aspect, embodiments of this application provide a code retrieval method for AI programming, including:

[0007] Construct a two-layer embedding vector model; wherein the two-layer embedding vector model includes a basic semantic encoding layer with parameter freezing, and multiple independent lightweight adaptation layers coexisting, each lightweight adaptation layer corresponding to a different code domain or tenant;

[0008] The implicit feedback data generated by user interaction with the target code library is monitored, and positive and negative sample pairs are extracted based on preset heuristic rules. Difficult negative samples are mined based on the current model. A training sample set is then formed based on the positive and negative sample pairs and the difficult negative samples. The current model is the constructed two-layer embedding vector model or the deployed two-layer embedding vector model.

[0009] When the cumulative number of samples in the training sample set reaches a preset trigger threshold, based on the training sample set, at least one lightweight adaptation layer parameter of the multiple lightweight adaptation layers is optimized and updated using a preset contrastive loss function, and elastic weight constraints are applied to the key parameters to obtain the updated two-layer embedding vector model.

[0010] The updated two-layer embedding vector model is evaluated in multiple dimensions. When the evaluation results meet the preset release conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to the code retrieval service to support users in code retrieval.

[0011] Secondly, based on the code retrieval method for AI programming described in the first aspect of this application, embodiments of this application also provide an apparatus for code retrieval in AI programming, comprising:

[0012] A two-layer embedding module is used to construct a two-layer embedding vector model; wherein, the two-layer embedding vector model includes a parameter-frozen basic semantic encoding layer and multiple independent lightweight adaptation layers coexisting.

[0013] The feedback acquisition module is used to monitor implicit feedback data generated by user interaction with the target code library, and extract positive and negative sample pairs based on preset heuristic rules, and mine difficult negative samples based on the current model; thereby forming a training sample set based on the positive and negative sample pairs and the difficult negative samples; wherein, the current model is the constructed two-layer embedding vector model or the deployed two-layer embedding vector model;

[0014] The optimization and update module is used to optimize and update at least one lightweight adaptation layer parameter of the multiple lightweight adaptation layers based on the training sample set when the cumulative number of samples in the training sample set reaches a preset trigger threshold, and to apply elastic weight constraints to the key parameters to obtain the updated embedding vector model.

[0015] The self-verification module is used to perform multi-dimensional performance evaluation on the updated two-layer embedding vector model. When it is determined that the evaluation result meets the preset release conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to the code retrieval service to support users in code retrieval.

[0016] Thirdly, embodiments of this application also provide a computer storage medium storing computer-executable instructions, which, when executed, perform any of the code retrieval methods for AI programming as described in the first aspect of embodiments of this application.

[0017] Fourthly, embodiments of this application also provide an electronic device, including: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus;

[0018] The memory is used to store at least one executable instruction that causes the processor to execute any of the code retrieval methods for AI programming as described in the first aspect of the embodiments of this application.

[0019] This application provides a code retrieval method, apparatus, and related equipment for AI programming. It constructs a two-layer embedding vector model, comprising a parameter-frozen basic semantic encoding layer and multiple coexisting independent lightweight adaptation layers, each corresponding to a different code domain or tenant. The method monitors implicit feedback data generated by user interactions with the target code repository and extracts positive and negative sample pairs based on preset heuristic rules. It also mines difficult negative samples based on the current model, which is either the constructed two-layer embedding vector model or a deployed two-layer embedding vector model. A training sample set is then formed based on the positive and negative sample pairs and the difficult negative samples. When the cumulative number of samples in the training sample set reaches a preset trigger threshold, at least one lightweight adaptation layer parameter is optimized and updated using a preset contrastive loss function based on the training sample set. The solution applies flexible weight constraints to key parameters to obtain an updated embedding vector model. A multi-dimensional performance evaluation is then performed on the updated two-layer embedding vector model. When the evaluation results meet the preset release conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to the code retrieval service to support user code retrieval. This solution establishes a two-layer architecture as its foundation and, through a "freeze the base layer + update the adaptation layer" approach, adjusts and optimizes only the parameters of the adaptation layer to adapt to code retrieval in new domains. The frozen state of the base layer prevents catastrophic forgetting, making the process flexible, controllable, and cost-effective. It effectively solves the technical problems of existing code retrieval models, such as high costs and susceptibility to catastrophic forgetting, and achieves zero-label continuous self-evolution of the code retrieval model. Attached Figure Description

[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings.

[0021] Figure 1A schematic diagram illustrating the workflow of a code retrieval method for AI programming provided in this application embodiment;

[0022] Figure 2 A schematic diagram of a device for code retrieval in AI programming provided in an embodiment of this application;

[0023] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0024] To enable those skilled in the art to better understand the technical solutions in the embodiments of this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art should fall within the protection scope of the embodiments of this application.

[0025] It should be understood that the steps described in the method embodiments of this application may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this application is not limited in this respect.

[0026] This application provides a code retrieval method for AI programming, such as... Figure 1 As shown, Figure 1 This application provides a schematic diagram illustrating the workflow of a code retrieval method for AI programming, including:

[0027] Step S101: Construct a two-layer embedding vector model; wherein the two-layer embedding vector model includes a parameter-frozen basic semantic encoding layer and multiple independent lightweight adapter layers, each lightweight adapter layer corresponding to a different code domain or tenant. This embodiment uses a two-layer embedding vector model composed of a "basic semantic encoding layer" and multiple independent lightweight "Adapter Layers" to encode code blocks and user queries in the target code library, generating high-dimensional code semantic embedding vectors. The basic semantic encoding layer provides general semantic knowledge and is frozen; different lightweight adapter layers are used to carry semantic mappings specific to different domains or tenants, and the updatable adapter layers achieve efficient domain specialization of parameters. In the practical application scenario of this embodiment, for neural network models, their structure determines the efficiency of training and operation. Establishing this two-layer embedding vector model as the hardware / software foundation of this solution is not only a prerequisite for subsequent low-cost updates, but also provides efficient and differentiable semantic representations for subsequent continuous learning. Furthermore, this method aims to obtain a dynamically optimized model capable of generating high-precision embedding vectors. This reduces the computational resource requirements for training and deployment, and enables the separation of general knowledge from specialized knowledge.

[0028] Specifically, in an optional implementation of this application embodiment, the method further includes: setting the basic semantic encoding layer to use a pre-trained CodeBERT model. CodeBERT is a model based on the Transformer architecture, pre-trained on a large-scale codebase, capable of generating code semantic vectors such as 768-dimensional vectors. In the practical application of this embodiment, a large-scale pre-trained CodeBERT model is used as the foundation, responsible for general code syntax and semantic understanding. Throughout the entire update lifecycle, these parameters are frozen, i.e., they do not accept gradient updates. This is equivalent to preserving the parameters of the model's general common sense layer, which are completely frozen and do not participate in gradient updates during subsequent model parameter training and optimization, in order to retain general multilingual code understanding capabilities and prevent catastrophic forgetting. Each lightweight adaptation layer adopts a parameter efficient fine-tuning (PEFT) structure, and each lightweight adaptation layer is embedded between the Transformer layers of the basic semantic encoding layer using a bottleneck structure, and its trainable parameter count is configured to be less than a preset proportion of the total number of parameters in the entire two-layer vector model architecture. The lightweight adaptor layer is configured as a parameter-efficient fine-tuning structure, inserted between Transformer layers. It comprises a bottleneck structure with dimensionality reduction and expansion mappings, and its trainable parameters represent a very small proportion of the total parameters of the base model. This allows for relatively independent adaptor layer parameters for codebases in different knowledge domains (e.g., front-end projects, back-end payment systems), achieving knowledge isolation in a user-friendly manner. In this embodiment, the lightweight adaptor layer is typically inserted between each or a specific layer of the base semantic encoding layer (Transformer block). Its core structure is the bottleneck mapping: it first reduces the dimensionality of high-dimensional features (e.g., from 768 dimensions to 64 dimensions), and then expands them back to the original dimensions. Because only a small number of dimensionality reduction (Wdown) and expansion (Wup) matrices are trained, its trainable parameters are extremely small, typically only about 0.3% of the total parameters of the base model. These parameters are active and specifically designed to capture the unique knowledge and logical patterns of a specific project or domain. This design significantly reduces the computational overhead of training and deployment, enabling rapid model iteration on low- to mid-range hardware and facilitating parallel training across multiple domains. Furthermore, this step restricts continuous learning to small batches and noise-based feedback, making training stability crucial. An adaptive learning rate optimizer is used in conjunction with a gradient clipping strategy. Gradient clipping restricts the norm of the gradient vector, effectively preventing gradient explosion that could lead to destructive updates of model parameters when dealing with outliers or noisy data, thus ensuring stable convergence and controllability of the training process.

[0029] Step S102: Monitor the implicit feedback data generated by the user's interaction with the target code library, extract positive and negative sample pairs based on preset heuristic rules, and mine difficult negative samples based on the current model; thereby forming a training sample set based on the positive and negative sample pairs and the difficult negative samples, wherein the current model is the constructed two-layer embedding vector model or the deployed two-layer embedding vector model. In the actual application scenario of this application embodiment, the training sample set is usually composed of positive sample pairs reflecting the query operation of the user retrieving the required code and negative sample pairs reflecting the query operation of the user failing to retrieve the required code, so as to enable the model to be trained and optimized quickly. In this application embodiment, the interaction behavior generated by the user's interaction with the target code library can be obtained, and positive and negative sample pairs can be constructed based on the interaction behavior to form the training sample set. This application embodiment uses interactive behaviors generated from interactions with the target code library, such as natural user interactions during code retrieval, as a measure of true relevance. These are then transformed into positive and negative sample pairs required for comparative learning during model updates. This solves the problem of model updates relying on costly manual annotation, achieving continuous self-learning capability with zero annotation. It intuitively, easily, and accurately enables subsequent dynamic optimization of the model, resulting in an optimized model with high adaptability to scene evolution.

[0030] Specifically, in an optional implementation of this application embodiment, the step of monitoring implicit feedback data generated by user interaction with the target code library and extracting positive and negative sample pairs based on preset heuristic rules includes: monitoring user actions on the search result list retrieved from the target code library; when it is detected that the user performs a copy operation on a specific code snippet, or clicks to enter the details page and stays for more than a preset time, marking the retrieved query statement and the corresponding specific code snippet as a positive sample pair; when it is detected that the user quickly skips or does not click on the code snippets in the search results, marking the corresponding code snippets as ordinary negative samples; establishing the association between the query statement and the marked positive sample pairs and the ordinary negative samples through the operation behavior, forming the positive and negative sample pairs. This step in this application embodiment transforms abstract implicit feedback data into quantifiable and operable training signals. This ensures the extraction of highly representative, low-noise supervision signals from high-noise implicit feedback and constructs zero-labeled training samples, thereby continuously improving the quality of continuous learning samples. For example, if a user copies the code from the result R retrieved for query Q, or if the time T spent on R exceeds a preset threshold τdwell (e.g., set to 10 seconds), then the pair (Q, R) is determined to be a highly relevant positive sample pair (Q, R+). However, if the user quickly skips result R (i.e., the time T spent on R is less than the preset threshold τskip (e.g., set to 1 second), or if the result is recalled but the user does not click on it and quickly browses the search results list, then the pair (Q, R) can be determined to be a low-relevance ordinary negative sample pair (Q, R). ).

[0031] Furthermore, in the process of forming the training sample set, the method may further include: obtaining the similarity between the current query statement and each candidate code segment (i.e., positive sample pair) in the target code library in the embedding semantic space of the current model; sorting the candidate code segments according to the similarity results; and selecting code segments with similarity higher than a preset similarity threshold but judged as irrelevant based on implicit feedback data from the sorting results as the hard negative samples (HNM). In this embodiment, hard negative samples are samples that are semantically close but actually unrelated in the embedding space. Using mined hard negative samples to participate in the parameter optimization of the model can solve the problem of insufficient ability of traditional retrieval models to distinguish fine-grained semantic differences. Introducing hard negative samples as part of the training sample data in this step can significantly improve the robustness and accuracy of the model on complex and similar code semantics. In this embodiment, hard negative samples are defined as samples that are very close to query Q in semantic similarity but are actually unrelated in function or logic. Specifically, this can be determined by calculating the cosine similarity between the high-dimensional code semantic embedding vector and the vectors of candidate code blocks in the negative sample pool. The system sorts the samples by similarity and selects candidate samples with similarity higher than a preset similarity threshold σhard (e.g., σhard=0.65). If these high-similarity samples are confirmed to be inconsistent with the Q relation in semantic labels, functional patterns (Playbook), or manual proofreading results, they are included in the hard negative sample set (Rhard) of the training set. This also avoids the training sample set being filled with overly simple negative samples, preventing the model from converging too quickly and thus reducing its discriminative ability.

[0032] Optionally, in one possible implementation of this application embodiment, the preset heuristic rule includes at least: noise filtering and abnormal behavior data removal of the detected implicit feedback data. In the actual application scenario of this application, in order to ensure that the data fed to the model is clean, strict data cleaning rules are first performed when monitoring and collecting implicit feedback data to extract positive and negative sample pairs. The data cleaning rules include at least:

[0033] Abnormal dwell time filtering involves setting an effective reading threshold range [T_{min}, T_{max}] (e.g., 3 seconds to 10 minutes). If a user clicks on a code and only stays for 1 second before closing it, the implicit feedback data is considered to be behavioral data caused by accidental touch, and the sample is discarded. If there is no operation for more than 30 minutes, the behavior is considered to be caused by the user being offline, and the sample is also downgraded or removed.

[0034] Click-to-No-Click Ratio (CTR) Statistical Filtering: For a single period, calculates the ratio of clicks to viewed cards. If a user rapidly flips through pages and clicks on 20 results within 1 minute (extremely high CTR), it can be identified as crawler behavior or blind searching by the user. All data within this time window can be marked as noise data and discarded.

[0035] Noise reduction via time window: For the same query, if a user clicks on three results A, B, and C in sequence, but ultimately copies B, then the "final acceptance principle" can be used. B is marked as a strong positive sample (weight 1.0), while A and C are marked as weak positive samples (weight 0.2) or ignored, thereby eliminating noise in the exploration process.

[0036] By implementing the above data cleaning rules, the positive and negative sample pairs extracted based on the monitored implicit feedback can better reflect the actual situation, so as to promote the convergence of the model parameters to be updated more quickly using a relatively smaller training sample set, thereby improving the efficiency and accuracy of parameter updates.

[0037] Furthermore, in an optional implementation of this application embodiment, when mining difficult negative samples based on the current model, the method further includes: periodically and dynamically refreshing the negative sample pool formed by negative sample pairs, and periodically reconstructing the entire negative sample pool according to model performance or time intervals. In practical application scenarios of this application embodiment, based on changes in model performance, for example, when it is determined that the model has converged or its discriminative ability has decreased, or based on a preset time interval (e.g., monthly), the negative sample pair data in the negative sample pool can be refreshed, or the entire negative sample pool can be periodically reconstructed, thereby ensuring that the negative samples always possess challenge and representativeness.

[0038] Step S103: When the cumulative number of samples in the training sample set reaches a preset trigger threshold, based on the training sample set, the parameters of at least one lightweight adaptation layer of the two-layer embedding vector model are optimized and updated using a preset contrastive loss function, and elastic weight constraints are applied to key parameters to obtain the updated two-layer embedding vector model. In this embodiment, this step limits the continuous monitoring of the cumulative number of these effective positive and negative sample pairs. During the acquisition of the training sample set, the system does not update the model in real time. Instead, when the cumulative number of effective sample pairs reaches the preset trigger threshold (e.g., 1000 high-quality positive and negative sample pairs are accumulated), the system automatically starts the subsequent model optimization process. This trigger-based update closed loop solves the problem of long traditional offline fine-tuning cycles and avoids overfitting to a small amount of noisy data. During the model training and optimization process, the weights of the basic semantic encoding layer are frozen, and only the parameters of the lightweight adaptation layer are updated to generate an updated two-layer embedding vector model. Furthermore, elastic weight constraints are applied to key parameters within this step to limit their offset range relative to the previous optimal weights. This effectively protects the stability of the model's existing domain knowledge in a multi-adaptor coexistence architecture and ensures that the trained and updated two-layer embedding vector model has high adaptability for retrieving specific domain knowledge codes. The training and optimization process is efficient and flexible.

[0039] Specifically, in one optional implementation of this application embodiment, based on the training sample set, the parameters of the adaptation layer of the two-layer embedding vector model are optimized and updated using a preset contrastive loss function to train the two-layer embedding vector model. This includes: constructing a contrastive learning objective using the Information Noise Contrast Estimation (InfoNCE) loss function, and introducing a temperature parameter to scale and adjust the cosine similarity between the query statement and the positive and negative sample vectors, calculating the contrastive loss value of the current batch of training samples to quantify the model's deviation in fine-grained semantic distinction; based on the contrastive loss value, executing a backpropagation algorithm to calculate the gradient information of the parameters of each layer of the two-layer embedding vector model; according to the gradient information, performing weight update operations only on the dimensionality reduction mapping parameters and dimensionality increase mapping parameters in the lightweight adaptation layer, and intercepting gradient updates for the basic semantic encoding layer, so as to maintain the general language model capability while optimizing the domain semantic representation. In this application embodiment, this step limits the contrastive learning framework to control the sharpness of the embedding vector distribution through InfoNCE Loss and the temperature parameter, with the goal of maximizing positive sample similarity and minimizing negative sample similarity, thereby bringing similar samples closer and pushing away dissimilar samples in the vector space. Calculate these similarities and loss values. Update the parameters of the lightweight adaptation layer by optimizing the distribution of high-dimensional code semantic embedding vectors generated by encoding code blocks and user queries in the target codebase using a two-layer embedding vector model. Implement domain semantic specialization of the embedding vector representation. This makes the optimized adaptation layer parameters make the code embeddings more closely match the semantic features of a specific domain or user, thereby significantly enhancing the discriminative power of the updated model.

[0040] Optionally, in one implementation of this application embodiment, applying elastic weight constraints to key parameters includes: calculating the Fisher information matrix of each parameter in at least one lightweight adaptation layer to quantify the importance of each parameter to existing domain knowledge; and employing an elastic weight solidification mechanism (EWC) to add a regularization term to a preset contrastive loss function, penalizing the update magnitude of parameters whose importance is greater than the preset weight, so that while the model learns new domain features, it limits the range of its offset relative to the previous optimal weight, thereby achieving the coexistence and retention of multi-domain knowledge in a single model. To solve the catastrophic forgetting problem, this application embodiment introduces the EWC mechanism in this step. Its core lies in calculating the Fisher information matrix F of the adaptation layer parameters. This Fisher information matrix F quantifies the importance of each parameter to old domain knowledge by measuring the second derivative information of the parameter with respect to the loss function of the previous learning task. Then, the elastic weight solidification mechanism adds the regularization term LEWC to the total loss function to penalize the change of the current parameter relative to the previous optimal parameter. For example, setting LEWC = i∑Fii(θi) θi )2.

[0041] Where Fii is the importance weight value of parameter θi, θi These are the optimal parameters from the last stable deployment; this effectively limits the update range of parameters that are crucial to old knowledge, thus achieving stable knowledge retention.

[0042] Step S104: Perform a multi-dimensional performance evaluation on the updated two-layer embedding vector model. When the evaluation result meets the preset conditions, confirm the updated two-layer embedding vector model as the final model and deploy it to the code retrieval service to support users in code retrieval. In this embodiment, this step is limited to generating a new adaptation layer weight version after the parameters of the two-layer embedding vector model have been updated. To prevent overfitting, a multi-dimensional performance evaluation based on a system multi-way self-verifier is required for the two-layer embedding vector model.

[0043] Furthermore, in an optional implementation of this application embodiment, the method further includes: triggering a rollback mechanism or a retraining mechanism when the result of the multi-dimensional performance evaluation does not meet preset conditions. This involves reverting to the previous validated stable version or triggering a retraining mechanism to perform targeted corrective training using specific failure samples. This mechanism further avoids the risks of overfitting and performance degradation of the model after training updates.

[0044] Specifically, in a preferred implementation of this application, the specific failed sample pairs are used for targeted correction training, including: when a verification failure triggers a rollback, extracting test data that causes the failure to meet preset conditions or a subset of samples that perform poorly in the verification set; marking the subset of samples as "high-difficulty correction samples," mixing them with new implicit feedback data to form a correction dataset; and based on the correction dataset, performing targeted fine-tuning training on the old version of the lightweight adapter after rollback by reducing the learning rate and increasing the weight of the Playbook diversity regularization term until multi-dimensional performance evaluation verification is triggered again. In this embodiment, this step limits the process so that when a verification failure leads to a rollback, the update is not simply discarded. Instead, the reasons why the dimensional performance evaluation results do not meet preset conditions are analyzed and determined, the damaging queries that cause a decrease in MRR are extracted, and then the positive and negative sample pairs corresponding to these damaging queries are marked as high-priority "correction datasets." Then, a replay fine-tuning strategy is employed: training is restarted based on the rolled-back old version adapter. By halving the learning rate and significantly increasing the weight of the Playbook diversity regularization term, the model is forced to jump out of its previous local optimum for replay correction, thereby fixing the performance degradation caused by specific dirty data or over-optimization. In this embodiment, the hard negative sample mining mechanism and the Playbook diversity constraint mechanism are combined, forming a complementary effect. The hard negative sample mechanism focuses on improving the model's ability to discriminate fine-grained semantic differences within the local semantic space; while the diversity constraint mechanism (Playbook) focuses on maintaining the dispersion of embedding vectors by monitoring semantic clustering within the global semantic space. The two work together to prevent excessive collapse of the embedding space, thereby ensuring that the retrieval results are both accurate and structurally diverse.

[0045] Specifically, in one optional implementation of this application embodiment, the multi-dimensional performance evaluation dimensions include at least: semantic consistency verification, retrieval performance evaluation, vector diversity detection, and user acceptance verification. Semantic consistency verification refers to comparing whether the semantic representation of the benchmark test set by the model before and after the update has undergone drastic distortion, ensuring that the general semantic relationships have not been destructively shifted. For example, inputting a benchmark code pair, calculating the correlation coefficient of the semantic similarity matrix before and after the update; if the correlation coefficient is lower than the consistency threshold, it is determined that the semantic structure is broken. This step in this embodiment is an important step in ensuring the reliability of the dynamically optimized model update, providing a quality assurance gate for continuous learning. Retrieval performance evaluation refers to calculating the mean reciprocal rank (MRR) on the validation set to measure retrieval quality, requiring the updated metric to be higher than a preset gain threshold. In practical applications, MRR@10 is usually used; verification is only passed when MRR@10 is improved compared to the baseline model, and the improvement rate exceeds the preset gain threshold; if the MRR metric shows negative growth and the decrease exceeds the tolerance threshold, it is determined that the retrieval quality has degraded. Vector diversity detection involves calculating the Playbook category coverage of the global embedding vectors, or calculating the average information entropy of the embedding vectors, to ensure that context collapse has not occurred. If the information entropy is lower than the collapse threshold, it is considered a risk of context collapse. User acceptance verification involves conducting online A / B testing within a small traffic range to verify the actual click-through rate (CTR) metric. For example, if the CTR is significantly lower than the old version, it is considered a decline in user experience. Correspondingly, when the evaluation results meet the preset conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to the code retrieval service. This includes: when the performance evaluation of each dimension passes, the formal deployment of the updated two-layer embedding vector model is executed. That is, only when all dimensions of the metrics meet the preset thresholds is the model optimization update confirmed as successful and usable, completing a dynamic optimization loop.

[0046] This application embodiment illustrates a specific example of a multi-dimensional method for determining whether an evaluation result meets preset conditions in order to decide whether to deploy an updated model or trigger a rollback mechanism:

[0047] Scenario 1: The model update is determined to be a valid improvement and non-conflicting: The deployment and release of the model shall be executed if and only if the correlation coefficient of the semantic consistency verification result is higher than the consistency threshold, the retrieval performance evaluation index shows positive growth or remains flat, the average information entropy of the calculated embedding vector is higher than the collapse threshold, and the verification true click-through rate index does not show a significant decrease.

[0048] Scenario 2: Determining that the code retrieval quality of the updated model has degraded: If the decline in retrieval performance evaluation metrics exceeds the tolerance threshold, or if the verified real click-through rate metric declines significantly, it is determined that the updated model has failed to adapt to the current domain characteristics, and automatic rollback and failure log recording can be triggered.

[0049] Scenario 3: Determining potential compatibility or structural conflicts in the updated model: If the correlation coefficient of the semantic consistency verification result is lower than the consistency threshold, it indicates that the basic semantic knowledge is damaged; or if the average information entropy of the embedded vector is lower than the collapse threshold, it indicates that the model is trapped in single-mode overfitting; either of these situations will trigger automatic rollback.

[0050] Furthermore, in another optional implementation of this application embodiment, when performing multi-dimensional performance evaluation on the updated two-layer embedded vector model, the process of determining whether the evaluation result meets the preset conditions can also be as follows: Semantic consistency verification and diversity verification are set as strong constraint indicators; if they fail, they have a veto right and directly trigger automatic rollback; retrieval performance verification is set as a target constraint indicator, allowing small fluctuations in performance indicators within a preset tolerance range, provided the strong constraint indicators pass; user acceptance verification is set as a post-observation indicator for final confirmation during the gray-scale release phase; the model is only approved to enter the gray-scale release phase when both the strong constraint indicators and the target constraint indicators meet the requirements. In this embodiment, the gray-scale release phase refers to a transitional phase where the new model is piloted on a small number of users or traffic, rather than being directly deployed to all production environments. It uses actual user traffic for final verification to ensure the model's real business value beyond offline indicators. This step in this application embodiment limits the system implementing this solution from using a simple unanimous vote as the sole basis for determining whether the preset conditions are met. Instead, a hierarchical decision-making process is adopted. It sets strong constraints (Veto Power) conditions, using semantic consistency and vector diversity as red lines. As described above, for example, if the updated model causes the basic semantic relevance coefficient to drop from 0.9 to 0.6 (breaking generalization ability), or the average information entropy to fall below the threshold (collapse), it is a veto regardless of how good the retrieval performance is, forcing the model parameters to be rolled back. Retrieval performance (MRR) is the optimization goal of model parameter updates. If the strong constraint indicators are passed, but the MRR drops slightly (e.g., -0.1%), it can be judged in conjunction with the confidence interval. If it is within the error range and the diversity is significantly improved, the updated model can be allowed to be released to obtain a more generalized model to support the retrieval service.

[0051] Optionally, in one implementation of this application embodiment, the method further includes: predefining multiple code function semantic pattern categories and clustering the training samples into the corresponding categories; during the model update process, monitoring in real time the distribution of the top-ranked retrieval results output by the two-layer embedding vector model across each semantic pattern category; if the retrieval results are detected to be concentrated in a single semantic pattern category, a diversity constraint regularization term based on Playbook semantic classification is introduced into the contrastive loss function to guide the updated model-generated embedding vectors to maintain dispersion in the semantic space. This step aims to solve the common problem of context collapse in contrastive learning, i.e., all embedding vectors cluster towards the center of the space, leading to homogenization of retrieval results. This step is limited to introducing structured semantic constraints before model training and updating, automatically clustering the training samples into different function pattern categories (Playbooks), such as data processing, interface logic, machine learning inference, etc. These categories provide a structured semantic topology for the embedding space. Then, a diversity constraint regularization term, LDuversity, is introduced as part of the joint optimization function. During training, the distribution of Top-K retrieval results in the Playbook category, PPlaybook, is monitored. When the calculated information entropy H(PPlaybook) falls below a preset threshold... During entropy, if the Top-K retrieval results of the updated model are too concentrated in a single pattern (results tend to be homogeneous), a diversity constraint regularization term, LDuversity, is introduced. This regularization term penalizes this overly concentrated distribution. By imposing this constraint, this step guides the model to maintain the dispersion and structural differences in the embedding space, ensuring that the retrieval results are highly semantically relevant while possessing functional diversity and breadth, thus maintaining the diversity of results.

[0052] Optionally, in one implementation of this application embodiment, the method further includes: when constructing the two-layer embedding vector model, instantiating and maintaining independent lightweight adapter layer parameter sets for different code domains or tenants, but sharing the frozen base encoding layer, for dynamically loading the corresponding adapter layer parameter sets according to the context for encoding use during code retrieval or model training. In this embodiment, this step is achieved by instantiating and maintaining multiple independent lightweight adapter layer parameter sets θadapter(i). A unique adapter layer parameter set i is maintained for different code domains (such as finance, healthcare) or different tenants. When a user initiates a retrieval request, the corresponding adapter layer parameter set θadapter(i) is dynamically loaded according to the domain to which the user or code repository belongs, and combined with the frozen base encoding layer to generate domain-specific code semantic embedding vectors.

[0053] Specifically, to implement the above technical process, a unique domain identifier (Domain ID) can be assigned to each code domain or tenant, and an incrementing version number (Version ID) can be maintained for the adapter parameter group under that domain. When a retrieval request is received, the domain identifier in the retrieval request context is parsed, and the latest version of the adapter parameter group with the "Active" status under that domain is automatically loaded into memory and combined with the basic semantic encoding layer for subsequent model inference. This embodiment exemplifies how to perform full lifecycle version management of multiple adapter parameters in complex scenarios involving multiple tenants and multiple domains, and how to dynamically load and switch adapter layer parameter groups based on the context of a user-initiated retrieval request:

[0054] To support fine-grained management, a hierarchical index structure is used to store lightweight adapter parameters (AdapterWeights), specifically defined as follows:

[0055] First-level index (tenant / domain dimension): Use Tenant_ID (tenant identifier) ​​and Domain_ID (domain / project identifier) ​​as a composite primary key. For example, Domain_Payment (payment module) and Domain_RiskControl (risk control module) under Tenant_FinTech_01 (a financial technology company) each have independent storage space.

[0056] Second-level index (version dimension): Under each domain, maintain an incremental list of Version_IDs. Each version contains a complete adapter parameter file (typically several MB in size) and metadata.

[0057] Configure a version state machine to maintain state labels for each version throughout the entire lifecycle of the multi-adapter parameters. The specific process includes:

[0058] Training: Parameters are being updated in the adaptive learning engine;

[0059] Canary (in grayscale / validation): Training has been completed and is being tested in multi-path self-validation or low-traffic environments;

[0060] Active (already launched): The main version that has passed all verifications and is currently being used entirely for online inference;

[0061] Archived: Historical older versions, used for quick and intelligent rollback;

[0062] When a user's search request is received, the following dynamic routing process is executed:

[0063] Step a: Context Extraction. Parse the retrieval request header or metadata to extract the X-Tenant-ID (e.g., "T001") and X-Context-Tag (e.g., "Java / Spring"). If the request does not explicitly carry a domain tag, the system calls a lightweight classifier to predict the domain based on the query content;

[0064] Step b: Route lookup. Query the metadata database to locate the latest version of the Java / Spring domain adapter under tenant T001 that is currently in Active state, such as Adapter_v1.5.

[0065] Step c: Parameter Acquisition. Generate a loading instruction that points to the parameter address for this specific version.

[0066] The system's inference service nodes maintain a GPU memory / memory-level adapter cache pool. Frozen CodeBERT base model parameters reside permanently in GPU memory and do not change with retrieval requests. If the target adapter Adapter_v1.5 is already in the GPU memory cache pool, it is directly reused to achieve zero-latency switching. If the target adapter does not exist in the cache pool, the parameter file is retrieved from object storage or a high-speed SSD and loaded into GPU memory.

[0067] The above steps in this embodiment, through hierarchical storage and version state management, enable the system implementing this solution to easily support the customized needs of tens of thousands of tenants. Version rollback and canary release operations only require modification of metadata state, without restarting the service. The context-based automatic routing strategy ensures that even when switching between different domain codebases, the latency fluctuation of the retrieval service remains within a very small time range (milliseconds). Furthermore, this embodiment limits the adapter version's lifecycle to follow a strict state transition model: after training, the version automatically migrates from Training to Canary; after passing multi-way verification, it migrates to Active; after a new Active version is released, the previous version is downgraded to Archived; if Canary verification fails, it directly downgrades to Archived. This closed-loop approach clearly defines the engineering path for the system to implement canary releases and automatic rollbacks.

[0068] Further optionally, in one implementation of this application embodiment, the method further includes: when multiple retrieval requests are received, supporting the processing of concurrent requests within the same inference service instance. For example, thread A processes requests in the financial domain, calling Base_Model + Adapter_Finance; thread B simultaneously processes requests in the gaming domain, calling Base_Model + Adapter_Game. Since the base model is read-only and shared, while the adapter parameters are thread-local or request-level isolated, this better achieves physical isolation and non-interference of multi-domain knowledge on a single physical node. In multi-tenant concurrent scenarios, this thread-level adapter loading mechanism ensures that semantic embedding calculations between different tenants or domains are independent. This mechanism guarantees the isolation of domain knowledge from an engineering perspective, effectively avoiding the problem of mutual pollution of adapter parameters due to high-concurrency access, and is a key foundation for ensuring data security and semantic accuracy in a multi-tenant environment.

[0069] Optionally, in one implementation of this application embodiment, the method further includes: configuring the trigger threshold as an adaptive threshold, the adaptive dynamic adjustment mechanism of which includes: initializing and setting a basic trigger threshold; monitoring the model performance improvement and user feedback density in historical update cycles; if it is determined that the recent model retrieval performance improvement has slowed down or is in a plateau period, then raising the basic trigger threshold; if a significant shift in user query distribution or an increase in the frequency of new words is detected, then lowering the basic trigger threshold. This application embodiment further limits the method described in this embodiment to a practical application scenario where a fixed mechanism, such as accumulating more than 1000 positive and negative sample pairs to trigger updates, can be used instead of a fixed one. Instead, a more intelligent and flexible dynamic threshold adjustment mechanism can be used for adaptive adjustment. For example, the trigger threshold Ntrigger can be determined in the following way:

[0070] Ntrigger= Nbase* (1+ α* Pstability)*(1 – β*Ddrift)

[0071] Nbase is the preset base threshold (e.g., 500 entries). Pstability is the model's stability coefficient. If the MRR improvement is less than 0.5% after the last update, it indicates that the model has entered a plateau period, and the threshold is automatically increased (e.g., to 2000 entries) to avoid ineffective fine-tuning and wasting computing power. Ddrift is the data drift coefficient. If a surge in the proportion of new words (OOV) in user queries is detected, it indicates that the business has changed, and the system automatically lowers the threshold (e.g., to 200 entries) to accelerate iteration and adapt to new concepts.

[0072] α is a weighted coefficient used to measure the impact of model performance stability (Pstability) on the trigger threshold. It controls how much the system increases N when model performance plateaus. trigger The strength of the force. It is a hyperparameter that a user sets based on experience, determined by the user during the initial deployment based on business stability and resource budget;

[0073] β is a weighted coefficient used to measure the impact of data drift (Ddrift) on the trigger threshold. It controls the reduction of Ntrigger's response speed when a significant change in user query semantics is detected (e.g., the appearance of new terms or patterns). It is also an empirically set hyperparameter, typically ranging from [0, 1). A larger β setting (e.g., β=0.9) indicates that the system implementing this solution is highly sensitive to changes in new business patterns, the trigger threshold will decrease rapidly and significantly, and the system will respond to business changes more promptly. A smaller β setting (e.g., β=0.2) indicates that the system considers changes in business semantics to be slow, maintaining a higher trigger threshold to reduce noise interference.

[0074] The above calculation method in this application, by introducing α and β to achieve an adaptive dynamic adjustment mechanism, optimizes system resources and saves costs. When the improvement of model performance indicators (such as MRR) is negligible after multiple updates, it is determined that the model has entered a plateau period of current knowledge. Training is no longer frequently triggered by a small amount of new implicit feedback, avoiding a large amount of unnecessary computational overhead and power consumption. This significantly reduces the model's operation and maintenance costs. When a significant change in user query distribution is detected, such as a surge in the frequency of new domain terms (OOV) (i.e., increased Ddrift), it indicates that business domain knowledge is evolving rapidly. At this time, the β coefficient drives the trigger threshold Ntrigger to decrease. Even if the model performance is good on old data, the system will immediately lower the threshold for triggering updates, accelerating the model's learning process. This ensures that the model can quickly absorb the latest business semantics and adapt to new retrieval requirements in a timely manner. Therefore, it more effectively solves the technical problems of model lag and semantic disconnect when facing rapid codebase evolution, ensuring the effectiveness and timeliness of code retrieval.

[0075] Optionally, in one possible implementation of this application embodiment, the method further includes: when it is detected that there is no historical implicit feedback data for the new domain corresponding to the retrieval request, analyzing the structural features of the target code library and extracting function names and docstrings as pseudo-positive sample pairs; using pseudo-positive samples to pre-train the parameter set for initializing a new lightweight adapter layer; when it is determined that the accumulated amount of real implicit feedback data in the new domain reaches the cold start switching threshold, switching the parameter set of the new adapter layer to an adaptive update process based on real implicit feedback. This step in this application embodiment is specific to a newly accessed domain (such as a proprietary scripting language developed by a company), where the implicit feedback corresponding to the target code library does not contain any historical user behavior data about that domain. In this case, the code library can be statically scanned first to extract (function name, function body) and (Docstring comment, function body) as paired data. Then, the Docstring is considered a "pseudo-query," and the function body is considered a "pseudo-positive sample." TF-IDF is used to mine functions with large textual differences as negative samples, thereby forming a synthetic dataset. This synthetic dataset is used to initialize an initial version of the lightweight adapter to configure the initial version of the model for deployment. The system collects real implicit user feedback during the use of the initial version model. Once the amount of real implicit feedback reaches the set switching threshold, the lightweight adapter initialized with the synthetic dataset is stopped, and the system switches to the full use of the collected real implicit feedback to update and iterate the parameters of the official version model (lightweight adaptation layer) as described in steps S101 to S104. The updated and iterated model is then deployed online for users to use in subsequent searches.

[0076] This application provides a code retrieval method for AI programming by constructing a two-layer embedding vector model. The two-layer embedding vector model includes a parameter-frozen basic semantic encoding layer and multiple independent lightweight adaptation layers, each corresponding to a different code domain or tenant. It monitors implicit feedback data generated by user interactions with the target code repository and extracts positive and negative sample pairs based on preset heuristic rules, while also mining difficult negative samples based on the current model. A training sample set is then formed based on the positive and negative sample pairs and the difficult negative samples. When the cumulative number of samples in the training sample set reaches a preset trigger threshold, at least one lightweight adaptation layer parameter is optimized and updated using a preset contrastive loss function based on the training sample set. Elastic weight constraints are applied to key parameters to obtain the updated two-layer embedding vector model. The updated two-layer embedding vector model undergoes multi-dimensional performance evaluation. When the evaluation results meet preset release conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to a code retrieval service to support user code retrieval. This solution establishes a two-layer architecture as its material foundation and, through "freezing the base layer and updating the adaptation layer," adjusts and optimizes only the parameters of the adaptation layer to adapt to code retrieval in new domains. It utilizes the frozen state of the base layer to prevent catastrophic forgetting, making the process flexible and controllable, and with low implementation costs. It effectively solves the technical problems of existing code retrieval models being difficult to adapt across domains, having high costs, and being prone to catastrophic forgetting, and achieves zero-label continuous self-evolution of the code retrieval model.

[0077] Based on the code retrieval method for AI programming provided in the above embodiments of this application, this application also provides a corresponding device for code retrieval in AI programming, such as... Figure 2 As shown, Figure 2 This application provides a schematic diagram of the structure of a code retrieval device 20 for AI programming, which includes:

[0078] The dual-layer embedding module 201 is used to construct a dual-layer embedding vector model; wherein, the dual-layer embedding vector model includes a parameter-frozen basic semantic encoding layer and multiple independent lightweight adaptation layers coexisting.

[0079] The feedback acquisition module 202 is used to monitor implicit feedback data generated by users interacting with the target code library, extract positive and negative sample pairs based on preset heuristic rules, and mine difficult negative samples based on the current model; thereby forming a training sample set based on the positive and negative sample pairs and the difficult negative samples; wherein, the current model is the constructed two-layer embedding vector model or the deployed two-layer embedding vector model.

[0080] The optimization and update module 203 is used to optimize and update at least one lightweight adaptation layer parameter of the multiple lightweight adaptation layers based on the training sample set when the cumulative number of samples in the training sample set reaches a preset trigger threshold, and apply elastic weight constraints to the key parameters to obtain the updated two-layer embedding vector model.

[0081] The self-verification module 204 is used to perform multi-dimensional performance evaluation on the updated two-layer embedding vector model. When it is determined that the evaluation results meet the preset release conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to the code retrieval service to support users in code retrieval.

[0082] Optionally, in one implementation of this application embodiment, the feedback collection module 202 is further configured to: monitor the user's operation behavior on the list of search results retrieved from the target code library; when it is detected that the user has performed a copy operation on a specific code snippet, or clicked to enter the details page and stayed for more than a preset time, mark the retrieved query statement and the corresponding specific code snippet as a positive sample pair; when it is detected that the user quickly skips or does not click on the code snippet in the search results, mark the corresponding code snippet as a normal negative sample; establish the association relationship between the query statement and the marked positive sample pair and the code snippet corresponding to the normal negative sample through the operation behavior, and form the positive and negative sample pair.

[0083] Optionally, in one implementation of this application embodiment, the training sample set further includes difficult negative samples; correspondingly, the feedback acquisition module 202 is further used to obtain the similarity between the current query statement and each candidate code segment in the target code library in the embedding semantic space of the current model; sort the candidate code segments according to the similarity results; and select code segments with similarity higher than a preset value but determined to be irrelevant based on the interaction behavior from the sorting results as the difficult negative samples.

[0084] Optionally, in one implementation of this application embodiment, the optimization update module 203 is further configured to: construct a contrastive learning objective using the Information Noise Contrast Estimation (InfoNCE) loss function, and introduce a temperature parameter to scale and adjust the cosine similarity between the query statement and the positive and negative sample vectors, calculate the contrastive loss value of the current batch of training samples, so as to quantify the deviation of the model in fine-grained semantic distinction; based on the contrastive loss value, execute the backpropagation algorithm to calculate the gradient information of the parameters of each layer of the two-layer embedding vector model; according to the gradient information, perform weight update operations only on the dimensionality reduction mapping parameters and dimensionality increase mapping parameters in the lightweight adaptation layer, and intercept gradient updates for the basic semantic encoding layer, so as to maintain the general language model capability while optimizing the domain semantic representation.

[0085] Optionally, in one implementation of this application embodiment, the optimization update module 203 is further used to calculate the Fisher information matrix of each parameter in at least one lightweight adaptation layer to quantify the importance of each parameter to existing domain knowledge; and to adopt an elastic weight solidification mechanism to add a regularization term to the preset contrast loss function to penalize the update magnitude of parameters whose importance is greater than the preset weight, so that while the model learns new domain features, it limits the offset range of the model relative to the previous optimal weight, so as to achieve the coexistence and retention of multiple domain knowledge in a single model.

[0086] Optionally, in one implementation of this application embodiment, the optimization and update module 203 is further configured to predefine multiple code function semantic pattern categories and cluster the training samples into the corresponding categories; during the model update process, the distribution of the top-ranked retrieval results output by the two-layer embedding vector model on each semantic pattern category is monitored in real time; if the retrieval results are detected to be concentrated in a single semantic pattern category, a diversity constraint regularization term based on Playbook semantic classification is introduced into the contrastive loss function to guide the embedded vectors generated by the updated model to maintain dispersion in the semantic space.

[0087] Optionally, in one implementation of this application embodiment, the performance evaluation dimensions include at least two of the following: semantic consistency verification, retrieval performance evaluation, vector diversity detection, and user acceptance verification; wherein, the semantic consistency verification refers to comparing the semantic representation of the benchmark test set by the model before and after the update to ensure that the general semantic relationship has not undergone destructive shift; the retrieval performance evaluation refers to calculating the average reciprocal ranking index on the validation set, requiring the updated index to be higher than a preset gain threshold; the vector diversity detection refers to calculating the Playbook category coverage of the global embedding vector, or calculating the average information entropy of the embedding vector, to ensure that context collapse has not occurred; the user acceptance verification refers to conducting online A / B testing within a small traffic range to verify the real click-through rate index. Correspondingly, the self-verification module 204 is also used to perform formal deployment of the updated two-layer embedding vector model when all dimensions of performance evaluation pass.

[0088] Optionally, in one implementation of this application embodiment, the lightweight adaptation layer adopts a parameter efficient fine-tuning (PEFT) structure, and the lightweight adaptation layer is embedded between the Transformer layers of the basic semantic coding layer using a bottleneck structure; the proportion of trainable parameters in each lightweight adaptation layer is less than the preset proportion of the total number of parameters in the model architecture of the constructed two-layer embedding vector model.

[0089] Optionally, in one possible implementation of this application embodiment, the device 20 further includes a rollback module and a correction module (neither shown in the figures). The rollback module is used to trigger an automatic rollback mechanism to restore to the previous stable version when it is determined that the evaluation result does not meet the preset release conditions. The correction model is used to trigger a retraining mechanism if it is confirmed that the reason why the evaluation result does not meet the preset release conditions is due to local noise or overfitting, and then use specific failure sample pairs for correction training.

[0090] In a preferred implementation of this application, the specific failed sample pairs are used for targeted correction training, including: when a rollback is triggered by a verification failure, extracting test data that fails to meet preset conditions or a subset of samples that perform poorly in the verification set; marking the subset of samples as "high-difficulty correction samples" and mixing them with new implicit feedback data to form a correction dataset; based on the correction dataset, performing targeted fine-tuning training on the old version of the lightweight adapter after rollback by reducing the learning rate and increasing the weight of the Playbook diversity regularization term, until the multi-dimensional performance evaluation verification is triggered again.

[0091] Optionally, in an optional implementation of this application embodiment, the dual-layer embedding module 201 is further configured to instantiate and maintain independent lightweight adaptation layer parameter sets for different code domains or tenants when constructing the dual-layer embedding vector model, but share the frozen basic encoding layer, and dynamically load the corresponding adaptation layer parameter set according to the context for encoding use when performing code retrieval or model training.

[0092] Optionally, in one possible implementation of this application embodiment, the preset heuristic rules include at least: noise filtering and abnormal behavior data removal of the monitored implicit feedback data.

[0093] Optionally, in one possible implementation of this application embodiment, the trigger threshold is an adaptive threshold, and its adaptive dynamic adjustment mechanism includes: initializing and setting a basic trigger threshold; monitoring the model performance improvement and user feedback density in historical update cycles; if it is determined that the recent model retrieval performance improvement has slowed down or is in a plateau period, then the basic trigger threshold is increased; if a significant shift in user query distribution or an increase in the frequency of new words is detected, then the basic trigger threshold is decreased.

[0094] Optionally, in one optional implementation of this application embodiment, the optimization update module 203 is further configured to: when it is detected that there is no historical implicit feedback data in the new domain corresponding to the retrieval request, analyze the structural features of the target code library and extract function names and docstrings as pseudo-positive sample pairs; use pseudo-positive sample pairs to initialize a new adapter parameter group for preheating training; when it is determined that the accumulated amount of real implicit feedback data in the new domain reaches the cold start switching threshold, switch the new adapter layer parameter group to the adaptive update process based on real implicit feedback.

[0095] In another optional implementation of this application embodiment, when the optimization and update module 203 performs multi-dimensional performance evaluation on the updated two-layer embedded vector model, the process of determining whether the evaluation result meets the preset conditions can also be as follows: setting semantic consistency verification and diversity verification as strong constraint indicators, which have a veto right if they fail, and directly triggering automatic rollback; setting retrieval performance verification as a target constraint indicator, allowing small fluctuations in performance indicators within a preset tolerance range on the premise that the strong constraint indicators pass; setting user acceptance verification as a post-observation indicator for final confirmation during the gray release stage; and approving the model to enter the gray release stage only when both the strong constraint indicators and the target constraint indicators meet the requirements.

[0096] This application embodiment exemplarily illustrates the collaborative workflow of the various component modules in this device:

[0097] In the operation of the device described in this application embodiment, the specific workflow of the entire device (system) is initiated by the feedback acquisition module. This module continuously monitors the user's code retrieval interaction behavior (clicks, copying, dwelling, etc.) and processes the raw log data in real time. It first performs noise filtering and abnormal behavior removal, and generates a reliable effective sample set based on the behavior weights. Subsequently, the module compares the accumulated number of effective samples with the adaptive dynamic update trigger threshold. Once the sample size reaches the threshold, indicating that the accumulated domain knowledge is sufficient to drive an effective update, the feedback acquisition module issues a "TRIGGER_UPDATE" trigger signal to start the next step of the model optimization process;

[0098] Upon receiving the trigger signal, the device enters the sample preparation phase: the feedback acquisition module provides cleaned positive sample pairs. Simultaneously, this module (or its internal functional components) requests the adapter parameters of the currently online (Active) service from the two-layer embedding module to establish the current semantic space baseline. Subsequently, this module obtains the similarity between the positive sample retrieval and the candidate codebase, using dynamic similarity filtering intervals and historical data to accurately identify difficult negative samples that are similar to the retrieval but functionally inconsistent. The positive sample pairs and difficult negative samples are combined to form a high-quality final training dataset, which is then delivered to the optimization and update module.

[0099] After receiving the training dataset, the optimization update module initiates efficient parameter fine-tuning. This module strictly adheres to the two-layer architecture convention, updating only the lightweight adapter parameters for the target domain using the contrastive learning objective function, while keeping the weights of the basic semantic encoding layer frozen. During update training, this module enforces EWC parameter constraints to preserve old knowledge and enables Playbook diversity constraints to prevent vector collapse. After update training is complete, the optimization update module generates new candidate adapter parameters and notifies the version manager of the two-layer embedding building module to mark the new parameters as Canary (in grayscale validation) status.

[0100] New candidate parameters are fed into the self-verification module. This module can execute multiple verification processes in parallel, including semantic consistency, MRR performance, vector diversity, and user acceptance (A / B testing). Based on the scores of the four verifications, the module performs aggregation and judgment according to a preset decision priority logic (e.g., semantic consistency and diversity are strong constraints, and retrieval performance is a target constraint), outputting the final decision signal (PASS or FAIL), and can also output the reason for failure.

[0101] The device performs the final closed-loop operation based on the output of the multi-channel self-verification module:

[0102] If the decision signal is PASS: After receiving the pass signal, the dual-layer embedded module updates the parameter status of the lightweight adaptation layer and sets it to Active, notifies the device to switch the routing to the new version, and completes a successful adaptive iterative deployment.

[0103] If the decision signal is FAIL (structural failure), the rollback module is immediately triggered. The rollback module sends an instruction to the two-layer embedded module to force the lightweight adapter layer parameters of the previous stable version to remain in the Active state. The purpose of the rollback module is to restore to the previous stable version and ensure the stability of the current online service.

[0104] Furthermore, when the decision signal FAIL is determined to be due to local noise or overfitting, the correction module is triggered and analyzes the cause of failure, extracting specific failure sample pairs that lead to performance degradation based on the cause. Using these failure sample pairs, hyperparameters are adjusted (e.g., reducing the learning rate, strengthening regularization constraints), and the task is then resent to the optimization and update module. The role of the correction module is to trigger a retraining mechanism, using specific failure sample pairs for corrective training to address local degradation issues and complete the correction loop closure.

[0105] By implementing the above-mentioned modular collaborative workflow mechanism in this application, the device achieves systematic, zero-interruption, and low-cost continuous evolution of the model, ensuring the structural stability and retrieval quality of the system through rigorous verification and automatic rollback mechanisms while learning new knowledge.

[0106] This application provides a code retrieval device for AI programming, which sets up a two-layer embedding module to construct a two-layer embedding vector model. The two-layer embedding vector model includes a parameter-frozen basic semantic encoding layer and multiple independent lightweight adaptation layers. Then, a set feedback acquisition module monitors implicit feedback data generated by user interaction with the target code library, extracts positive and negative sample pairs based on preset heuristic rules, and mines difficult negative samples based on the current model, wherein the current model is the constructed two-layer embedding vector model or the deployed two-layer embedding vector model. A training sample set is then formed based on the positive and negative sample pairs and the difficult negative samples. Finally, an optimization update module, when the cumulative number of samples in the training sample set reaches a preset trigger threshold, optimizes and updates at least one lightweight adaptation layer parameter based on the training sample set using a preset contrastive loss function, and applies elastic weight constraints to key parameters to obtain the updated embedding vector model. Finally, a self-verification module is used to perform multi-dimensional performance evaluation on the updated two-layer embedding vector model. When the evaluation results meet the preset release conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to the code retrieval service to support users in code retrieval. The device has a simple structure. It establishes a two-layer architecture as its material foundation and adjusts and optimizes only the parameters of the adaptation layer to adapt to code retrieval in new domains by "freezing the base layer and updating the adaptation layer". The frozen state of the base layer is used to prevent catastrophic forgetting. The process is flexible and controllable, and the implementation cost is low. It effectively solves the technical problems of existing code retrieval models being difficult to adapt across domains, having high costs, and being prone to catastrophic forgetting, and achieves zero-label continuous self-evolution of the code retrieval model.

[0107] This application also provides a storage medium storing a computer program thereon, which, when executed by a processor, implements any of the code retrieval methods for AI programming described in the foregoing embodiment one of this application.

[0108] This application also provides an electronic device, such as... Figure 3 As shown, Figure 3 This application provides a schematic diagram of the structure of an electronic device 30, which includes:

[0109] One or more processors 301, communication interface 302, memory 303 and communication bus 304, the processors 301, memory 303 and communication interface 302 communicate with each other through communication bus 304;

[0110] Memory 303 is used to store one or more programs;

[0111] When the one or more programs are executed by the one or more processors 301, the one or more processors 301 implement any of the code retrieval methods for AI programming as described in Embodiment 1 of this application.

[0112] This application has now described specific embodiments of the subject matter. In some cases, the actions described in the claims can be performed in a different order and still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require a specific or sequential order to achieve the desired result. In some embodiments, multitasking and parallel processing can be advantageous.

[0113] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system layer onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must also be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also understand that by simply performing some logic programming on the method flow using one of these hardware description languages ​​and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.

[0114] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.

[0115] The system layers, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.

[0116] For ease of description, the above devices are described separately by function as various units. Of course, in implementing this application, the functions of each unit can be implemented in one or more software and / or hardware.

[0117] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0118] Those skilled in the art will understand that embodiments of this application can be provided as methods, system-level, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0119] This application can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific transactions or implement specific abstract data types. This application can also be practiced in distributed computing environments where transactions are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0120] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system-level embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0121] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A code retrieval method for AI programming, characterized in that, include: Construct a two-layer embedding vector model; wherein the two-layer embedding vector model includes a basic semantic encoding layer with parameter freezing, and multiple independent lightweight adaptation layers coexisting, each lightweight adaptation layer corresponding to a different code domain or tenant; The system monitors implicit feedback data generated by user interactions in the target code library, extracts positive and negative sample pairs based on preset heuristic rules, and mines difficult negative samples based on the current model; a training sample set is formed based on the positive and negative sample pairs and the difficult negative samples; wherein, the current model is the constructed two-layer embedding vector model or the deployed two-layer embedding vector model. When the cumulative number of samples in the training sample set reaches a preset trigger threshold, based on the training sample set, at least one lightweight adaptation layer parameter of the multiple lightweight adaptation layers is optimized and updated using a preset contrastive loss function, and elastic weight constraints are applied to key parameters to obtain an updated two-layer embedding vector model; wherein, applying elastic weight constraints to key parameters includes: calculating the Fisher information matrix of each parameter in at least one lightweight adaptation layer to quantify the importance of each parameter to existing domain knowledge; and adopting an elastic weight solidification mechanism to add a regularization term to the preset contrastive loss function to penalize the update magnitude of parameters whose importance is greater than the preset weight, so as to limit their offset range relative to the previous optimal weight. The updated two-layer embedding vector model is subjected to multi-dimensional performance evaluation. When the evaluation results meet the preset release conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to the code retrieval service to support users in code retrieval.

2. The code retrieval method for AI programming according to claim 1, characterized in that, The monitoring process involves implicit feedback data generated by user interactions with the target codebase, and the extraction of positive and negative sample pairs based on preset heuristic rules, including: Monitor user actions on the list of search results retrieved from the target code library. When user actions on the list of search results retrieved from the target code library are detected, such as copying a code snippet in the list of search results or clicking to enter a details page and staying there for more than a preset time, mark the search query and the corresponding code snippet as a positive sample pair. When it is detected that a user quickly skips or does not click on a code snippet in the search results, the corresponding code snippet is marked as a normal negative sample; The operation establishes a relationship between the query statement and the code fragments corresponding to the marked positive sample pairs and ordinary negative samples, thus forming the positive and negative sample pairs.

3. The code retrieval method for AI programming according to claim 1, characterized in that, The training sample set also includes difficult negative samples. The process of obtaining the training sample set also includes: Obtain the similarity between the current query statement and each candidate code fragment in the target code library in the embedding semantic space of the current model; The candidate code segments are sorted according to the similarity results; Code snippets with similarity higher than a preset similarity threshold and deemed irrelevant based on the implicit feedback data are selected from the sorting results as the difficult negative samples.

4. The code retrieval method for AI programming according to claim 1, characterized in that, When mining difficult negative samples based on the current model, the method further includes: The negative sample pool formed by negative sample pairs is refreshed periodically and the entire negative sample pool is reconstructed periodically based on model performance or time intervals.

5. The code retrieval method for AI programming according to claim 1, characterized in that, The step of optimizing and updating the parameters of the adaptation layer based on the training sample set using a preset contrastive loss function includes: A contrastive learning objective is constructed using the information noise contrastive estimation loss function, and a temperature parameter is introduced to scale and adjust the cosine similarity between the query statement and the positive and negative sample vectors. The contrastive loss value of the current batch of training samples is calculated to quantify the model's deviation in fine-grained semantic distinction. Based on the contrastive loss value, the backpropagation algorithm is executed to calculate the gradient information of the parameters of each layer of the two-layer embedding vector model; Based on the gradient information, weight update operations are performed only on the dimensionality reduction mapping parameters and dimensionality increase mapping parameters in the lightweight adaptation layer, and gradient updates for the basic semantic encoding layer are intercepted, so as to maintain the general language model capability while optimizing the domain semantic representation.

6. The code retrieval method for AI programming according to claim 1, characterized in that, In obtaining the updated two-layer embedding vector model, the method further includes: Multiple code function semantic pattern categories are predefined, and the training samples are clustered and assigned to the corresponding categories; During the model update process, the distribution of the top-ranked search results in the model output across various semantic pattern categories is monitored in real time. If the search results are detected to be concentrated in a single semantic pattern category, a diversity constraint regularization term based on Playbook semantic classification is introduced into the contrastive loss function to guide the updated model to maintain the dispersion of the embedded vectors in the semantic space.

7. The code retrieval method for AI programming according to claim 1, characterized in that, Performance evaluation dimensions should include at least: semantic consistency verification, retrieval performance evaluation, vector diversity detection, and user acceptance verification. The semantic consistency verification refers to comparing the semantic representation of the benchmark test set by the model before and after the update to ensure that the general semantic relationships have not undergone destructive shifts; the retrieval performance evaluation refers to calculating the average reciprocal ranking index on the validation set, requiring the updated index to be higher than a preset gain threshold; the vector diversity detection refers to calculating the Playbook category coverage of the global embedding vector, or calculating the average information entropy of the embedding vector, to ensure that context collapse has not occurred; the user acceptance verification refers to conducting online A / B testing within a small traffic range to verify the true click-through rate index. Correspondingly, the step of confirming the updated two-layer embedding vector model as the final model and deploying it to the code retrieval service when the evaluation result meets the preset release conditions includes: Once all performance evaluations pass, the updated two-layer embedding vector model will be formally deployed.

8. The code retrieval method for AI programming according to claim 1, characterized in that, The lightweight adaptation layer adopts a parameter efficient fine-tuning (PEFT) structure, and the lightweight adaptation layer is embedded between the Transformer layers of the basic semantic coding layer using a bottleneck structure. The proportion of trainable parameters in each lightweight adaptation layer is less than the preset proportion of the total number of parameters in the constructed two-layer embedding vector model architecture.

9. The code retrieval method for AI programming according to claim 1, characterized in that, The method further includes: When the results of the multi-dimensional performance evaluation do not meet the preset conditions, a rollback mechanism or a retraining mechanism is triggered to restore the previous verified stable version, or a retraining mechanism is triggered to perform targeted corrective training using specific failure sample pairs. Herein, the specific failure sample pairs refer to the positive and negative sample pairs corresponding to the test data that caused the results of the multi-dimensional performance evaluation to fail to meet the preset conditions during the multi-dimensional performance evaluation process, or the sample subset that performed poorly in the validation set and was judged as having degraded retrieval quality or destroyed semantic structure.

10. The code retrieval method for AI programming according to claim 1, characterized in that, The method further includes: when constructing the two-layer embedding vector model, instantiating and maintaining an independent set of lightweight adaptation layer parameters for different code domains or tenants, but sharing the frozen base encoding layer, which is used to dynamically load the corresponding adaptation layer parameter set according to the context for encoding use when performing code retrieval or model training.

11. The code retrieval method for AI programming according to claim 1, characterized in that, The preset heuristic rules include at least: noise filtering and abnormal behavior data removal for the monitored implicit feedback data.

12. The code retrieval method for AI programming according to claim 1, characterized in that, The trigger threshold is an adaptive threshold, and its adaptive dynamic adjustment mechanism includes: Initialize and set the basic trigger threshold; Monitor the model performance improvement and user feedback density throughout the historical update cycle; If it is determined that the recent improvement in model retrieval performance has slowed down or is in a plateau phase, the basic trigger threshold is increased; if a significant shift in user query distribution or an increase in the frequency of new words is detected, the basic trigger threshold is decreased.

13. The code retrieval method for AI programming according to claim 1, characterized in that, The method further includes: when it is detected that there is no historical implicit feedback data for the new domain corresponding to the user's search request, analyzing the structural features of the target code library and extracting function names and document strings as pseudo-positive sample pairs; The pseudo-positive samples are used to preheat the parameter set for initializing a new lightweight adaptation layer. When the accumulated amount of real implicit feedback data in the new domain reaches the cold start switching threshold, the new adaptation layer parameter group is switched to the adaptive update process based on real implicit feedback.

14. A device for code retrieval in AI programming, characterized in that, include: A two-layer embedding module is used to construct a two-layer embedding vector model; wherein, the two-layer embedding vector model includes a parameter-frozen basic semantic encoding layer and multiple independent lightweight adaptation layers coexisting. The feedback acquisition module is used to monitor implicit feedback data generated by user interaction in the target code library, and extract positive and negative sample pairs based on preset heuristic rules, and mine difficult negative samples based on the current model; thereby forming a training sample set based on the positive and negative sample pairs and the difficult negative samples; wherein, the current model is the constructed two-layer embedding vector model or the deployed two-layer embedding vector model; The optimization and update module is used to optimize and update at least one lightweight adaptation layer parameter of the multiple lightweight adaptation layers based on the training sample set when the cumulative number of samples in the training sample set reaches a preset trigger threshold, and to apply elastic weight constraints to key parameters to obtain an updated two-layer embedding vector model. The application of elastic weight constraints to key parameters includes: calculating the Fisher information matrix of each parameter in at least one lightweight adaptation layer to quantify the importance of each parameter to existing domain knowledge; and employing an elastic weight solidification mechanism to add a regularization term to the preset contrastive loss function to penalize the update magnitude of parameters whose importance is greater than a preset weight, thereby limiting their offset range relative to the previous optimal weight. The self-verification module is used to perform multi-dimensional performance evaluation on the updated two-layer embedding vector model. When it is determined that the evaluation result meets the preset release conditions, the updated two-layer embedding vector model is confirmed as the final model and deployed to the code retrieval service to support users in code retrieval.

15. A computer storage medium, characterized in that, The computer storage medium stores computer-executable instructions, which, when executed, perform the code retrieval method for AI programming as described in any one of claims 1-13.