RAG-oriented cue word optimization method, system and device

Through a method based on hybrid prompt expert architecture and output-oriented prompt restoration technology, the prompt words in RAG technology are dynamically optimized, solving the problems of time-consuming and insufficient generalization capabilities of prompt strategies in the existing technology, and achieving efficient and accurate information retrieval. and content generation, improving user experience and system adaptability.

CN118673121APending Publication Date: 2024-09-20SHANDONG INSPUR SCI RES INST CO LTD

Patent Information

Application Number
CN202410849238.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-27
Publication Date
2024-09-20

AI Technical Summary

Technical Problem

In the information retrieval process, existing RAG technology has problems such as time-consuming prompting strategies, intensive resources, insufficient generalization capabilities, rigid static design, and balance between efficiency and quality. It is difficult to meet the needs of specific fields or special tasks, and cannot effectively adapt to personalization and dynamics. Contextual Scenario.

Method used

Using the Transformer model based on the hybrid prompt expert architecture, combined with the P-MoE layer and output-oriented prompt restoration technology, it dynamically adjusts and optimizes prompt words, and generates efficient and accurate prompts through user intention understanding, keyword extraction, automated design and feedback iteration. word.

Benefits of technology

It improves user satisfaction and experience, enhances retrieval efficiency and accuracy, reduces information retrieval costs, achieves system flexibility and high-quality content generation, and enhances interpretability and transparency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118673121A
    Figure CN118673121A
Patent Text Reader

Abstract

The invention provides an RAG-oriented cue word optimization method, system and device, and belongs to the technical field of natural language processing. Comprising the following steps: input preprocessing: receiving and processing original input information; user intention understanding: deeply understanding the user intention by using a Transform model based on a hybrid prompt expert architecture; performing output guiding prompt restoration, and reversely deriving prompt or query information triggering output by analyzing an output text generated by the large language model; automatic cue word design is carried out, and cue words are automatically generated and adjusted according to the intention of the user and the restored cue information; and feedback and iterative optimization: collecting user feedback and optimizing a cue word generation strategy. According to the method, the intention of the user is deeply understood, and the prompt content is dynamically adjusted, so that the reply content better meeting the requirement of the user can be generated, and the retrieval efficiency and the accuracy of the generated content are maximized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing, and more particularly to a method, system and device for optimizing prompt words for RAG. Background Art

[0002] At present, RAG technology has demonstrated remarkable capabilities in the fields of question answering, dialogue and text summarization. It successfully integrates the dual advantages of information retrieval and text generation, greatly improving the content quality and response accuracy. However, the full potential of RAG technology is still limited by efficient and accurate prompt strategies, which are crucial for guiding the information retrieval process. The traditional method that relies on manual experience and fixed templates has exposed many limitations: first, it is an extremely time-consuming and resource-intensive process. In the face of rapidly evolving task environments, continuous maintenance and upgrading of templates is a daunting challenge; second, the generalization ability of general templates is insufficient, and it is difficult to fully meet the needs of specific fields or special tasks, causing its retrieval results to often deviate from the target; third, in the face of increasingly personalized and dynamic contextual scenarios, statically designed prompt words appear rigid and lack the necessary adaptability and flexibility, which restricts the wide application and effectiveness of the system; finally, there is a delicate balance between efficiency and quality in prompt word design. Prompts that are too broad or narrow will affect the retrieval effect, and finding the optimal solution between the two has become a major problem. Therefore, in order to overcome the above limitations, the research community urgently needs a prompt word optimization method that can automatically learn and has strong adaptability.

[0003] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention

[0004] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.

[0005] The disclosed embodiments provide a prompt word optimization method, system and device for RAG, which dynamically adjust the prompt content according to task requirements, context environment and user preferences to maximize the retrieval efficiency and the accuracy of generated content.

[0006] In some embodiments, the method comprises:

[0007] Input preprocessing, receiving and processing raw input information, including user queries, conversation history, and knowledge base materials;

[0008] User intent understanding, using a Transformer model based on a hybrid prompt expert architecture to deeply understand user intent. The model is based on the standard Transformer architecture with a P-MoE layer inserted;

[0009] Output-oriented prompt restoration, by analyzing the output text generated by a large language model, reversely inferring the prompt or query information that triggers the output;

[0010] Automated prompt word design automatically generates and adjusts prompt words based on user intent and restored prompt information.

