Code completion method, electronic device, storage medium and program product

By strengthening the encoding information and semantic information in the vector database and combining the pre-trained completion model, the problem of low completion accuracy for specific frameworks and libraries in the existing technology is solved, and higher code completion accuracy and applicability are achieved.

CN119621030APending Publication Date: 2025-03-14INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411717062.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

The existing code completion technology is trained and optimized based on public open source libraries and frameworks, resulting in low accuracy and applicability of specific frameworks and libraries, and the inability to achieve high accuracy completion.

Method used

By obtaining the target encoding environment, the target encoding context semantic information, and the target code encoding information, it is input into the pre-constructed vector database to obtain the reinforced semantic information and encoding information. Then, input this information into the pre-trained completion model, generate multiple completion codes and their correlation values ​​to determine the most suitable completion code.

Benefits of technology

Improves the accuracy and applicability of code completion, especially when dealing with specific frameworks and libraries, and provides more accurate completion suggestions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621030A_ABST
    Figure CN119621030A_ABST
Patent Text Reader

Abstract

The invention discloses a code completion method, electronic equipment, a storage medium and a program product, and relates to the field of artificial intelligence, and the method comprises the steps: obtaining a target coding environment, target coding context semantic information and coding information of a target code; inputting the context semantic information of the target code and the coding information of the target code into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; inputting the target coding environment, the enhanced semantic information and the enhanced coding information into a pre-trained completion model to obtain a plurality of completion codes output by the completion model and a correlation value corresponding to each completion code; and determining a target completion code according to the plurality of completion codes and the correlation value corresponding to each completion code, and determining a code completion result according to the target completion code. According to the method, code completion can be more accurately combined with the current development platform, and the applicability and accuracy of code completion are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence, and in particular to a code completion method, electronic device, storage medium and program product. Background Art

[0002] As software development becomes increasingly complex and its scale expands, code completion technology plays a vital role in improving development efficiency and reducing errors in the software development process.

[0003] Currently, code completion provides developers with automatic code completion suggestions by analyzing the structure and context of existing code, thereby greatly improving developers' coding efficiency.

[0004] However, existing code completion technologies are trained and optimized based on public open source libraries and frameworks. Therefore, for specific frameworks and libraries, such as those developed by a company itself, their accuracy and applicability are low, and they cannot achieve high-accuracy completion. Summary of the invention

[0005] The present application provides a code completion method, an electronic device, a storage medium and a program product to solve the problem that the existing code completion technology in the prior art is trained and optimized based on public open source libraries and frameworks. Therefore, for specific frameworks and libraries, such as frameworks and libraries developed by a certain enterprise, its accuracy and applicability are low, and high-accuracy completion cannot be achieved.

[0006] In a first aspect, the present application provides a code completion method, the method comprising:

[0007] Obtaining target coding environment, target coding context semantic information and coding information of target code;

[0008] Inputting the target coding context semantic information and the coding information of the target code into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on development data of a development platform corresponding to the target code;

[0009] Inputting the target coding environment, the enhanced semantic information and the enhanced coding information into a pre-trained completion model to obtain a plurality of completion codes output by the completion model and a correlation value corresponding to each of the completion codes;

[0010] A target completion code is determined according to the multiple completion codes and the correlation value corresponding to each of the completion codes, and a code completion result is determined according to the target completion code.

[0011] In a second aspect, the present application provides a code completion device, the device comprising:

[0012] An acquisition module, used for acquiring target coding environment, target coding context semantic information and coding information of target code;

[0013] An enhancement module, used for inputting the target coding context semantic information and the coding information of the target code into a pre-built vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on the development data of the development platform corresponding to the target code;

[0014] A completion module, used for inputting the target coding environment, the enhanced semantic information and the enhanced coding information into a pre-trained completion model, and obtaining a plurality of completion codes output by the completion model and a correlation value corresponding to each of the completion codes;

[0015] A determination module is used to determine a target completion code according to the multiple completion codes and a correlation value corresponding to each of the completion codes, and determine a code completion result according to the target completion code.

[0016] In a third aspect, the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the code completion method as described in any embodiment of the present application is implemented.

[0017] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the code completion method as described in any embodiment of the present application.

[0018] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the code completion method as described in any embodiment of the present application.

