A large language model prompt word engineering method and system based on multi-round RAG technology

Through multiple rounds of RAG technology, the problem of high cost of training and use of large language models is solved by constructing prompt words and using low-parameter-scale large models, and high-quality inference results and cost-reducing effects are achieved.

CN119761521APending Publication Date: 2025-04-04陈泽暄
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510002052.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-02
Publication Date
2025-04-04

AI Technical Summary

Technical Problem

The training and use of existing large language models is expensive, the computing resource requirements are huge, and the model tuning is complex, making it difficult to iterate quickly and respond to market demand.

Method used

Multi-round RAG technology is used to construct prompt words, and train them through large models with low parameter scale, which significantly improves the knowledge range, recall, accuracy and F1 score of the inference results, thereby reducing the consumption and usage costs of computing resources.

Benefits of technology

It realizes the quality of large model inference results without increasing the scale of training parameters, fine-tuning training, and improving hardware resources, and reducing the cost of using large models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119761521A_ABST
    Figure CN119761521A_ABST
Patent Text Reader

Abstract

The present invention provides a large language model prompt word engineering method and system based on multi-round RAG technology, belonging to the field of artificial intelligence large language models. The present invention constructs a group of prompt words including background knowledge, industry-specific knowledge, and preliminary reasoning results, and inputs the group of prompt words into a large model with a low training parameter scale and no industry-specific knowledge fine-tuning training, so as to significantly improve the knowledge scope, recall rate (Recall), precision rate (Precision) and F1 score (F1 Score) covered by the reasoning results, thereby achieving the same reasoning results. Under the premise of using a large model with a lower parameter scale and less computing resource consumption, the cost of using the large model is reduced; the method and system include a prompt word construction step and a large model question-answering system with low computing power consumption, and the large model question-answering system with low computing power consumption includes: a pre-trained large language model, question-answering system application software and a low-cost general-purpose personal computer running these programs and software.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence large model technology, and in particular to a large language model prompt word engineering method and system based on multi-round RAG technology. Background Art As an important branch of the field of artificial intelligence, Large Language Models (LLM) have experienced rapid development. Through deep learning and massive data training, these models can understand and generate natural language, and show strong summarization, reasoning, and prediction capabilities. The number of parameters of large language models has rapidly increased from hundreds of millions at the beginning to trillions today. In applications in specific industries or fields, large language models need to be deeply customized in combination with industry-specific knowledge and data. Large models in industries including but not limited to medicine, finance, and law can provide more professional and accurate services.

[0003] Existing large model training and usage solutions have huge computing resource demands and high hardware environment requirements. The training and inference process of large language models requires a lot of computing resources, especially high-performance hardware such as GPU or TPU. As the scale of model parameters increases, the required computing power grows exponentially. At the same time, the weights and intermediate results of large model training require a lot of storage space.

[0004] Due to the large scale of parameters, the training process of large language models usually takes weeks or even months. As the parameter scale increases, model tuning becomes more complicated, and researchers need to spend more time and energy to adjust hyperparameters and optimize training strategies, which is not conducive to rapid iteration and rapid response to market demand.

[0005] How to improve the quality of large model inference results and indirectly reduce the cost of using large models without increasing the scale of training parameters, fine-tuning training, or increasing hardware resources is a problem that needs to be solved. Summary of the invention

[0006] In order to solve the above problems, the present invention provides a large language model prompt word engineering method and system based on multi-round RAG technology. The present invention constructs a group of prompt words including background knowledge, industry-specific knowledge, and preliminary reasoning results, and inputs this group of prompt words into a large model with a low training parameter scale and no industry-specific knowledge fine-tuning training. The method can significantly improve the knowledge scope, recall rate (Recall), precision rate (Precision) and F1 score (F1Score) covered by the reasoning results, thereby achieving the same reasoning results under the premise of using a large model with a lower parameter scale and less computing resource consumption, thereby reducing the cost of using the large model.

[0007] The present invention adopts the following technical solutions:

[0008] A large language model prompt word engineering method and system based on multi-round RAG technology, including prompt word construction steps and a large model question-answering system with low computing power consumption: wherein,