[0011] Preferably, input preprocessing includes: purifying input data to filter out all non-text elements; format consistency processing to standardize the text format and unify text encoding, punctuation, and capitalization; language cleaning and normalization to identify and remove redundant words and stop words, correct spelling errors, and identify synonyms; keyword extraction to extract core keywords and phrases from the processed text.

[0012] Preferably, the P-MoE layer includes an expert component and a sparse gating network; the expert component optimizes the prompt word; the sparse gating network distributes the prompt word to the K expert components with the highest Top-K sparse activation weights, and combines the outputs of each expert component according to the weights to obtain the final prediction result.

[0013] Preferably, the expert components include semantic understanding experts, domain experts, user behavior pattern experts, thought chain prompt experts, multimodal fusion experts, adaptive optimization experts, and knowledge fusion experts.

[0014] Preferably, output-oriented prompt restoration utilizes the output text of a large language model to reversely determine the original prompt through a sparse encoder and a decoder based on a Transformer architecture; the specific method is as follows:

[0015] Given a set of n output sequences y1,...,y generated by a large language model for prompts x′ n , restore the model after output guidance prompts From the output, infer the distribution of the original prompt x″ that has the highest probability of triggering a response

[0016] Each output sequence is processed by a sparse encoder, which focuses on extracting the semantic information of the sequence; all independently encoded sequence representations are concatenated through a concatenation operation to form a comprehensive representation h;

[0017] Input the comprehensive representation h into the decoder based on the Transformer architecture;

[0018] Circuit Training The model is optimized to maximize the probability of correctly recovered cue x″, using a loss function — cross entropy loss that measures the information difference between the probability distribution predicted by the model and the encoding of the true cue;

[0019] The prompt word x′ is reconstructed through the output-oriented prompt restoration model, combined with the conversation context and the information retrieved from the knowledge base, and sent to a large language model for processing to generate high-quality, context-appropriate reply content.

[0020] Preferably, in the automated prompt word design step, various prompt word variants are generated, and synonym replacement and sentence rewriting strategies are adopted; by calculating the relevance score, the prompt word that best matches the user query, context and knowledge base content is selected.

[0021] In some embodiments, the system comprises:

[0022] Input preprocessing module: configured to receive and process raw input information, including user queries, conversation history, and knowledge base materials;

[0023] User Intent Understanding Module: This module is configured to deeply understand user intent using a Transformer model based on a hybrid prompt expert architecture. The model is based on a standard Transformer architecture with a P-MoE layer inserted.

[0024] Output-oriented prompt restoration module: configured to reversely derive the prompt or query information that triggers the output by analyzing the output text generated by the large language model;

[0025] Automatic prompt word design module: configured to automatically generate and adjust prompt words according to user intention and restored prompt information;

[0026] Feedback and iterative optimization module: configured to collect user feedback and optimize the prompt word generation strategy.

[0027] Preferably, in the feedback and iterative optimization module, the system collects direct and indirect feedback from users and uses them as supervisory signals to guide further optimization of the prompt words.

[0028] In some embodiments, the apparatus includes: a processor and a memory storing program instructions, and the processor is configured to execute the RAG-oriented prompt word optimization method when running the program instructions.

[0029] The present disclosure provides a RAG-oriented prompt word optimization method, system, and device, which can achieve the following technical effects:

[0030] By deeply understanding the user's intention and dynamically adjusting the prompt content, the present invention can generate reply content that better meets the user's needs, thereby improving user satisfaction and experience.

[0031] Steps such as input preprocessing and keyword extraction ensure the accuracy and relevance of input information, providing a solid foundation for subsequent prompt word optimization and content generation.

[0032] Through automated prompt word design, feedback and iterative optimization, the system can continuously learn and improve, thereby improving retrieval efficiency and accuracy and reducing the cost of information retrieval.

[0033] The introduction of components such as the Transformer model based on the hybrid prompt expert architecture and the output-oriented prompt restoration model enables the system to intelligently process and analyze input information and generate high-quality prompt words and response content.

[0034] Through output-guided prompt restoration technology, the system can reversely derive the original prompt that triggered the output, thereby enhancing the interpretability and transparency of the system and helping users understand and trust the system's output results.

[0035] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] One or more embodiments are exemplarily described by corresponding drawings, which do not limit the embodiments. Elements with the same reference numerals in the drawings are shown as similar elements, and the drawings do not constitute a scale limitation, and wherein:

[0037] Figure 1 It is a schematic diagram of the process of the present invention.

[0038] Figure 2 Schematic diagram of the hybrid prompt expert (P-MoE) architecture in the Transformer model of the present invention.

[0039] Figure 3 It is a schematic diagram of the output guidance prompt restoration method of the present invention.

[0040] Figure 4 It is a schematic diagram of the device structure provided by an embodiment of the present disclosure. DETAILED DESCRIPTION

[0041] In order to be able to understand the features and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.

[0042] The terms "first", "second", etc. in the description of the embodiments of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so as to describe the embodiments of the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.

[0043] Example 1

[0044] like Figure 1 As shown, a prompt word optimization method for RAG includes:

[0045] S1: Input preprocessing, receiving and processing raw input information, including user queries, conversation history, and knowledge base materials.

[0046] S2: User intent understanding, using a Transformer model based on a hybrid prompt expert architecture to deeply understand user intent. The model is based on the standard Transformer architecture with a P-MoE layer inserted.

[0047] S3: Output-guided prompt restoration, by analyzing the output text generated by a large language model, reversely inferring the prompt or query information that triggers the output.

[0048] S4: Automated prompt word design, automatically generating and adjusting prompt words based on user intent and restored prompt information.

[0049] As a refinement of the above embodiment, in S1, raw input information is received and processed from multiple sources, including query requests x submitted by users, previous conversation histories, and materials retrieved from the knowledge base. These data are preprocessed, including purifying the input data: filtering out all non-text elements, such as web links, special characters, advertising tags, and other interfering information; format consistency processing: formatting the text, unifying text encoding, punctuation, capitalization, etc. Language cleaning and normalization: identifying and removing redundant vocabulary and stop words, while correcting spelling errors and identifying synonyms. Keyword extraction: using natural language processing and information retrieval technology to extract core keywords and phrases from the processed text. Consider word frequency, word importance, and contextual relevance.

[0050] As a refinement of the above embodiment, Figure 2 As shown in Figure 1, a Transformer model based on the hybrid prompt expert (P-MoE) architecture is designed and implemented in S2 to deeply understand user intentions. Specifically, the P-MoE layer is inserted into the basic architecture of the standard Transformer. P-MoE includes multiple experts and a sparse gating network (SGNetwork). Each expert is responsible for performing different optimization processing on the prompt word. The sparse gating network determines which experts should be assigned to each prompt word. Top-K sparsification is used to activate the K experts with the highest weights, and then the outputs of each expert model are combined according to the weights to obtain the final prediction result.

[0051] Expert models include:

[0052] Semantic Understanding Expert (SUE) focuses on understanding the deep semantics of input queries, including context understanding, intent recognition, sentiment analysis, and entity extraction.

[0053] Domain-Specific Expert (DSE): Focuses on specific fields or tasks (such as medical diagnosis, legal consultation, financial analysis, etc.), and generates prompt words that conform to the characteristics of the domain through in-depth understanding of domain knowledge, terminology and logic.

[0054] User Behavior Pattern Expert (UBPE): Analyzes historical user interaction data, understands user preferences, habits, and demand patterns, and generates personalized prompts to adapt to the user's unique interaction style and preferences.

[0055] Chain-of-Thought Expert (COTE) is responsible for building logically clear thinking paths, optimizing decision-making processes, promoting deep understanding and adaptive learning, and improving decision-making quality and user cognitive ability by simulating and guiding orderly reasoning in solving complex problems.

[0056] Multimodal Fusion Expert (MFE) integrates multiple modal information such as text, image, and voice. Multimodal information complements each other and enhances the model's ability to understand complex queries.

[0057] Adaptive Optimization Expert (AOE): monitors operating status and user feedback, dynamically adjusts the working parameters and strategies of each expert model, analyzes multi-dimensional indicators such as processing speed, accuracy, and user satisfaction, and automatically optimizes model weights, algorithm parameters, and resource allocation.

[0058] Knowledge Fusion Expert (KFE) integrates knowledge from different sources, formats and fields to build a unified and dynamically updated knowledge graph. Specifically, it not only integrates the general semantic knowledge parsed by SUE and the professional domain knowledge of DSE, but also includes the user personality preference knowledge analyzed by UBPE and the logical thinking path optimized by COTE.