[0019] The scheme of the present application obtains the target coding environment, the target coding context semantic information and the coding information of the target code; inputs the target coding context semantic information and the coding information of the target code into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on the development data of the development platform corresponding to the target code; inputs the target coding environment, enhanced semantic information and enhanced coding information into a pre-trained completion model to obtain multiple completion codes output by the completion model and the correlation value corresponding to each completion code; determines the target completion code according to the multiple completion codes and the correlation value corresponding to each completion code, and determines the code completion result according to the target completion code. That is, the scheme of the present application, by inputting the context semantic information and the coding information into the vector database established based on the development data of the development platform corresponding to the target code, the context semantic information and the coding information are semantically enhanced, and can be more accurately combined with the current development platform, avoiding the problem of low accuracy of the completion code generated for specific frameworks and libraries, and improving the applicability and accuracy of code completion. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0021] Figure 1 It is a flowchart of the code completion method provided by this application;

[0022] Figure 2 It is a schematic diagram of the completion model training process of the code completion method provided by this application;

[0023] Figure 3 It is a structural schematic diagram of the code completion device provided by this application;

[0024] Figure 4 It is a structural schematic diagram of the electronic device provided by this application. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0026] The technical terms described in this article are explained and described as follows.

[0027] Encoder-decoder network model: Encoder-decoder is a common model framework in deep learning. The encoder and decoder parts can be any text, voice, image, video, etc. The model can adopt various structures such as Convolutional Neural Networks (CNN), Recurrent Neural Networks (RNN), Bidirectional Recurrent Neural Networks (BiRNN) and Gated Recurrent Unit (GRU), providing an end-to-end learning framework for various network models.

[0028] Recurrent Neural Network: A type of recurrent neural network that takes sequence data as input, recursively in the direction of sequence evolution, and all nodes (recurrent units) are connected in a chain.

[0029] Long Short-Term Memory (LSTM): A time-recurrent neural network designed to solve long-standing problems with general RNNs. All RNNs have a repetitive neural network module connected in a chain.

[0030] Bidirectional Long Short-Term Memory (BiLSTM) neural network: This network is composed of a forward LSTM and a backward LSTM, and is used to extract deep semantic information.

[0031] Transformer network model: Transformer is a solution proposed to solve the sequence-to-sequence problem. This network model uses a full attention structure instead of a long short-term memory neural network model.

[0032] Code completion model: refers to an artificial intelligence model trained using a deep learning network that contains code information and semantic information of the current coding scene. Its main function is to provide real-time code prompt completion services during coding.

[0033] Vector database: In a vector database, each data item is represented as a vector, where each dimension corresponds to a specific attribute or feature. This makes vector databases excel in processing high-dimensional data such as images, audio, and text, because they can directly store and manipulate the feature representations of these data. Vector databases are specifically optimized for high-dimensional data, so they can efficiently store and retrieve data with multiple features. The difference from traditional databases is that vector databases specialize in storing and managing vector data, usually using a vector index-based storage method to map vector data into a high-dimensional space, and build an index interface in this space to support efficient similarity queries.

[0034] The acquisition, storage, use, and processing of data in the technical solution of this application comply with the relevant provisions of national laws and regulations.

[0035] Figure 1 The present invention provides a flowchart of a code completion method, which can be performed by a code completion device, which can be implemented in software and / or hardware. In a specific embodiment, the device can be applied to an electronic device, which can be a computer. The following embodiments will be described by taking the application of the device in an electronic device as an example, referring to Figure 1 , the method may specifically include the following steps:

[0036] Step 101, obtaining target coding environment, target coding context semantic information and coding information of target code.

[0037] Specifically, the target code refers to the vacant code that is expected to be supplemented in this embodiment. The target coding environment is worth the coding environment where the target code is located, and the coding environment where the target code is located refers to the information including the programming language type of the target code (such as Java, python, etc.), the coding software architecture where the target code is located (such as SpringBoot framework programming), and the coding scene where the target code is located (such as writing unit tests). The target coding context semantic information refers to the semantic information of the code text where the target code is located, such as the complete code text information of the currently opened code file. The coding information of the target code refers to the semantic information corresponding to the coding text information of the line where the target code is located. In the intelligent assisted programming scenario, the semantic extraction model based on the Encoder-Decoder framework and built by BiLSTM and Transformer can obtain the semantic information of the coding scene. The method of obtaining the target coding environment, the target coding context semantic information, and the coding information of the target code can be obtained by the electronic device executing this embodiment performing semantic recognition on the coding environment and the coding text where the target code is located, or it can be sent to the electronic device executing this embodiment after determining the semantics by other devices, and this application does not limit this.