[0009] The prompt word construction step is used to construct a large model prompt word to guide the AI ​​system to generate an expected response or perform a specific task;

[0010] The prompt word construction step includes:

[0011] The first step is to obtain the original prompt words;

[0012] The second step is to submit the RAG operation to the original prompt word to obtain an answer from the AI ​​model;

[0013] The third step is to submit a RAG operation for the AI ​​model's answer and obtain the next answer of the AI ​​model;

[0014] Step 4: For the next answer of the AI ​​model, repeat step 3 n times to obtain the nth answer of the AI ​​model;

[0015] Step 5: The nth answer of the AI ​​model and the original prompt word are integrated and processed using a preset final prompt word template to construct a final prompt word;

[0016] In some implementations, the comprehensive satisfaction of the large model reasoning result is set to SAT (Satisfaction), STA∈[0,1];

[0017] Repeat the third step n times, and the relationship between the value of n and STA satisfies:

[0018] SAT = f(n);

[0019] Let SAT = 1, and find n;

[0020] In some implementations, the content of the final prompt word template is: "{original prompt word}, ​​you can refer to the following knowledge: {the first answer of the AI ​​model} and {the nth answer of the AI ​​model}";

[0021] The RAG operation includes:

[0022] Perform text preprocessing on the information input into the RAG operation, segment the text into words, remove meaningless words, and obtain the prompt word text;

[0023] The prompt word text is vectorized to convert the natural language text into a numerical vector, the main purpose of which is to enable the computer to use mathematical and machine learning algorithms to analyze, classify, retrieve and other operations on the text to obtain a vectorized prompt word text;

[0024] Constructing a vector index for the vectorized prompt word text to achieve fast retrieval and obtain a vectorized prompt word text index;

[0025] Calculate the similarity between the vectorized prompt word text index and the knowledge index to obtain similarity values ​​from high to low and the knowledge segments corresponding to the knowledge base;

[0026] For the knowledge segments corresponding to the knowledge base, recall the k segments with the highest similarity;

[0027] In some implementations, the comprehensive satisfaction of the large model reasoning result is set to SAT (Satisfaction), STA∈[0,1];

[0028] The relationship between the value of k, the total number of knowledge segments m in the knowledge base, and STA satisfies:

[0029] SAT = f(k,m);

[0030] Since m is known, let SAT = 1 and find k;

[0031] The original prompt word and the k segments with the highest similarity are integrated and processed using a preset prompt word template to construct a new prompt word;

[0032] In some implementations, the content of the prompt word template is: "Which professional terms or proper nouns are there in {original prompt words}? You can refer to the following knowledge: {k recalled segments}";

[0033] Submitting the AI ​​model to the new prompt word and obtaining the sth answer of the AI ​​model;

[0034] For the s-th answer of the AI ​​model, determine whether s=n? If yes, output the n-th answer of the AI ​​model; if no, submit the RAG operation for the s-th answer of the AI ​​model to obtain the s+1-th answer of the AI ​​model;

[0035] In some embodiments, the text vectorization uses the Bag of Words (BoW) model to represent the text as a fixed-length vector, where each dimension corresponds to a word in the vocabulary and the value is the frequency of the word appearing in the text; or uses TF-IDF (Term Frequency-Inverse Document Frequency) weights, a weighted method based on term frequency and inverse document frequency, to highlight words that frequently appear in the current document but are less common in the entire corpus; or word embeddings, mapping each word to a low-dimensional dense vector space so that semantically similar words are closer in the vector space.

[0036] In some implementations, the constructing of the vector index uses an inverted index, or an approximate nearest neighbor search (ANN), or a locality-sensitive hashing (LSH) to construct the vector index.

[0037] In some embodiments, the similarity is calculated by using cosine similarity to measure the cosine value of the angle between two vectors, where the closer the value is to 1, the more similar they are; using Euclidean distance to measure the straight-line distance between two vectors, where the smaller the value is, the more similar they are; and using Manhattan distance to measure the sum of the absolute differences between two vectors in each dimension.

[0038] The large model question-answering system with low computing power consumption is used to run the large model and supporting software in a low-cost hardware environment to realize user question-answering;

[0039] The large model question answering system with low computing power consumption comprises: a pre-trained large language model, question answering system application software and a low-cost general-purpose personal computer running these programs and software;