[0059] Specifically, multiple expert models based on feedforward networks (FFNs) are used. Although the architecture is the same, each model has independent weight parameters to adapt to different task requirements. These expert models are integrated with a gating network, which is also specially trained to understand the relationship between input data and each expert model, and dynamically adjust the weight distribution to achieve adaptive learning. All expert models are executed in parallel, and the activation frequency of each model is intelligently controlled to balance the load, effectively prevent resource overload, reduce computing costs, and enhance overall computing efficiency.

[0060] In the preparation stage, we first built a comprehensive annotated dataset that includes user queries, related prompt words and their corresponding intents. The dataset was strictly cleaned, deduplicated, and standardized to ensure a high-quality training foundation. Then, we used this dataset to train each expert model, and carefully adjusted hyperparameters such as learning rate and batch size to optimize model performance. By continuously monitoring the loss function and validation set performance during the training process, we ensured that the model not only converged smoothly but also had strong generalization capabilities. Training is not limited to the expert model itself, but also includes the gating network, which aims to optimize synchronously and work together to achieve optimal efficiency.

[0061] The outputs of the selected expert models are weighted and aggregated to form the comprehensive output of the MoEFFN layer, which is the expert-optimized prompt word.

[0062] As a refinement of the above embodiment, Figure 3 As shown, in S3, an output-guided prompt restoration method is proposed, which relies on the output text of a large language model (LLM) to reversely determine the prompts or query information that originally triggered these outputs.

[0063] S3-1: Problem setting: Given a set of n output sequences y1,...,y generated by a large language model for prompts x′ n , restore the model after output guidance prompts From these outputs, we can infer the distribution of the original cue x″ that has the highest probability of triggering a response. That is, reverse analysis generates the source information of these outputs.

[0064] S3-1: Feature encoding: Each output sequence is first processed by a specially designed sparse encoder (SEncoder), which focuses on extracting the semantic information of the sequence. Subsequently, all independently encoded sequence representations are concatenated through a concatenation operation to form a comprehensive representation h, that is,

[0065] S3-2: Decoder processing: The comprehensive representation h is input into the decoder based on the Transformer architecture. The decoder has a complex structure, including multiple sublayers such as self-attention, criss-cross attention, and feedforward neural networks. Among them, the information in h plays a key role in the criss-cross attention layer, guiding the model to dynamically focus on the output fragments that are most relevant to the generated prompt x″.

[0066] S3-3: Model optimization and loss calculation: Model The goal is to improve the accuracy of its prediction prompt x″ by optimizing the strategy. The model is optimized to maximize the probability of correctly recovered cue x″. A loss function — cross entropy loss — is used, which measures the information difference between the probability distribution predicted by the model and the encoding of the true cue.

[0067] S3-4: Training loop: In each round of training, the model receives a set of output sequences and their corresponding true prompts By calculating the cross entropy loss between the predicted probability distribution and the actual distribution, the back propagation algorithm is then applied to update the model parameters. This process is repeated until the model parameters converge or the preset stop condition is reached, aiming to continuously improve the model's ability to accurately predict similar inputs. ability.

[0068] S3-5: Prompt reconstruction: The prompt word x′ is reconstructed through the output-oriented prompt restoration model, and then combined with the conversation context and relevant information retrieved from the knowledge base, it is sent to a large language model for processing to generate high-quality, context-appropriate response content.

[0069] As a refinement of the above embodiment, in S4, the knowledge accumulated from the user intent understanding (S2) and output guidance prompt restoration (S3) stages is fully utilized to enhance the generation and adjustment process of prompt words, so as to better adapt to user needs and improve the relevance of search content. This stage includes generating diverse prompt word variants, using strategies such as synonym replacement and sentence rewriting; and then calculating the relevance score to select the prompt word that best fits the user query, context and knowledge base content.

[0070] It also incorporates real-time user feedback, using indicators such as click-through rate and satisfaction ratings to dynamically optimize prompt strategies for personalization and rapid iteration. At the same time, taking into account changes in the external environment, such as time sensitivity and regional characteristics, the generation strategy is dynamically adjusted to ensure the timeliness and situational adaptability of the prompt words. In addition, the performance monitoring mechanism established ensures that optimization measures are continuously adjusted based on user feedback to maintain efficient operation and improve user experience. Finally, the stages S2 to S4 are integrated into a closed-loop cycle to promote continuous self-learning and evolution, accurately grasp user intent, optimize prompt word design, accurately predict and trigger the generation of high-quality content, and thus promote continuous improvement in performance and service quality as a whole.

