Retrieval enhancement code generation method and system using dual view embedded vectors

Through the combination of the dual-view embedding vector and the BM25 algorithm, the difficulty in retrieving information with similar semantics but different lexical methods in the prior art is solved, and more accurate Bash code generation is achieved.

CN120523451AActive Publication Date: 2025-08-22UNIV OF SCI & TECH OF CHINA
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202511018026.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-23
Publication Date
2025-08-22
Estimated Expiration
2045-07-23

AI Technical Summary

Technical Problem

Existing code generation models are difficult to generalize to unknown functions or system environments when faced with unfamiliar commands, insufficient recording functions, or rare usage patterns, and traditional vocabulary retrievers cannot effectively capture information with similar semantics but different lexical methods.

Method used

The search enhancement method of dual-view embedding vectors is adopted to generate complementary embeddings of original text and clean text, and combined with the BM25 algorithm and semantic similarity score, the search accuracy is improved through the mixed scoring mechanism.

Benefits of technology

Improves the accuracy and generalization of code generation, especially performs better than existing methods on command-level and token-level metrics, and improves the quality of generating Bash code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120523451A_ABST
    Figure CN120523451A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence and natural language processing, and discloses a retrieval enhancement code generation method and system using double views to embed vectors. The method comprises the following steps: generating two complementary embedding vectors for each Bash document in a knowledge base; calculating a double-view semantic similarity score of each Bash document which is queried by the user and embedded in the knowledge base, and calculating a BM25 lexical similarity score of the Bash document based on a BM25 algorithm; fusing the double-view semantic similarity score and the BM25 lexical similarity score, and sorting the Bash documents according to the obtained final score; and inputting the N Bash documents with the highest final scores and the user query into the large language model to generate a target Bash code. According to the method, a retrieval stage is enhanced by using a dual embedding strategy, and more accurate information related to context is provided for the generator in combination with a BM25 algorithm and semantic similarity, so that the code generation accuracy can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of artificial intelligence and natural language processing, and in particular to a retrieval-enhanced code generation method and system using dual-view embedding vectors. Background Art

[0002] Generating code from natural language (NLP) instructions is a core task in software engineering and programming assistance. The rise of large-scale pre-trained language models (PLMs) has enabled significant progress in translating user intent into executable code. However, existing code generation models often struggle when faced with unfamiliar commands, poorly documented functions, or rare usage patterns, particularly in areas like Bash code generation. Existing code generation models are typically trained on static corpora and, without external support, struggle to generalize to unknown functions or system environments.

[0003] Retrieval-Augmented Generation (RAG) is a code generation framework that retrieves relevant external documents and trains the model on them during inference. RAG allows the model to incorporate up-to-date, task-specific information on demand. For example, when RAG is used to generate Bash code, its concise documentation can significantly improve the quality of the generated code.

[0004] Retrieval-augmented generation (RAG) techniques in code generation typically rely on traditional lexical retrievers, such as the BM25 algorithm, which prioritize matching exact tokens. While effective at matching direct terms, these traditional lexical retrievers often fail to retrieve relevant documents when the query's vocabulary and phrases differ significantly from the knowledge base, posing a serious limitation on capturing semantically similar but lexically different information. The aforementioned challenges have motivated the development of semantic retrieval techniques based on dense embedding models. Semantic retrieval addresses this limitation by mapping query and code knowledge into a shared vector space, enabling the system to capture subtle semantic relationships and retrieve information based on underlying meanings, and generate enhanced code using a variety of context-dependent knowledge. Dense embedding retrieval conceptually bridges the semantic gap between user queries and the most relevant documents, successfully connecting related concepts despite differences in language and structure.