[0040] The pre-trained large model is used to provide natural language processing (NLP) services;

[0041] The question-answering system application software includes: a large model operation framework module, a prompt word generation controller module, a RAG engine module, a knowledge base module, and a WebUI interface module;

[0042] The WebUI interface is used to provide interaction between the system and users, including user registration and login function, setting function, large model dialogue function, knowledge base setting function and other related functions;

[0043] The large model operation framework module is used to realize five functions: model loading, prompt word input, computing resource scheduling, reasoning execution, and result output;

[0044] The prompt word generation controller module is used to sequentially execute the prompt word construction steps through a computer program;

[0045] The RAG engine module is used to execute the RAG operations sequentially through a computer program;

[0046] The knowledge base module includes:

[0047] Enter relevant knowledge;

[0048] In some implementations, the relevant knowledge includes: industry background knowledge, professional technical knowledge, news information, and other knowledge that customers need to enter into the knowledge base;

[0049] Performing text preprocessing on the relevant knowledge, dividing the text into words, removing meaningless words, and obtaining knowledge text;

[0050] The knowledge text is vectorized to convert the natural language text into a numerical vector, the main purpose of which is to enable the computer to use mathematics and machine learning algorithms to analyze, classify, retrieve and other operations on the text to obtain vectorized knowledge text;

[0051] Constructing a vector index for the vectorized knowledge text to achieve fast retrieval and obtain a knowledge index;

[0052] In some implementations, let the total cost of the hardware device be: TCH;

[0053] TCH = processor cost + memory cost + graphics card cost + motherboard cost + interface and connection cable cost + I / O device cost + other related equipment cost;

[0054] In some embodiments, the low-cost general-purpose personal computer running these programs and software has the following minimum configurations: processor: 2.4 GHz; memory: 8 GB; graphics card: NVIDIA, video memory: 8 GB. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] The drawings described herein are used to provide a further understanding of the present invention and are not intended to limit the present invention.

[0056] Figure 1 It is an overall schematic diagram of a large language model prompt word engineering method and system based on multi-round RAG technology provided by the present invention.

[0057] Figure 2 It is a flow chart of the specific method of the prompt word construction steps provided by the present invention.

[0058] Figure 3 It is a flow chart of the specific method of RAG operation and knowledge base module provided by the present invention. DETAILED DESCRIPTION

[0059] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0060] See also Figure 1 , Figure 1 is an overall schematic diagram of a large language model prompt word engineering method and system based on multi-round RAG technology provided by the present invention. In some embodiments of the present application, Figure 1 The overall structure of the system includes but is not limited to module S101 to step S108. Figure 1 These eight modules are introduced in detail.

[0061] Module S101 is the WebUI interface provided by the system, which is used to provide interaction between the system and the user, including user registration and login function, setting function, large model dialogue function, knowledge base setting function and other related functions;

[0062] Module S102 is a large model question-answering dialog box provided by the system, which is used for the user to input prompt words, the system to submit the prompt words to the subsequent computer program, display the large model answer, and display the dialogue record;

[0063] Module S103 is a prompt word generation controller provided by the system, which is used to sequentially execute the prompt word construction steps through a computer program;

[0064] Module S104 is the large model operation framework provided by this system, which is used to implement five functions: model loading, prompt word input, computing resource scheduling, reasoning execution, and result output;

[0065] Module S105 is a low-cost hardware environment provided by the system for running the computer program and software system of the present invention;

[0066] Module S106 is a knowledge base provided by the system, which is used for users to input required knowledge and other relevant information;

[0067] Module S107 is a RAG engine provided by the system, which is used to execute the RAG operations sequentially through a computer program;

[0068] Module S108 is a pre-trained large model provided by the system, which is used to provide natural language processing (NLP) services;

[0069] In some implementations, the comprehensive satisfaction of the large model reasoning result is set to SAT (Satisfaction), STA∈[0,1];

[0070] The training parameter scale of the pre-trained large model is PS (Parameter scale);

[0071] The total cost of hardware equipment is: TCH;

[0072] The average response time of the system answer is T;

[0073] Then SAT, PS, TCH, T satisfy: SAT = f (PS, TCH, T);