[0071] To ensure that patterns and trends in new data can be absorbed, the training data set is updated regularly. The new data will include the latest user feedback, industry trends and other information. After the data is updated, the algorithm model is periodically retrained. In particular, the P-MoE architecture in S2 and the output-oriented prompt restoration model in S3 are used to reflect changes in user behavior and updates to the knowledge base.

[0072] It should be noted that the present invention has shown a wide range of applicability, especially in scenarios that require high-precision information retrieval and generation. These scenarios include but are not limited to intelligent customer service, personalized recommendation systems, academic research assistants, and knowledge graph question answering. Each field expects to be able to understand user needs more deeply and provide more accurate and personalized services.

[0073] Example 2

[0074] This embodiment describes in detail the specific process of the method of the present invention in combination with the following specific implementation scenarios.

[0075] Specific example: Li Ming is a heart patient who is using an intelligent medical consultation application to ask questions about his medication adjustment, and the user has frequently inquired about information related to blood pressure management in the past.

[0076] User input:

[0077] "I've been feeling my heart racing lately, and the alpha drug my doctor prescribed doesn't seem to be working. I saw an article saying that beta drug is also effective in controlling high blood pressure and heart rate. Can I try this drug instead?"

[0078] System processing flow:

[0079] 1. Parsing user input

[0080] Keyword recognition: "accelerated heartbeat", "alpha drug", "beta drug", "hypertension", "heart rate".

[0081] Identification of causal relationships: The association between “accelerated heart rate” and “poor effect of α drug”.

[0082] · Comparative identification: comparison between "α-agent" and "β-agent".

[0083] Emotion recognition: “Not very effective” reflects the user’s dissatisfaction with the efficacy of the treatment.

[0084] Expectation Identification: Users want to understand the safety and feasibility of medication substitution.

[0085] 2. Gated Network Allocation:

[0086] Increased weight of SUE: users’ dissatisfaction with drug effects and their intention to try new treatment options.

[0087] Increased DSE weight: Expertise is required to evaluate specialized medical terms such as “heart disease,” “alpha drug,” and “beta drug.”

[0088] UBPE weight increase: Identify users’ continued concern for cardiovascular health and influence the generation of personalized recommendations.

[0089] MFE weight is reduced: Current interactions are entirely text-based, with no information involving other media such as images, videos, or voice.

[0090] COTE weight is moderate and active: The continuous thinking trajectory revealed in the user dialogue, such as from dissatisfaction with the efficacy of existing drugs, to interest in exploring alternative treatment options, to mentioning personal health history, shows a clear thinking path for problem solving and health management model.

[0091] AOE weight is moderate and active: Dynamically adjust the weight distribution of each expert model and optimize the algorithm parameters based on the user's immediate feedback on this communication (such as satisfaction evaluation, follow-up questions, etc.).

[0092] KFE is moderately weighted and active: it integrates information from other expert models and dynamically updates the knowledge graph.

[0093] 3. Experts work together:

[0094] SUE: Analyze user sentiment, identify concerns about current treatment options, and understand their need to seek alternatives.

[0095] DSE: Retrieve information from the medical knowledge base, evaluate the applicable conditions, side effects and interactions of alpha and beta drugs, and generate professional opinions.

[0096] UBPE: Combines user preferences and historical query records to emphasize continuous attention to blood pressure control and provide personalized recommendations.

[0097] COTE: Integrate information from SUE, DSE and UBPE, analyze user needs, combine scientific rigor and user preferences to form a comprehensive decision-making basis. Predict the possible effects of new solutions and user acceptance.

[0098] KFE: Integrate the information of each expert model to build a dynamically updated knowledge graph.

[0099] 4. Output guide prompt restoration:

[0100] "Hello, I have been feeling my heart racing lately, and the alpha drug my doctor prescribed me before doesn't seem to be working well. I read an article that mentioned that beta drugs are also effective in controlling high blood pressure and heart rate. I would like to know if I can consider switching to beta drugs? Can you provide information about the mechanism of action of beta drugs, possible side effects, and precautions when switching drugs? Thank you."

[0101] 5. Content Generation:

[0102] We understand that you are concerned about the effect of using alpha drugs to control your heart rate. Our professional analysis shows that beta drugs, as a common alternative, are effective in improving hypertension and heart function and may be more suitable for your needs. However, we solemnly remind you that the change of drugs must be carried out under the guidance of the attending physician, because individual differences and drug interactions require professional evaluation. Considering your concerns and preferences, we recommend that you have an in-depth discussion with your doctor about the suitability of beta drugs to ensure that the treatment plan is both safe and meets your personal health conditions. At the same time, we emphasize the importance of continuing to pay attention to blood pressure control throughout the treatment journey, and strive to achieve the best health management effect.

[0103] 6. Feedback loop:

[0104] After the user is satisfied with the suggestion and adopts it, he / she informs the system through the feedback mechanism. AOE records this successful interaction and may be more inclined to quickly activate similar expert combinations when encountering similar situations in the future to provide more accurate services.

[0105] Example 3

[0106] A prompt word optimization system for RAG, comprising:

[0107] Input preprocessing module: configured to receive and process raw input information, including user queries, conversation history, and knowledge base materials;

[0108] User Intent Understanding Module: This module is configured to deeply understand user intent using a Transformer model based on a hybrid prompt expert architecture. The model is based on a standard Transformer architecture with a P-MoE layer inserted.

[0109] Output-oriented prompt restoration module: configured to reversely derive the prompt or query information that triggers the output by analyzing the output text generated by the large language model;

[0110] Automatic prompt word design module: configured to automatically generate and adjust prompt words according to user intention and restored prompt information;

[0111] Feedback and iterative optimization module: configured to collect user feedback and optimize the prompt word generation strategy.

[0112] As a refinement of the above embodiment, a closed-loop feedback and iterative optimization mechanism is incorporated into the feedback and iterative optimization module. After generating the output, direct feedback from users (such as satisfaction ratings, clear correct and incorrect indications) and indirect feedback (such as users' subsequent query behaviors, interaction duration, etc.) are collected. These feedback data are fed back to the algorithm model as a supervisory signal to guide the further optimization of the prompt words. By comparing the retrieval effect and content generation quality before and after optimization, the algorithm identifies and learns which adjustments are effective and which need improvement. Based on these insights, the prompt word generation strategy is continuously fine-tuned to achieve self-evolution.

[0113] Combination Figure 4As shown, the embodiment of the present disclosure provides a prompt word optimization device 300 for RAG, including a processor (processor) 304 and a memory (memory) 301. Optionally, the device may also include a communication interface (CommunicationInterface) 302 and a bus 303. The processor 304, the communication interface 302, and the memory 301 may communicate with each other through the bus 303. The communication interface 302 may be used for information transmission. The processor 304 may call the logic instructions in the memory 301 to execute the prompt word optimization method for RAG of the above embodiment.

[0114] In addition, the logic instructions in the memory 301 described above can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.

[0115] The memory 301 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor 304 executes the function application and data processing by running the program instructions / modules stored in the memory 301, that is, implementing the RAG-oriented prompt word optimization method in the above embodiment.

[0116] The memory 301 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 301 may include a high-speed random access memory and may also include a non-volatile memory.

[0117] The embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute the above-mentioned RAG-oriented prompt word optimization method.

[0118] The computer-readable storage medium mentioned above may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.

[0119] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, and other media that can store program codes, or a transient storage medium.

[0120] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent only possible changes. Unless explicitly required, separate components and functions are optional, and the order of operation may vary. The parts and features of some embodiments may be included in or replace the parts and features of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the claims. As used in the description of the embodiments and the claims, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of listings containing one or more associated ones. In addition, when used in the present application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the presence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.

[0121] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. The technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. The technicians may clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0122] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.

[0123] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. 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 consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.

Claims

1. A prompt word optimization method for RAG, characterized in that: include: Input preprocessing, receiving and processing raw input information, including user queries, conversation history, and knowledge base materials; User intent understanding, using a Transformer model based on a hybrid prompt expert architecture to deeply understand user intent. The model is based on the standard Transformer architecture with a P-MoE layer inserted; Output-oriented prompt restoration, by analyzing the output text generated by a large language model, reversely inferring the prompt or query information that triggers the output; Automated prompt word design automatically generates and adjusts prompt words based on user intent and restored prompt information.