[0038] Optionally, the vector database is constructed through steps 11 and 12.

[0039] Step 11, obtain historical development data of the development platform.

[0040] The historical development data includes multiple code semantic information of the development platform.

[0041] Specifically, the development platform refers to the development platform of the project where the target code is located. For example, if code completion is required in a certain coding file of a bank, the development platform is the development platform of the bank. The historical development data of the development platform can be development code files collected from the development environment where the target code is located, such as development code files collected from the internal target development platform of the company where the target code is located. Therefore, the historical development data can include unique semantic information of the development environment where the target code is located, avoiding the situation where the data source of the model is limited to open source data, resulting in low accuracy of the completion code generated for specific frameworks and libraries.

[0042] Step 12: convert multiple code semantic information into multiple semantic vector information and construct a vector database.

[0043] Specifically, multiple code semantic information is converted into vector representation, that is, multiple semantic vector information, and then the multiple semantic vector information is constructed into a vector database. Therefore, the vector database includes semantic vector information of unique semantic information of the development environment where the target code is located.

[0044] Step 102, inputting the target coding context semantic information and the coding information of the target code into a pre-built vector database to obtain enhanced semantic information and enhanced coding information.

[0045] The vector database is established based on the development data of the development platform corresponding to the target code.

[0046] Specifically, since there is an index interface in the vector database, relevant vector data can be searched in the vector database. Therefore, after obtaining the target coding context semantic information and the coding information of the target code, the target coding context semantic information and the coding information of the target code are input into a pre-constructed vector database, and the vector data related to the target coding context semantic information is retrieved through the index interface, and the vector data related to the coding information of the target code is retrieved. The target coding context semantic information is combined with the vector data related to the target coding context semantic information, that is, the combination of the target coding context semantic information and the relevant semantic information in the vector database is completed, thereby achieving a further understanding of the target coding context semantic information and obtaining enhanced semantic information. The coding information of the target code is combined with the vector data related to the coding information of the target code, that is, the combination of the coding information of the target code and the semantic information of the relevant coding in the vector database is completed, thereby achieving a further understanding of the coding information of the target code and obtaining enhanced coding information.

[0047] Optionally, step 102 may be implemented through steps 1021 to 1023 .

[0048] Step 1021, converting the target coding context semantic information into a context vector, and converting the coding information of the target code into a coding vector.

[0049] Specifically, the target coding context semantic information is represented by a vector, which can be converted into a context vector. The coding information of the target code is represented by a vector, which can be converted into a coding vector. The process of representing the semantic information by a vector can be to vectorize and map the text through a vector bag, so as to obtain the vector corresponding to the text. For example, the vector bag can be a word bag model (word2bag) vector bag.

[0050] Step 1022: Based on the context vector, a similarity search is performed in the vector database to obtain enhanced semantic information.

[0051] Specifically, based on the context vector, a similarity search is performed in the vector database through an index interface of the vector database, and the context vector is semantically enhanced according to vectors whose similarity is higher than a preset similarity to obtain enhanced semantic information.

[0052] Step 1023, based on the coding vector, perform similarity search in the vector database to obtain enhanced coding information.

[0053] Specifically, based on the coding vector, a similarity search is performed in the vector database through the index interface of the vector database, and the coding vector is semantically enhanced according to the vector whose similarity is higher than the preset similarity to obtain enhanced coding information. Since the vector information in the vector database is semantic vector information including the unique semantic information of the development environment where the target code is located, the enhanced enhanced semantic information and enhanced coding information are both information related to the unique semantic information of the development environment where the target code is located, thereby enhancing the accuracy of determining the semantic information.

[0054] Step 103, input the target coding environment, enhanced semantic information and enhanced coding information into a pre-trained completion model to obtain a plurality of completion codes output by the completion model and a correlation value corresponding to each completion code.