[0005] Despite these advances, lexical and semantic retrieval methods still face a core limitation: they tend to treat a document as a monolithic block of text, failing to account for the different roles played by different types of content. For example, in the Bash command documentation, some paragraphs provide a high-level description of the command behavior, while others list detailed parameter usage enclosed in placeholder symbols (e.g. <filename> , <pkgname>These segments contribute differently to downstream generation: descriptive text supports intent understanding, while placeholders guide syntax and structure. However, existing methods often collapse everything into a single embedding, discarding this important structural distinction. Summary of the Invention

[0006] To address the above technical problems, the present invention provides a method and system for retrieval-enhanced code generation using dual-view embedding vectors. This invention proposes a hybrid retrieval mechanism that combines the advantages of lexical and semantic matching. The invention introduces dual-view embedding, computing two embedding representations for each document: one derived from the original document and the other derived from cleaning placeholder patterns. At query time, the invention scores documents using a weighted combination of the two similarity scores. This approach achieves more nuanced matching through both surface-level phrase alignment and deeper semantic alignment.

[0007] In order to solve the above technical problems, the present invention adopts the following technical solutions: In a first aspect, the present invention provides a retrieval-enhanced code generation method using a dual-view embedding vector, comprising: Generate two complementary embedding vectors for each Bash document in the knowledge base, including the embedding of the original text view and the embedding of the cleaned text view after removing placeholders; Calculate the dual-view semantic similarity score between the user query embedding and each Bash document in the knowledge base. At the same time, calculate the BM25 lexical similarity score of the Bash document based on the BM25 algorithm. The dual-view semantic similarity score is obtained by combining the similarity between the user query embedding and the embedding of the original text view, and the similarity between the user query embedding and the embedding of the cleaned text view. Fusion of the dual-view semantic similarity score and the BM25 lexical similarity score, sorting the Bash documents by the final score; The N Bash documents with the highest final scores and the user query are input into the large language model to generate the target Bash code.

[0008] In one embodiment, generating two complementary embedding vectors for each Bash document in the knowledge base, including an embedding of the original text view and an embedding of the cleaned text view after removing placeholders, specifically includes: For a given Bash document d, construct the original view and clean up the view ; The original view is the unmodified document containing the placeholders; the cleaned view is the document obtained by cleaning the placeholder mode; Will and Input them into the encoder respectively to get the embedding of the original text view and the embedding of the cleaned text view.

[0009] In one embodiment, the and Input them into the encoder respectively to obtain the embedding of the original text view and the embedding of the cleaned text view, specifically including: ; ; is a pre-trained dense encoder from the Nomic-Embed model, is the embedding of the original text view, To clean up the embedding of the text view.

[0010] In one embodiment, calculating the dual-view semantic similarity score between the embedding of the user query and each Bash document in the knowledge base specifically includes: The pre-trained dense encoder based on the Nomic-Embed model calculates the embedding q of the user query; Calculate the cosine similarity between the embedding of the user query and the embedding of the original text view : ; Compute the cosine similarity of the embedding of the user query and the embedding of the cleaned text view : ; Indicates the calculation of cosine similarity; Dual-view semantic similarity score , is the proportionality coefficient.

[0011] In one embodiment, the step of fusing the dual-view semantic similarity score and the BM25 lexical similarity score and sorting the Bash documents according to the final score obtained specifically includes: ; is the final score, is the BM25 lexical similarity score of the Bash document, is the final score of semantic similarity, is the proportionality coefficient, is the embedding of the user query, For the i-th Bash file.

[0012] In a second aspect, the present invention provides a retrieval-enhanced code generation system using dual-view embedding vectors, comprising: The embedding calculation module generates two complementary embedding vectors for each Bash document in the knowledge base, including the embedding of the original text view and the embedding of the cleaned text view after removing placeholders; The similarity calculation module calculates the dual-view semantic similarity score between the user query embedding and each Bash document in the knowledge base, and also calculates the BM25 lexical similarity score of the Bash documents based on the BM25 algorithm. The dual-view semantic similarity score is obtained by combining the similarity between the user query embedding and the embedding of the original text view, and the similarity between the user query embedding and the embedding of the cleaned text view. The sorting module integrates the dual-view semantic similarity score and the BM25 lexical similarity score and sorts the Bash documents according to the final score; The code generation module inputs the N Bash documents with the highest final scores and the user query into the large language model to generate the target Bash code.

[0013] In one embodiment, generating two complementary embedding vectors for each Bash document in the knowledge base, including an embedding of the original text view and an embedding of the cleaned text view after removing placeholders, specifically includes: For a given Bash document d, construct the original view and clean up the view ; The original view is the unmodified document containing the placeholders; the cleaned view is the document obtained by cleaning the placeholder mode; Will and Input them into the encoder respectively to get the embedding of the original text view and the embedding of the cleaned text view.

[0014] In one embodiment, the and Input them into the encoder respectively to obtain the embedding of the original text view and the embedding of the cleaned text view, specifically including: ; ; is a pre-trained dense encoder from the Nomic-Embed model, is the embedding of the original text view, To clean up the embedding of the text view.

[0015] In one embodiment, calculating the dual-view semantic similarity score between the embedding of the user query and each Bash document in the knowledge base specifically includes: The pre-trained dense encoder based on the Nomic-Embed model calculates the embedding q of the user query; Calculate the cosine similarity between the embedding of the user query and the embedding of the original text view : ; Compute the cosine similarity of the embedding of the user query and the embedding of the cleaned text view : ; Indicates the calculation of cosine similarity; Dual-view semantic similarity score , is the proportionality coefficient.

[0016] In one embodiment, the step of fusing the dual-view semantic similarity score and the BM25 lexical similarity score and sorting the Bash documents according to the final score obtained specifically includes: ; is the final score, is the BM25 lexical similarity score of the Bash document, is the final score of semantic similarity, is the proportionality coefficient, is the embedding of the user query, For the i-th Bash file.

[0017] The method of the present invention corresponds to the system, and the specific technical solutions applicable to the method are also applicable to the system.

[0018] Compared with the prior art, the beneficial technical effects of the present invention are: This paper proposes a hybrid retrieval enhancement framework tailored for natural language, specifically for Bash code generation. By enhancing the retrieval phase with a dual embedding strategy and combining it with the BM25 algorithm and semantic similarity, the invention provides the generator with more accurate and contextually relevant information. Experiments demonstrate that the hybrid retrieval enhancement framework consistently outperforms existing methods, such as DocPrompting, particularly on challenging metrics such as command-level accuracy, exact match, and token-level F1.

[0019] Our analysis shows that retrieval quality plays a key role in downstream generation, and that richer retrieval signals are more beneficial for large language models. While additional semantic processing incurs a modest runtime overhead, in applications where correctness is a key metric, the trade-off between correctness and the additional overhead needs to be carefully considered. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 is a flow chart of a method in an embodiment of the present invention; Figure 2 is a schematic diagram of a dual-view retrieval framework in an embodiment of the present invention; Figure 3 A schematic diagram of code generation based on a hybrid retrieval enhancement framework in an embodiment of the present invention; Figure 4 Schematic diagram of a hybrid search enhancement framework in an embodiment of the present invention. DETAILED DESCRIPTION

[0021] A preferred embodiment of the present invention will be described in detail below with reference to the accompanying drawings.

[0022] like Figure 1 and Figure 3 As shown, a retrieval-enhanced code generation method using dual-view embedding vectors includes the following steps: S1, generates two complementary embedding vectors for each Bash document in the knowledge base, including the embedding of the original text view and the embedding of the cleaned text view after removing placeholders; S2: Calculate the dual-view semantic similarity score between the embedding of the user query and each Bash document in the knowledge base, and calculate the BM25 lexical similarity score of the Bash document based on the BM25 algorithm. The dual-view semantic similarity score is obtained by combining the similarity between the embedding of the user query and the embedding of the original text view, and the similarity between the embedding of the user query and the embedding of the cleaned text view. S3, fuses the dual-view semantic similarity score and the BM25 lexical similarity score, and sorts the Bash documents according to the final score; S4, the N Bash documents with the highest final scores and the user query are input into the large language model to generate the target Bash code.

[0023] In response to the limitations of existing retrieval enhancement generation frameworks in Bash code generation, such as insufficient decoupling of document semantics and structural information and the separation of lexical and semantic retrieval, this paper proposes a hybrid retrieval enhancement framework of sparse retrieval and dense semantic retrieval based on an in-depth analysis of the natural language semantics and parameter tag structure characteristics in command descriptions. In dense semantic retrieval, a dual-view embedding strategy is adopted to improve the accuracy and robustness of retrieval, thereby improving the quality and generalization ability of code generation, so as to better meet the needs of automated code generation in complex command line scenarios.

[0024] like Figure 4 As shown in Figure 3, our proposed hybrid retrieval enhancement framework (BashRAG++) improves the retrieval quality of code generation by integrating sparse and dense retrieval signals into a unified retrieval pipeline. Specifically, for each document, we construct a dual-view embedding: one from the original text and the other from a placeholder-removed version that emphasizes structure and descriptiveness. These two views capture the complementary semantics of the same document and are aggregated through a dual-view retrieval framework. To further improve robustness, the generated dual-view semantic similarity score is combined with the traditional BM25 lexical similarity score through a hybrid scoring mechanism. This design enables the retriever to benefit from precise term matching and semantic understanding, ultimately providing the generator with more relevant and diverse contextual information and improving the quality of the generated Bash code.

[0025] 1. Dual-view embedded retrieval: To better capture the semantic richness of Bash documents, this paper proposes a dual-view embedding retrieval strategy. Bash manual pages usually contain placeholders, such as <pkgname>or <command> , which may hinder direct semantic matching with natural language queries. However, simply removing these placeholders completely may result in losing valuable structural or contextual clues. To balance these views, the present invention generates two complementary embeddings for each document and combines their retrieval signals.

[0026] Dual-view embedding construction: Given a document d, we construct two text views: 1) Original view , an unmodified document containing placeholders.