[0074] Let STA = 1, TCH = 10,000 yuan, T <= 5 seconds, and calculate PS;

[0075] In some embodiments, PS∈[500 million, 7 billion];

[0076] See also Figure 2 , Figure 2 is a flowchart of the specific method of constructing the prompt word provided by the present invention. In some embodiments of the present application, Figure 2 The method includes but is not limited to steps S201 to S204. Figure 2 These four steps are introduced in detail.

[0077] Step S201, obtaining the original prompt word;

[0078] Step S202, submitting the original prompt word to a RAG operation to obtain an answer from the AI ​​model;

[0079] Step S203, one answer of the AI ​​model is marked as the sth answer of the AI ​​model, and a RAG operation is submitted to obtain the s+1th answer of the large model;

[0080] For the next answer of the large model, step S202 is repeated n times to obtain the nth answer of the AI ​​model;

[0081] Step S204, integrating and processing the nth answer of the AI ​​model and the original prompt word using a preset final prompt word template, thereby constructing a final prompt word;

[0082] In some implementations, the comprehensive satisfaction of the large model reasoning result is set to SAT (Satisfaction), STA∈[0,1];

[0083] Repeat the third step n times, and the relationship between the value of n and STA satisfies:

[0084] SAT = f(n);

[0085] Let SAT = 1, and find n;

[0086] In some implementations, the content of the final prompt word template is: "{original prompt word}, ​​you can refer to the following knowledge: {the first answer of the AI ​​model} and {the nth answer of the AI ​​model}";

[0087] See also Figure 3 , Figure 3 is a flow chart of the specific method of RAG operation and knowledge base module provided by the present invention. In some embodiments of the present application, Figure 3 The method includes but is not limited to process S301 to process S319. Figure 3 These 19 processes are introduced in detail.

[0088] Process S301 is to input information of RAG operation;

[0089] Process S302 is used to perform text preprocessing on process S301, segmenting the text into words and removing meaningless words;

[0090] Process S303 is the process S302 to obtain the prompt word text;

[0091] Process S304 is used to vectorize the text in process S303, converting the natural language text into a numerical vector, the main purpose of which is to enable the computer to use mathematical and machine learning algorithms to analyze, classify, retrieve and other operations on the text;

[0092] Process S305 is the vectorized prompt word text obtained in process S304;

[0093] Step S306, constructing a vector index for step S305 to achieve fast retrieval;

[0094] Process S307 is the vectorized prompt word text index obtained in process S306;

[0095] In process S308, similarity calculation is performed on process S307 and process S318 to obtain similarity values ​​from high to low and knowledge segments corresponding to the knowledge base;

[0096] Step S309, integrating and processing the pre-set prompt word template in step S319, thereby constructing a new prompt word;

[0097] In some implementations, the content of the prompt word template is: "Which professional terms or proper nouns are there in {original prompt words}? You can refer to the following knowledge: {k recalled segments}";

[0098] Process S310 is a new prompt word obtained in process S309;

[0099] Process S311 is used to submit the content of process S310 to the AI ​​model.

[0100] Process S312 is the sth answer of the AI ​​model obtained in process S311;

[0101] In process S313, for the parameter s in process S312, execute s=s+1, and judge whether s=n? If yes, proceed to process S314, if not, proceed to process S301;

[0102] Process S314 is the nth answer of the AI ​​model;

[0103] Process S315 is the process in which the user needs to enter relevant knowledge into the system;

[0104] Process S316 is the knowledge text obtained by process S315 after process S302;

[0105] Process S317 is the vectorized knowledge text obtained by process S316 after process S304;

[0106] Process S318 is an index of the knowledge obtained by process S317 after process S306;

[0107] Process S319 is the k segments with the highest similarity obtained in process S308;

[0108] In some embodiments, the text vectorization uses the Bag of Words (BoW) model to represent the text as a fixed-length vector, where each dimension corresponds to a word in the vocabulary and the value is the frequency of the word appearing in the text; or uses TF-IDF (Term Frequency-Inverse Document Frequency) weights, a weighted method based on term frequency and inverse document frequency, to highlight words that frequently appear in the current document but are less common in the entire corpus; or word embeddings, mapping each word to a low-dimensional dense vector space so that semantically similar words are closer in the vector space.