[0055] Specifically, the correlation value refers to the correlation between the semantic information of the completion code and the enhanced semantic information and enhanced coding information determined according to the vector database. The closer the semantic information to be completed is to the enhanced semantic information and enhanced coding information determined according to the vector database, the higher the correlation value. After obtaining the enhanced semantic information and enhanced coding information, the target coding environment, the enhanced semantic information and the enhanced coding information are input into the pre-trained completion model, and the completion model outputs multiple completion codes, each of which has a corresponding correlation value.

[0056] Exemplarily, multiple completion codes output by the completion model and the correlation value corresponding to each completion code are {1.void main(0.9)} and {2.void hello(0.1)}, where void main and void hello are 2 completion codes, the correlation value corresponding to void main is 0.9, and the correlation value corresponding to void hello is 0.1.

[0057] Step 104: determine a target completion code according to the multiple completion codes and the correlation value corresponding to each completion code, and determine a code completion result according to the target completion code.

[0058] Specifically, among multiple completion codes, according to the correlation value corresponding to each completion code, multiple completion codes with correlation values ​​higher than a preset correlation value are determined as target completion codes. Then, the code completion result is determined according to the target completion code, and the target completion code with the highest correlation value can be completed, or multiple target completion codes can be sent to a user device corresponding to a target user, and the target user can select the target completion code selected by the target user, and the code completion is performed to obtain the code completion result. According to the target completion code, the code completion result can be determined in the form of a plug-in, and the code completion prediction results after sorting and semantic verification can be rendered into the completion candidate box of the integrated development environment code editor.

[0059] Optionally, determining the target completion code according to the multiple completion codes and the correlation value corresponding to each completion code may be implemented through steps 1041 to 1042 .

[0060] Step 1041 , sorting the multiple completion codes according to the multiple completion codes and the correlation value corresponding to each completion code.

[0061] Specifically, according to the multiple completion codes and the correlation value corresponding to each completion code, the multiple completion codes are sorted according to the correlation value.

[0062] For example, in {1.void main(0.9)} and {2.void hello(0.1)}, the correlation value corresponding to void main is 0.9, and the correlation value corresponding to void hello is 0.1, so void main is in the first position and void hello is in the second position.

[0063] Step 1042: determine a target completion code based on the completion codes ranked within a preset ranking.

[0064] Specifically, the preset ranking is a preset ranking of the target completion code, and for example, the preset ranking may be the top 2. Determining the target completion code based on the completion codes ranked within the preset ranking means determining the completion code ranked within the preset ranking after sorting as the target completion code. Determining the target completion code based on the sorting result avoids the completion code with a lower similarity value interfering with the completion result.

[0065] Optionally, after step 104, steps 41 to 42 may also be performed.

[0066] Step 41: convert the code completion result into a code completion vector.

[0067] Specifically, after determining the code completion result, the code completion result is converted into a code completion vector conversion, which can be obtained by vectorizing and mapping the text through a vector package.

[0068] Step 42: store the code completion vector in a vector database.

[0069] Specifically, after the code completion vector is obtained, the code completion vector is stored in a vector database, the amount of code semantic information in the vector database is increased, and the vector database is updated to make the code semantic vector information in the vector database more accurate.

[0070] The scheme of the present application obtains the target coding environment, the target coding context semantic information and the coding information of the target code; inputs the target coding context semantic information and the coding information of the target code into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on the development data of the development platform corresponding to the target code; inputs the target coding environment, enhanced semantic information and enhanced coding information into a pre-trained completion model to obtain multiple completion codes output by the completion model and the correlation value corresponding to each completion code; determines the target completion code according to the multiple completion codes and the correlation value corresponding to each completion code, and determines the code completion result according to the target completion code. That is, the scheme of the present application, by inputting the context semantic information and the coding information into the vector database established based on the development data of the development platform corresponding to the target code, the context semantic information and the coding information are semantically enhanced, and can be more accurately combined with the current development platform, avoiding the problem of low accuracy of the completion code generated for specific frameworks and libraries, and improving the applicability and accuracy of code completion.

[0071] Figure 2 is a schematic diagram of the completion model training process of the code completion method provided by this application. Figure 1 Based on the illustrated embodiment and various optional implementation schemes, the steps of completing the model training are described in detail. Figure 2 As shown, the method may include the following steps:

[0072] Step 201 , obtain a standard code data set, perform data processing on the standard code data set, and convert the standard code data set into a vector code data set.

[0073] Among them, the vector code data set includes multiple training vector data groups, each training vector data group includes a training coding environment, training semantic vector information, training coding vector information and training completion results.

[0074] Specifically, the standard code dataset refers to a code dataset that includes multiple code languages, as well as different business codes and code styles in the same code language. Data processing is performed on the standard code dataset, such as data cleaning, semantic information summary extraction, semantic information splitting training, and verification dataset, so that the data in the code dataset is more convenient for semantic information processing. The code data in the standard code dataset is then converted into vector code data to obtain a vector code dataset.

[0075] Step 202, training the model to be trained according to multiple training coding environments, multiple training semantic vector information, multiple training coding vector information and multiple training completion results until the training termination condition is reached to obtain a completed model.

[0076] Specifically, the model to be trained can be a model that uses an Encoder-Decoder network framework and a BiLSTM neural network. The model to be trained is trained according to multiple training coding environments, multiple training semantic vector information, and multiple training coding vector information, and the parameters of the model to be trained are adjusted based on multiple training completion results until the training termination condition is reached to obtain a completion model. For example, when the training reaches a certain end condition, the training can be stopped, and the model updated in the last round can be used as the recommended group determination model. The end condition can be that the number of training rounds reaches a preset number of rounds, or the training loss is lower than a certain value. The completion model is used to output multiple training completion results and the correlation value corresponding to each training completion result according to the training coding environment, the training semantic vector information, and the training coding vector information. Completing the code through the completion model can improve the rate and accuracy of code completion.

[0077] Optionally, after obtaining the completed model, step 21 to step 22 may also be performed.

[0078] Step 21, determining the accuracy of the completion model according to the test coding environment, the test semantic vector information, the test coding vector information and the test completion result.

[0079] Specifically, the test set includes a test coding environment, test semantic vector information, test coding vector information, and test completion results. The test coding environment, test semantic vector information, and test coding vector information are input into the completion model to obtain the output result of the completion model. The accuracy of the completion model is determined based on the consistency between the output result of the completion model and the test completion result.

[0080] Step 22: If the accuracy is less than the preset accuracy, the parameters of the completion model are optimized to obtain the completion model after parameter tuning as the new completion model.

[0081] Specifically, the preset accuracy is a preset accuracy threshold that can characterize the accuracy of the completion model. For example, the preset accuracy can be 90%. Therefore, if the accuracy is less than the preset accuracy, it means that the accuracy of the completion model is unqualified. At this time, the completion model needs to be parameter tuned, for example, by adjusting the learning rate, batch size (batchsize) and training iterations and other training parameters to adjust the accuracy of the completion results in the vector code data set and the model output, until the accuracy of the completion model is greater than or equal to the preset accuracy. At this time, the obtained completion model is the completion model after parameter tuning, which is used as the new completion model.

[0082] The solution of the present application trains the completion model through a standard code data set, and tunes the parameters according to the accuracy of the completion model after training, so that the accuracy of the completion model is improved, thereby further improving the accuracy of code completion.

[0083] Figure 3 is a schematic diagram of the structure of the code completion device provided by the present application, and the device is suitable for executing the code completion method provided by the present application. Figure 3 As shown, the device may specifically include:

[0084] The acquisition module 301 is used to acquire the target coding environment, the target coding context semantic information and the coding information of the target code.

[0085] The enhancement module 302 is used to input the target coding context semantic information and the coding information of the target code into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on the development data of the development platform corresponding to the target code.

[0086] The completion module 303 is used to input the target coding environment, the enhanced semantic information and the enhanced coding information into a pre-trained completion model to obtain multiple completion codes output by the completion model and a correlation value corresponding to each of the completion codes.

[0087] The determination module 304 is configured to determine a target completion code according to the multiple completion codes and a correlation value corresponding to each of the completion codes, and determine a code completion result according to the target completion code.

[0088] In one embodiment, the device also includes: a database construction module, used to obtain historical development data of the development platform; wherein the historical development data includes multiple code semantic information of the development platform; converting the multiple code semantic information into multiple semantic vector information to construct the vector database.