[0027] 2) Clean up the view , obtained by cleaning the document in placeholder mode.

[0028] Placeholder cleanup example. For example, in the cleanup view, something like "apt install <pkgname>" will be converted to "apt install", removing symbolic placeholders that could mislead semantic matching while preserving the executable intent. Another example is "kill <pid>”, it becomes “kill”, emphasizing the action.

[0029] Each view is encoded into its own embedding using the same encoder: ; (1) is the resulting embedding, including the embedding of the original text view and clean up the embedding of the text view ; d is the document that needs to be embedded, including and .

[0030] The encoder is used. In a preferred embodiment, the present invention uses a pre-trained dense encoder from the Nomic-Embed model, which has shown strong performance on semantic retrieval benchmarks. During the retrieval process, the encoder remains frozen to isolate the impact of the retrieval strategy proposed by the present invention.

[0031] Similarly, for user query, the present invention calculates its embedding q: Input the user query into the encoder , and get the embedding of the user query.

[0032] Compute the cosine similarity between the embedding of the user query and the embedding of the text view: ; (2) s is the cosine similarity obtained, including the cosine similarity of the embedding of the user query and the embedding of the original text view Cosine similarity between the embedding of the user query and the embedding of the cleaned text view .

[0033] The two cosine similarities above are combined by weighted average to calculate the dual-view semantic similarity score: ; (3) in, is a scaling factor, λ = 0.5 in the preferred embodiment, giving equal weight to both views. This design allows the retrieval system to jointly benefit from the structural fidelity of the original view and the semantic clarity of the cleaned view.