[0109] In some implementations, the constructing of the vector index uses an inverted index, or an approximate nearest neighbor search (ANN), or a locality-sensitive hashing (LSH) to construct the vector index.

[0110] In some embodiments, the similarity is calculated by using cosine similarity to measure the cosine value of the angle between two vectors, where the closer the value is to 1, the more similar they are; using Euclidean distance to measure the straight-line distance between two vectors, where the smaller the value is, the more similar they are; and using Manhattan distance to measure the sum of the absolute differences between two vectors in each dimension.

[0111] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of the present application in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the invention should be included in the scope of protection of the present invention.

Claims

1. A large language model prompt word engineering method and system based on multi-round RAG technology, characterized in that: The method and system include a prompt word construction step and a large model question answering system with low computing power consumption: wherein, The prompt word construction step is used to construct a large model prompt word to guide the AI ​​system to generate an expected response or perform a specific task; The prompt word construction step includes: The first step is to obtain the original prompt words; The second step is to submit the RAG operation to the original prompt word to obtain an answer from the AI ​​model; The third step is to submit a RAG operation for the AI ​​model's answer and obtain the next answer of the AI ​​model; Step 4: For the next answer of the AI ​​model, repeat step 3 n times to obtain the nth answer of the AI ​​model; The fifth step is to integrate and process the nth answer of the AI ​​model and the original prompt word using a pre-set final prompt word template to construct a final prompt word.

2. The RAG operation according to claim 1, characterized in that: Construct a set of prompt words that contain background knowledge, industry-specific knowledge, and preliminary reasoning results, including: Perform text preprocessing on the information input into the RAG operation, segment the text into words, remove meaningless words, and obtain the prompt word text; The prompt word text is vectorized to convert the natural language text into a numerical vector, the main purpose of which is to enable the computer to use mathematical and machine learning algorithms to analyze, classify, retrieve and other operations on the text to obtain a vectorized prompt word text; Constructing a vector index for the vectorized prompt word text to achieve fast retrieval and obtain a vectorized prompt word text index; Calculate the similarity between the vectorized prompt word text index and the knowledge index to obtain similarity values ​​from high to low and the knowledge segments corresponding to the knowledge base; For the knowledge segments corresponding to the knowledge base, recall the k segments with the highest similarity; The original prompt word and the k segments with the highest similarity are integrated and processed using a preset prompt word template to construct a new prompt word; For the new prompt word, submit the AI ​​model and obtain the sth answer of the AI ​​model.

3. The large-model question-answering system with low computing power consumption according to claim 1 is characterized in that: Used to run large models and supporting software in a low-cost hardware environment to implement user questions and answers, including: The large model question answering system with low computing power consumption comprises: a pre-trained large language model, question answering system application software and a low-cost general-purpose personal computer running these programs and software; The pre-trained large model is used to provide natural language processing (NLP) services.

4. The question-answering system application software according to claim 3, characterized in that: include: Large model running framework module, prompt word generation controller module, RAG engine module, knowledge base module, WebUI interface module; The WebUI interface is used to provide interaction between the system and users, including user registration and login function, setting function, large model dialogue function, knowledge base setting function and other related functions; The large model operation framework module is used to realize five functions: model loading, prompt word input, computing resource scheduling, reasoning execution, and result output; The prompt word generation controller module is used to sequentially execute the prompt word construction steps through a computer program; The RAG engine module is used to execute the RAG operations sequentially through a computer program.

5. The knowledge base module according to claim 4, characterized in that: include: Enter relevant knowledge; Performing text preprocessing on the relevant knowledge, dividing the text into words, removing meaningless words, and obtaining knowledge text; The knowledge text is vectorized to convert the natural language text into a numerical vector, the main purpose of which is to enable the computer to use mathematics and machine learning algorithms to analyze, classify, retrieve and other operations on the text to obtain vectorized knowledge text; A vector index is constructed for the vectorized knowledge text to achieve fast retrieval and obtain a knowledge index.

Citation Information

Cited By

  • Multi-model fused vertical domain knowledge question-answering method and system

    CN120336488A