[0089] In one embodiment, the enhancement module 302 is specifically used to: convert the target coding context semantic information into a context vector, and convert the coding information of the target code into a coding vector; based on the context vector, perform a similarity search in the vector database to obtain the enhanced semantic information; based on the coding vector, perform a similarity search in the vector database to obtain the enhanced coding information.

[0090] In one embodiment, the device also includes: a completion model training module, which is used to obtain a standard code data set, and perform data processing on the standard code data set and convert it into a vector code data set; wherein the vector code data set includes multiple training vector data groups, each of which includes a training coding environment, training semantic vector information, training coding vector information, and training completion results; the model to be trained is trained according to the multiple training coding environments, the multiple training semantic vector information, the multiple training coding vector information, and the multiple training completion results until the training termination condition is reached to obtain the completion model.

[0091] In one embodiment, after the completion model training module obtains the completion model, it is also used to: determine the accuracy of the completion model based on the test coding environment, test semantic vector information, test coding vector information and test completion results; if the accuracy is less than the preset accuracy, the completion model is parameter-tuned to obtain the completion model after parameter tuning as the new completion model.

[0092] In one embodiment, the determination module 304, in terms of determining the target completion code based on the multiple completion codes and the correlation value corresponding to each of the completion codes, is specifically used to: sort the multiple completion codes based on the multiple completion codes and the correlation value corresponding to each of the completion codes; and determine the target completion code based on the completion codes sorted within a preset ranking.

[0093] In one embodiment, the device further includes: a storage module, configured to convert the code completion result into a code completion vector; and store the code completion vector in the vector database.

[0094] The device of the present application obtains the target coding environment, target coding context semantic information and coding information of the target code; inputs the target coding context semantic information and coding information of the target code into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on the development data of the development platform corresponding to the target code; inputs the target coding environment, enhanced semantic information and enhanced coding information into a pre-trained completion model to obtain multiple completion codes output by the completion model and the correlation value corresponding to each completion code; determines the target completion code according to the multiple completion codes and the correlation value corresponding to each completion code, and determines the code completion result according to the target completion code. That is, the scheme of the present application, by inputting the context semantic information and coding information into the vector database established based on the development data of the development platform corresponding to the target code, makes the context semantic information and coding information semantically enhanced, can be more accurately combined with the current development platform, avoids the problem of low accuracy of the completion code generated for specific frameworks and libraries, and improves the applicability and accuracy of code completion.

[0095] The present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the code completion method provided in any of the above embodiments when executing the program.

[0096] The present application also provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the code completion method provided in any of the above embodiments is implemented.

[0097] Reference below Figure 4 , which shows a structural schematic diagram of an electronic device 400 suitable for implementing the present application. Figure 4 The electronic device shown is only an example and should not bring any limitation to the function and scope of use of the present application.

[0098] like Figure 4 As shown, the electronic device 400 includes a central processing unit (CPU) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage part 408 into a random access memory (RAM) 403. In the RAM 403, various programs and data required for the operation of the electronic device 400 are also stored. The CPU 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0099] The following components are connected to the I / O interface 405: an input section 406 including a keyboard, a mouse, etc.; an output section 407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 408 including a hard disk, etc.; and a communication section 409 including a network interface card such as a LAN card, a modem, etc. The communication section 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage section 408 as needed.

[0100] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 409, and / or installed from the removable medium 411. When the computer program is executed by the central processing unit (CPU) 401, the above-mentioned functions defined in the system of the present application are executed.

[0101] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0102] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the above-mentioned module, program segment or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0103] The modules and / or units described in this application may be implemented in software or hardware. The modules and / or units described may also be provided in a processor, for example, may be described as: a processor including an acquisition module, an enhancement module, a completion module, and a determination module. The names of these modules do not, in some cases, constitute limitations on the modules themselves.

[0104] As another aspect, the present application also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device performs the following operations:

[0105] Obtain a target coding environment, target coding context semantic information and coding information of a target code; input the target coding context semantic information and coding information of the target code into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on development data of a development platform corresponding to the target code; input the target coding environment, enhanced semantic information and enhanced coding information into a pre-trained completion model to obtain a plurality of completion codes output by the completion model and a correlation value corresponding to each completion code; determine a target completion code according to the plurality of completion codes and the correlation value corresponding to each completion code, and determine a code completion result according to the target completion code.