[0034] The dual-view retrieval framework of the present invention is as follows Figure 2 shown.

[0035] 2. Use BM25 algorithm for hybrid scoring: While the dual-view embedding strategy effectively improves semantic retrieval, traditional sparse retrieval methods like the BM25 algorithm remain competitive in code-related tasks due to their robustness to rare tokens, proper nouns, and command-specific syntax. To further improve retrieval accuracy, this paper employs a hybrid scoring mechanism that integrates sparse (BM25) and dense (dual-view embedding) retrieval signals.

[0036] Given a user query, the present invention retrieves a set of candidate documents { For each document, the present invention calculates: 1) BM25 lexical similarity score ; 2) Dual-view semantic similarity score.

[0037] Calculate the final score: ; (4) is the final score, is the BM25 lexical similarity score of the Bash document, is the final score of semantic similarity, is the proportionality coefficient, is the embedding of the user query, For the i-th Bash file.

[0038] We've found that setting β = 0.05 strikes a good balance between precise keyword matching and semantic alignment. Higher β values ​​can lead to fragile results dominated by word overlap, while over-reliance on dual-view embeddings can miss key command tokens, particularly in short or highly symbolic queries. This hybrid design allows the system to fully leverage both surface-level token overlap (via BM25) and deeper semantic representations (via dual-view embeddings). This technical solution is particularly useful in the Bash domain, where commands often contain both rare keywords and semantically meaningful options or descriptions. By introducing dual-view embeddings and a hybrid scoring pipeline, our hybrid retrieval enhancement framework effectively combines semantic understanding with precise token matching.