2. The RAG-oriented prompt word optimization method according to claim 1, characterized in that: Input preprocessing includes: purifying input data and filtering out all non-text elements; format consistency processing, standardizing the text format, unifying text encoding, punctuation, and capitalization; language cleaning and normalization, identifying and removing redundant words and stop words, correcting spelling errors, and identifying synonyms; keyword extraction, extracting core keywords and phrases from the processed text.

3. The RAG-oriented prompt word optimization method according to claim 1 or 2, characterized in that: The P-MoE layer includes an expert component and a sparse gating network; the expert component optimizes the prompt words; The sparse gating network distributes the prompt words to the K expert components with the highest Top-K sparse activation weights, and combines the outputs of each expert component according to the weights to obtain the final prediction result.

4. The RAG-oriented prompt word optimization method according to claim 3, characterized in that: The expert components include semantic understanding experts, domain experts, user behavior pattern experts, thinking chain prompt experts, multimodal fusion experts, adaptive optimization experts, and knowledge fusion experts.

5. The RAG-oriented prompt word optimization method according to claim 1, characterized in that: Output-guided prompt restoration uses the output text of a large language model to reversely determine the original prompt through a sparse encoder and a decoder based on the Transformer architecture; the specific method is as follows: Given a set of n output sequences generated by a large language model for prompts, the output-guided prompt restoration model infers the distribution of the original prompts with the highest probability of triggering a response from the outputs. Each output sequence is processed by a sparse encoder, which focuses on extracting the semantic information of the sequence; all independently encoded sequence representations are connected in series through the concatenation operation to form a comprehensive representation; The synthesized representation is fed into a decoder based on the Transformer architecture; The restoration model is trained cyclically. The model is optimized to maximize the probability of correctly restoring the original prompt with the highest probability of triggering a response. The loss function - cross entropy loss measures the information difference between the probability distribution predicted by the model and the encoding of the true prompt. The prompts are reconstructed through an output-oriented prompt restoration model, combined with the conversation context and information retrieved from the knowledge base, and fed into a large language model for processing to generate high-quality, contextually appropriate responses.

6. The RAG-oriented prompt word optimization method according to claim 1, characterized in that: In the automated prompt word design step, a variety of prompt word variants are generated, and synonym replacement and sentence rewriting strategies are adopted; by calculating the relevance score, the prompt word that best matches the user query, context, and knowledge base content is selected.

7. A prompt word optimization system for RAGs that executes the method of any one of claims 1 to 6, characterized in that: include: Input preprocessing module: configured to receive and process raw input information, including user queries, conversation history, and knowledge base materials; User Intent Understanding Module: This module is configured to deeply understand user intent using a Transformer model based on a hybrid prompt expert architecture. The model is based on a standard Transformer architecture with a P-MoE layer inserted. Output-oriented prompt restoration module: configured to reversely derive the prompt or query information that triggers the output by analyzing the output text generated by the large language model; Automatic prompt word design module: configured to automatically generate and adjust prompt words according to user intention and restored prompt information; Feedback and iterative optimization module: configured to collect user feedback and optimize the prompt word generation strategy.

8. The RAG-oriented prompt word optimization system according to claim 7, characterized in that: In the feedback and iterative optimization module, the system collects direct and indirect feedback from users and uses it as a supervisory signal to guide further optimization of the prompt words.

9. A prompt word optimization device for RAG, comprising a processor and a memory storing program instructions, characterized in that: The processor is configured to execute the RAG-oriented prompt word optimization method according to any one of claims 1 to 6 when running the program instructions.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the program is executed by a processor, the method described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Intention recognition method and device and electronic equipment

    CN112101044A

  • Intelligent customer service question answering method and system based on large language model

    CN117648420A

  • Response statement generation method and device, electronic equipment and storage medium

    CN117874207A

  • Methods and systems for natural language processing of graph database queries

    US20220414228A1

Cited By

  • Unstructured data processing system based on large language model and vector database

    CN118939848A

  • Control method, device and equipment for retrieving enhanced generative model, and readable medium

    CN119226439A

  • Automatic prompt construction method based on man-machine conversation history and semantic retrieval

    CN119441443A

  • Intelligent Go telling method and system based on multi-modal retrieval enhancement

    CN119494403A

  • Intelligent go playing method and system based on multi-modal retrieval enhancement

    CN119494403B