[0106] According to the technical solution of the present application, the target coding environment, the target coding context semantic information and the coding information of the target code are obtained; the target coding context semantic information and the coding information of the target code are input into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on the development data of the development platform corresponding to the target code; the target coding environment, the enhanced semantic information and the enhanced coding information are input into a pre-trained completion model to obtain multiple completion codes output by the completion model and the correlation value corresponding to each completion code; the target completion code is determined according to the multiple completion codes and the correlation value corresponding to each completion code, and the code completion result is determined according to the target completion code. That is, the solution of the present application, by inputting the context semantic information and the coding information into the vector database established based on the development data of the development platform corresponding to the target code, the context semantic information and the coding information are semantically enhanced, and can be more accurately combined with the current development platform, avoiding the problem of low accuracy of the completion code generated for specific frameworks and libraries, and improving the applicability and accuracy of code completion.

[0107] An embodiment of the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements a code completion method as provided in any embodiment of the present application.

[0108] In the process of implementation, the computer program product can be written in one or more programming languages ​​or a combination thereof to perform the computer program code of the present application, and the programming language includes an object-oriented programming language, such as Java, Smalltalk, C++, and also includes a conventional procedural programming language, such as "C" language or similar programming language. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).

[0109] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution of this application can be achieved, and this document is not limited here.

[0110] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.

Claims

1. A code completion method, characterized in that: The method comprises: Obtaining target coding environment, target coding context semantic information and coding information of target code; Inputting the target coding context semantic information and the coding information of the target code into a pre-constructed vector database to obtain enhanced semantic information and enhanced coding information; wherein the vector database is established based on development data of a development platform corresponding to the target code; Inputting the target coding environment, the enhanced semantic information and the enhanced coding information into a pre-trained completion model to obtain a plurality of completion codes output by the completion model and a correlation value corresponding to each of the completion codes; A target completion code is determined according to the multiple completion codes and the correlation value corresponding to each of the completion codes, and a code completion result is determined according to the target completion code.

2. The method according to claim 1, characterized in that The vector database is constructed by the following steps: Acquire historical development data of the development platform; wherein the historical development data includes multiple code semantic information of the development platform; The multiple code semantic information are converted into multiple semantic vector information to construct the vector database.

3. The method according to claim 2, characterized in that The step of inputting the target coding context semantic information and the coding information of the target code into a pre-built vector database to obtain enhanced semantic information and enhanced coding information includes: Converting the target coding context semantic information into a context vector, and converting the coding information of the target code into a coding vector; Based on the context vector, performing a similarity search in the vector database to obtain the enhanced semantic information; Based on the coding vector, a similarity search is performed in the vector database to obtain the enhanced coding information.

4. The method according to claim 2, characterized in that: The completion model is trained through the following steps: Obtain a standard code data set, and perform data processing on the standard code data set and convert it into a vector code data set; wherein the vector code data set includes a plurality of training vector data groups, each of which includes a training coding environment, training semantic vector information, training coding vector information, and training completion results; The model to be trained is trained according to the multiple training coding environments, the multiple training semantic vector information, the multiple training coding vector information and the multiple training completion results until a preset training termination condition is reached to obtain the completed model.

5. The method according to claim 4, characterized in that After obtaining the completion model, the method further includes: Determining the accuracy of the completion model according to the test coding environment, the test semantic vector information, the test coding vector information and the test completion result; If the accuracy is less than the preset accuracy, the parameters of the completion model are optimized to obtain the completion model after parameter tuning as the new completion model.

6. The method according to claim 1, characterized in that The determining a target completion code according to the plurality of completion codes and a correlation value corresponding to each of the completion codes comprises: Sorting the multiple completion codes according to the multiple completion codes and the correlation value corresponding to each of the completion codes; A target completion code is determined based on completion codes ranked within a preset ranking.

7. The method according to claim 1, characterized in that The method further comprises: Converting the code completion result into a code completion vector; The code completion vector is stored in the vector database.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the code completion method according to any one of claims 1 to 7 is implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the code completion method according to any one of claims 1 to 7 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements the code completion method according to any one of claims 1 to 7.