[0039] Figure 4 This paper presents the architecture of the proposed hybrid retrieval enhancement framework. The framework improves retrieval accuracy by integrating BM25 techniques and hybrid scoring with dual-view dense embeddings, without requiring additional retriever training. Retrieved documents are then fed into a large frozen-parameter language model for generation. This large language model can be either a decoder-only or encoder-decoder architecture, making the framework plug-and-play between different model families.

[0040] This method is model-agnostic and introduces negligible computational overhead (an additional 11 milliseconds per query). Experiments on a dataset of TLDR (Too Long; Didn't Read)-style Bash code generation demonstrate improvements across all Top-K metrics compared to a search enhancement solution using the BM25 algorithm alone. For example, Top-1 search accuracy increased from 32.2% to 37.1%, and Top-10 search accuracy increased from 58.4% to 64.1%.

[0041] This paper experiments on the TLDR Bash dataset, a benchmark specifically designed for natural language to Bash code generation, introduced in the DocPrompting technology. This dataset contains 9,187 natural language (NL) intent and Bash command pairs, covering 1,879 unique Bash commands, including common commands (e.g., cat, tar) and less common utilities (e.g., faketime, toilet). To evaluate model generalization, the training, development, and test sets are constructed using disjoint sets of command names. The associated document corpus consists of over 400,000 document paragraphs from the Bash manual maintained by the TLDR community. Each document paragraph typically describes a concept or usage (e.g., a parameter flag or command example).

[0042] To evaluate the experimental results, we set up two baselines: no retrieval and retrieval using the DocPrompting technology (specifically, the BM25 algorithm). These baselines were compared with the hybrid retrieval enhancement framework (BashRAG++) proposed in this paper. The code generation results are shown in Table 1.

[0043] Table 1: Code generation results

[0044] To better understand the effectiveness of each component in the retrieval pipeline, we conducted an ablation study by enabling or disabling different signals (the BM25 algorithm, the embeddings of the original text view, and the embeddings of the cleaned text view). In Table 2, BM25 indicates retrieval using only the BM25 algorithm, Raw Embedding indicates retrieval using only the embeddings of the original text view, Clean Embedding indicates retrieval using only the embeddings of the cleaned text view, Raw+Clean indicates retrieval using both the embeddings of the original text view and the embeddings of the cleaned text view, BM25+Raw indicates retrieval using both the BM25 algorithm and the embeddings of the original text view, and BM25+Clean indicates retrieval using both the BM25 algorithm and the embeddings of the cleaned text view.

[0045] As shown in Table 2, across all Top-K metrics, semantic retrieval performance with cleaned text view embeddings (e.g., Top-1 accuracy: 19.2%) consistently outperforms that with raw text view embeddings (e.g., Top-1 accuracy: 17.3%). This validates our hypothesis that text cleansing (removing irrelevant or noisy tokens) enhances the semantic model's ability to match intent and manual content. The combined approach (Raw + Clean) without a lexical basis does not significantly improve upon the cleaned text view embeddings alone, and even slightly underperforms them. This suggests that the information in the raw and cleaned text view embeddings is partially redundant, and simply aggregating them without utilizing lexical structure may introduce noise. On the other hand, combining the BM25 algorithm with either raw or cleaned text view embeddings consistently outperforms either approach alone. For example, the BM25 + Clean approach achieves a Top-1 accuracy of 36.6%, significantly outperforming either the BM25 approach (32.2%) or the Clean approach (19.2%). This demonstrates a strong complementarity between lexical and semantic retrieval signals, where the BM25 algorithm provides high-precision term matching, while embeddings capture underlying intent-level similarity.

[0046] Table 2: Retrieval results in different situations

[0047] Our hybrid retrieval enhancement framework (BashRAG++) integrates the BM25 algorithm with embeddings of both the original and cleaned text views, achieving the highest or second-highest accuracy across all metrics (e.g., 37.1% Top-1, 50.1% Top-3). This demonstrates that dual-view embeddings, when properly grounded in lexical cues, can reinforce each other, resulting in a more robust and accurate retrieval pipeline.

[0048] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times. The order of execution of these steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the steps or stages in other steps.

[0049] Based on the description of the above method embodiments, the present invention also provides a system. The system can be a device that uses the software (application), module, component, server, client, etc. of the method described in the embodiments of this specification and is combined with the necessary implementation hardware. Based on the same innovative concept, the device in one or more embodiments provided by the embodiments of the present disclosure is as described in the following embodiments. Since the implementation scheme of the device to solve the problem is similar to the method, the implementation of the specific device in the embodiments of this specification can refer to the implementation of the aforementioned method, and the repetitions will not be repeated. As used below, the term "module" or "module" is a combination of software and / or hardware that can realize the predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceived.

[0050] A retrieval-enhanced code generation system using dual-view embedding vectors, comprising: The embedding calculation module generates two complementary embedding vectors for each Bash document in the knowledge base, including the embedding of the original text view and the embedding of the cleaned text view after removing placeholders; The similarity calculation module calculates the dual-view semantic similarity score between the user query embedding and each Bash document in the knowledge base, and also calculates the BM25 lexical similarity score of the Bash documents based on the BM25 algorithm. The dual-view semantic similarity score is obtained by combining the similarity between the user query embedding and the embedding of the original text view, and the similarity between the user query embedding and the embedding of the cleaned text view. The sorting module integrates the dual-view semantic similarity score and the BM25 lexical similarity score and sorts the Bash documents according to the final score; The code generation module inputs the N Bash documents with the highest final scores and the user query into the large language model to generate the target Bash code.

[0051] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0052] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above and that the invention can be embodied in other specific forms without departing from the spirit or essential characteristics of the invention. Therefore, the embodiments should be considered in all respects as illustrative and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. It is intended that all variations within the meaning and range of equivalents of the claims be embraced herein, and any reference signs in the claims should not be construed as limiting the claims to which they relate.

[0053] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.< / pid> < / pkgname> < / pkgname> < / pkgname> < / filename>

Claims

1. A retrieval-enhanced code generation method using dual-view embedding vectors, characterized in that include: Generate two complementary embedding vectors for each Bash document in the knowledge base, including the embedding of the original text view and the embedding of the cleaned text view after removing placeholders; Calculate the dual-view semantic similarity score between the embedding of the user query and each Bash document in the knowledge base, and calculate the BM25 lexical similarity score of the Bash document based on the BM25 algorithm; The dual-view semantic similarity score is obtained by combining the similarity between the embedding of the user query and the embedding of the original text view, and the similarity between the embedding of the user query and the embedding of the cleaned text view; Fusion of the dual-view semantic similarity score and the BM25 lexical similarity score, sorting the Bash documents by the final score; The N Bash documents with the highest final scores and the user query are input into the large language model to generate the target Bash code.

2. A retrieval-enhanced code generation method using dual-view embedding vectors according to claim 1, characterized in that: The method generates two complementary embedding vectors for each Bash document in the knowledge base, including the embedding of the original text view and the embedding of the cleaned text view after removing placeholders, specifically including: For a given Bash document d, construct the original view and clean up the view ; The original view is the unmodified document containing the placeholders; the cleaned view is the document obtained by cleaning the placeholder mode; Will and Input them into the encoder respectively to get the embedding of the original text view and the embedding of the cleaned text view.

3. The method for generating retrieval-enhanced code using dual-view embedding vectors according to claim 2, wherein: The said and Input them into the encoder respectively to obtain the embedding of the original text view and the embedding of the cleaned text view, specifically including: ; ; is a pre-trained dense encoder from the Nomic-Embed model, is the embedding of the original text view, To clean up the embedding of the text view.

4. The method for generating retrieval-enhanced code using dual-view embedding vectors according to claim 1, wherein: Calculating the dual-view semantic similarity score between the embedding of the user query and each Bash document in the knowledge base specifically includes: The pre-trained dense encoder based on the Nomic-Embed model calculates the embedding q of the user query; Calculate the cosine similarity between the embedding of the user query and the embedding of the original text view : ; Compute the cosine similarity of the embedding of the user query and the embedding of the cleaned text view : ; Indicates the calculation of cosine similarity; Dual-view semantic similarity score , is the proportionality coefficient.

5. The method for generating retrieval-enhanced code using dual-view embedding vectors according to claim 1, wherein: The fusion of the dual-view semantic similarity score and the BM25 lexical similarity score, and sorting the Bash documents according to the final score obtained, specifically includes: ; is the final score, is the BM25 lexical similarity score of the Bash document, is the final score of semantic similarity, is the proportionality coefficient, is the embedding of the user query, For the i-th Bash file.

6. A retrieval-enhanced code generation system using dual-view embedding vectors, characterized in that include: The embedding calculation module generates two complementary embedding vectors for each Bash document in the knowledge base, including the embedding of the original text view and the embedding of the cleaned text view after removing placeholders; The similarity calculation module calculates the dual-view semantic similarity score between the embedding of the user query and each Bash document in the knowledge base, and also calculates the BM25 lexical similarity score of the Bash document based on the BM25 algorithm; The dual-view semantic similarity score is obtained by combining the similarity between the embedding of the user query and the embedding of the original text view, and the similarity between the embedding of the user query and the embedding of the cleaned text view; The sorting module integrates the dual-view semantic similarity score and the BM25 lexical similarity score and sorts the Bash documents according to the final score; The code generation module inputs the N Bash documents with the highest final scores and the user query into the large language model to generate the target Bash code.

7. A retrieval-enhanced code generation system using dual-view embedding vectors according to claim 6, characterized in that: The method generates two complementary embedding vectors for each Bash document in the knowledge base, including the embedding of the original text view and the embedding of the cleaned text view after removing placeholders, specifically including: For a given Bash document d, construct the original view and clean up the view ; The original view is the unmodified document containing the placeholders; the cleaned view is the document obtained by cleaning the placeholder mode; Will and Input them into the encoder respectively to get the embedding of the original text view and the embedding of the cleaned text view.

8. The retrieval-enhanced code generation system using dual-view embedding vectors according to claim 7, characterized in that: The said and Input them into the encoder respectively to obtain the embedding of the original text view and the embedding of the cleaned text view, specifically including: ; ; is a pre-trained dense encoder from the Nomic-Embed model, is the embedding of the original text view, To clean up the embedding of the text view.

9. The retrieval-enhanced code generation system using dual-view embedding vectors according to claim 6, characterized in that: Calculating the dual-view semantic similarity score between the embedding of the user query and each Bash document in the knowledge base specifically includes: The pre-trained dense encoder based on the Nomic-Embed model calculates the embedding q of the user query; Calculate the cosine similarity between the embedding of the user query and the embedding of the original text view : ; Compute the cosine similarity of the embedding of the user query and the embedding of the cleaned text view : ; Indicates the calculation of cosine similarity; Dual-view semantic similarity score , is the proportionality coefficient.

10. The retrieval-enhanced code generation system using dual-view embedding vectors according to claim 6, characterized in that: The fusion of the dual-view semantic similarity score and the BM25 lexical similarity score, and sorting of the Bash documents by the final score obtained, specifically includes: ; is the final score, is the BM25 lexical similarity score of the Bash document, is the final score of semantic similarity, is the proportionality coefficient, is the embedding of the user query, For the i-th Bash file.

Citation Information

Patent Citations

  • Three-friction stepper for juxtaposedly pushing double piezoelectrics and scanning probe microscope thereof

    CN101521195A

  • Encoder Using Machine-Trained Term Frequency Weighting Factors that Produces a Dense Embedding Vector

    US20200311542A1

  • System and method for performing cross-modal information retrieval using a neural network using learned rank images

    US20210349954A1

  • Neural ranking model for generating sparse representations for information retrieval

    US20230418848A1