Query method based on retrieval enhancement generation, electronic equipment and equipment

By correcting and identifying user problems, generating standardized problem text, and using search results to build prompt words, the problem of low accuracy of pre-trained generative models when generating structured query language codes is solved, achieving higher accuracy and efficiency.

CN119917531AInactive Publication Date: 2025-05-02STATE GRID HEBEI ELECTRIC POWER CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411640757.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-05-02
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The pre-trained generative model is not accurate when generating structured query language codes because it lacks professional knowledge in user problems and understanding of data table structure, and the organization of user problems is flexible and changeable, which interferes with the model's understanding.

Method used

By correcting and identifying the user's problem text, standardized problem text is generated and converted into a problem vector. Then, the similarity between the problem vector and the problem sample vector is calculated, and the first K-bit problem samples with the highest similarity are obtained as the search result. Prompt words are constructed based on these results and entered into a pre-trained generative model to generate a structured query language.

Benefits of technology

By standardizing the problem text and using search results to construct prompt words, we can give full play to the context learning ability of the pre-trained generative model, and significantly improve the accuracy of the structured query language generation and the accuracy of the data query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917531A_ABST
    Figure CN119917531A_ABST
Patent Text Reader

Abstract

The invention discloses a query method based on retrieval enhancement generation, electronic equipment and equipment, and the method comprises the steps: obtaining a first question text, and correcting and recognizing the first question text to obtain a second question text; adding a mask to the second question text to obtain a retrieval question text; converting the retrieval problem text into a problem vector; calculating the similarity between the question vector and each question sample vector, and taking the original questions, answers and table structures corresponding to the first K question sample vectors with the highest similarity as retrieval results; on the basis of the second question text and the retrieval result, a cue word is constructed, the cue word is input into a pre-training generative model, and a structured query language is obtained; and obtaining a data query result according to the structured query language. According to the method, the context learning ability of the pre-training generative model is brought into full play by utilizing a retrieval enhancement generation technology, the accuracy of structured query language generation is improved, and the accuracy of a data query result is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of large language models, and in particular relates to a query method, electronic device, and device based on retrieval enhancement generation. Background Art

[0002] In recent years, the technology and application of large-scale language models have experienced rapid development. A pre-trained generative model is a common large-scale language model that uses dedicated prompt words as input and can automatically generate text, images, codes and other content. The content generation capability of a pre-trained generative model comes from the pre-training process based on massive data. For specific tasks, the pre-trained generative model can achieve better results by adjusting parameters.

[0003] Currently, pre-trained generative models have huge demands for time, computing, storage and other resources during the training phase, which makes it inconvenient to train repeatedly. Since the data in the database management system may change at any time and has a certain sensitivity, the data in the database management system cannot be directly used to train the pre-trained generative model. Therefore, when using the pre-trained generative model for data analysis, it is necessary to rely on the existing database management system and generate structured query language code for data analysis.

[0004] However, the accuracy of directly using the pre-trained generative model to generate structured query language code is not high. The reason is that the pre-trained generative model does not have the potential professional knowledge in the user's questions and lacks understanding of the corresponding data table structure. At the same time, the organization of user questions is flexible and changeable, which interferes with the pre-trained generative model's understanding of the user's question intention. Summary of the invention

[0005] In view of the deficiencies in the prior art, the present invention provides a query method, electronic device, and device based on retrieval enhancement generation.

[0006] In a first aspect, an embodiment of the present invention provides a query method based on retrieval enhancement generation, the method comprising:

[0007] Obtaining a first question text, and correcting and recognizing the first question text to obtain a second question text; adding a mask to the second question text to obtain a search question text;

[0008] Convert the search question text into a question vector; calculate the similarity between the question vector and each question sample vector, and take the original question, answer, and table structure corresponding to the first K question sample vectors with the highest similarity as the search result;

[0009] A prompt word is constructed based on the second question text and the search result, and the prompt word is input into the pre-trained generative model to obtain a structured query language; and a data query result is obtained according to the structured query language.

[0010] Furthermore, the process of correcting and identifying the first question text includes:

[0011] Performing word correction on the first question text, identifying non-standard terms in the first question text, and converting the non-standard terms into standard terms according to a word library; wherein the word library includes non-standard terms, standard terms, and a conversion relationship between the non-standard terms and standard terms;

[0012] The content including time, unit name, indicator name, and question intention in the first question text is identified through word segmentation and part-of-speech tagging. The first question text is regenerated based on the identified content, and the order of appearance of the content including time, unit name, indicator name, and question intention is adjusted to generate a standard second question text.

[0013] Furthermore, the process of adding a mask to the second question text to obtain the search question text includes:

[0014] The time and unit name in the second question text are replaced with different masks to generate a search question text.

[0015] Furthermore, the process of calculating the similarity between the question vector and each question sample vector and taking the original question, answer, and table structure corresponding to the first K question sample vectors with the highest similarity as the retrieval result includes:

[0016] Obtain a sample question library, where each sample in the sample question library is a triple including a question, an answer, and a table structure;

[0017] Adding a mask to each question sample in the sample question library;

[0018] Perform text embedding representation on all the masked question samples to obtain the question sample vector corresponding to each question sample;

[0019] Calculate the similarity between the question vector and each question sample vector, and obtain the top K question sample vectors with the highest similarity;

[0020] The questions, answers, and table structures corresponding to the first K question sample vectors with the highest similarity in the sample question library are taken as retrieval results.

[0021] Furthermore, the prompt words include:

[0022] The first instruction is used to describe an example of the search result;

[0023] The second instruction is used to describe the generation of answers to standard questions.

[0024] Furthermore, the prompt words are:

[0025] / *Given the following questions, answers, and table structure examples* /

[0026] [mth question, mth answer, table structure]

[0027] [nth question, nth answer, table structure]

[0028] …

[0029] / *Give the answer to the following question: [Second question text]* / .

[0030] In a second aspect, an embodiment of the present invention provides a query system based on retrieval enhancement generation, which is used to implement the above-mentioned query method based on retrieval enhancement generation, and the system includes:

[0031] The question parsing module is used to obtain the first question text, and correct and identify the first question text to obtain the second question text; add a mask to the second question text to obtain the search question text;

[0032] The sample retrieval module is used to convert the retrieval question text into a question vector; calculate the similarity between the question vector and each question sample vector, and take the original question, answer, and table structure corresponding to the first K question sample vectors with the highest similarity as the retrieval result;

[0033] The data query module constructs prompt words based on the second question text and the search results, inputs the prompt words into the pre-trained generative model to obtain a structured query language; and obtains data query results according to the structured query language.

[0034] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory and a processor, characterized in that the memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the above-mentioned query method based on retrieval enhancement generation.

[0035] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that when the program is executed by a processor, the above-mentioned query method based on retrieval enhancement generation is implemented.

[0036] In a fifth aspect, an embodiment of the present invention provides a computer program product, including a computer program / instruction, characterized in that when the computer program / instruction is executed by a processor, the above-mentioned query method based on retrieval enhancement generation is implemented.

[0037] Compared with the prior art, the present invention has the following beneficial effects:

[0038] (1) The present invention corrects and identifies the first question text, thereby standardizing the question and reducing the difficulty of understanding the question.

[0039] (2) The present invention converts the search question text into a question vector, calculates the similarity between the question vector and each question sample vector, and takes the original question, answer, and table structure corresponding to the top K question sample vectors with the highest similarity as the search result; the search result is used as a reference question sample to construct prompt words, and the search enhancement generation technology is used to give full play to the context learning ability of the pre-trained generative model, further improve the accuracy of structured query language generation, and improve the accuracy of data query results. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.

[0041] Figure 1 A flowchart of a query method based on retrieval enhancement generation provided by an embodiment of the present invention;

[0042] Figure 2 A flowchart of a query method based on retrieval enhancement generation provided by an embodiment of the present invention;

[0043] Figure 3 A schematic diagram of a sample search process provided by an embodiment of the present invention;

[0044] Figure 4 A schematic diagram of an example of a prompt word provided by an embodiment of the present invention;

[0045] Figure 5 A schematic diagram of a query system based on retrieval enhancement generation provided by an embodiment of the present invention;

[0046] Figure 6 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0047] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0048] It should be noted that, in the absence of conflict, the features in the following embodiments and implementations may be combined with each other.

[0049] like Figure 1 and Figure 2 As shown, an embodiment of the present invention provides a query method based on retrieval enhancement generation, the method comprising the following steps:

[0050] Step S1, obtaining a first question text, and correcting and identifying the first question text to obtain a second question text; adding a mask to the second question text to obtain a search question text.

[0051] Specifically, the first question text is a user question output in natural language text.

[0052] Furthermore, the process of correcting and identifying the first question text to obtain the second question text includes:

[0053] Performing word correction on the first question text, identifying non-standard terms in the first question text, and converting them into standard terms used in a word library; wherein the word library includes non-standard terms, standard terms, and a conversion relationship between the non-standard terms and standard terms;

[0054] The time, unit name, indicator name, question intention and other contents in the first question text are identified through word segmentation, part-of-speech tagging and other technologies. The first question text is regenerated based on the identified content, and the order in which the time, unit name, indicator name, question intention and other contents appear is adjusted to generate a standard second question text.

[0055] Furthermore, the process of adding a mask to the second question text to obtain the search question text includes:

[0056] The time and unit name in the second question text are replaced with different masks to generate a search question text.

[0057] It should be noted that for the user question text, it is necessary to complete word correction, question reconstruction and question masking operations to realize user question parsing; among them, word correction aims to replace non-standard terms in the original question. This operation requires the use of a word library, which stores non-standard terms, standard terms and the conversion relationship between the two; question reconstruction aims to adjust the order of appearance of various elements (time, place, etc.) in the user question so that these elements appear in the specified standard order, thereby facilitating subsequent operations; question masking aims to replace information such as time and unit name with corresponding masks, remove unnecessary detailed information in the sample retrieval process, and generate retrieval question text, thereby improving retrieval efficiency and accuracy.

[0058] Step S2, convert the search question text into a question vector; calculate the similarity between the question vector and each question sample vector, and take the original question, answer, and table structure corresponding to the first K question sample vectors with the highest similarity as the search result.

[0059] Specifically, Figure 3 As shown, step S2 includes:

[0060] The retrieval question text is used as the input of the question text embedding model, and the vector text is output;

[0061] Obtain a sample question library, wherein each sample in the sample question library is a triplet including a question, an answer, and a table structure; illustratively, the sample question library = {(first question, first answer, table structure), (second question, second answer, table structure), (third question, third answer, table structure), ..., [Nth question, Nth answer, table structure]}, where N is the number of samples in the sample question library. The table structure is a table creation statement based on the structured query language.

[0062] Adding a mask to each question sample in the sample question library;

[0063] Input all the masked question samples into the question text embedding model to obtain the question sample vector corresponding to each question sample;

[0064] Calculate the similarity between the question vector and each question sample vector, and obtain the top K question sample vectors with the highest similarity;

[0065] The questions, answers, and table structures corresponding to the first K question sample vectors with the highest similarity in the sample question library are taken as retrieval results.

[0066] Step S3, constructing prompt words based on the second question text and the search results, inputting the prompt words into the pre-trained generative model to obtain a structured query language; and obtaining data query results according to the structured query language.

[0067] Specifically, in the step of constructing the prompt words, in addition to the standard question text and the first K samples, certain instructions should be introduced, including at least two types: a first instruction describing the content of the search results and a second instruction describing the generation of the answer to the standard question. With the help of the prompt words, the pre-trained generative model is used to generate the structured query language code in the code generation step. The structured query language code is input into the database management system to obtain the required data query results.

[0068] Exemplarily, the prompt words are:

[0069] / *Given the following questions, answers, and table structure examples* /

[0070] [mth question, mth answer, table structure]

[0071] [nth question, nth answer, table structure]

[0072] …

[0073] / *Give the answer to the following question: [Second question text]* / .

[0074] Example 1

[0075] Take the power grid data query as an example. Figure 1 and Figure 2 As shown in the figure, this example gives the specific process of the query method based on retrieval enhancement generation, in which the main steps are as follows:

[0076] Step S1, obtaining a first question text, and correcting and identifying the first question text to obtain a second question text; adding a mask to the second question text to obtain a search question text.

[0077] For example, the first question text is "What was the average monthly electricity sales volume of Shigong last year?";

[0078] Correct the words in the question text, identify and convert the non-standard terms in the question text into standard terms. That is, convert "Shigong" into "Shijiazhuang Power Supply Company", convert "last year" into "2023" (assuming this year is 2024), and output the corrected question text, "What is the average monthly electricity sales of Shijiazhuang Power Supply Company in 2023?".

[0079] The corrected question text is reorganized to identify the time, unit name, indicator name, question intention and other contents in the question text. The question text is regenerated based on the identified content, the order in which the above contents appear is adjusted, and the standard second question text is output, "What is the average monthly electricity sales volume of Shijiazhuang Power Supply Company in 2023?".

[0080] Based on the standard second question text, the time and unit name are replaced with different masks according to the predefined mask replacement rules to generate the retrieval question text.

[0081] In this example, the mask replacement rule is to replace the time element with the mask ####, replace the unit name element with the mask &&&&, and the search question text is "What is the average monthly electricity sales volume in &&&& city in #### year?".

[0082] Step S2, taking the search question text as the input of the question text embedding model, and outputting the vector text; calculating the similarity between the question vector and each question sample vector, and taking the original question, answer, and table structure corresponding to the top K question sample vectors with the highest similarity as the search result.

[0083] Specifically, in this example, the question text embedding model includes but is not limited to embedding-v3, Wenxin Yiyan, Tongyi Qianwen, etc.

[0084] A sample question library is obtained, wherein the sample question library contains a large number of samples, each of which is a triple including a question, an answer, and a table structure. Typical sample examples are shown in Table 1 below, where the answer refers to a structured query language based on the table structure.

[0085] Table 1: Sample examples

[0086]

[0087] For each sample in the sample question library, take out the question part and process it according to the mask replacement rule. For example, corresponding to the sample in Table 1, the question becomes "What is the average monthly electricity sales in &&&& city in ####?".

[0088] Input all the masked question samples into the question text embedding model to obtain the question sample vector corresponding to each question sample;

[0089] Calculate the cosine similarity between the question vector and each question sample vector, and obtain the top K question sample vectors with the highest similarity;

[0090] Sort all similarities from large to small, select the top K similarities, and use the questions, answers, and table structures corresponding to the top K question sample vectors with the highest similarity in the sample question library as the retrieval results.

[0091] Step S3, constructing prompt words based on the second question text and the search results, inputting the prompt words into the pre-trained generative model to obtain a structured query language; and obtaining data query results according to the structured query language.

[0092] For example, Figure 4 As shown in the figure, taking the question "What is the average monthly electricity sales of Shijiazhuang Power Supply Company in 2023?" as an example, the constructed prompt words are as follows:

[0093]

[0094]

[0095] In this example, K=4, and four most similar samples are retrieved for the current question, where the “ / *…* / ” part represents the instruction content.

[0096] On the other hand, Figure 5As shown, the present invention also provides a query system based on retrieval enhancement generation, which is used to implement the query method based on retrieval enhancement generation, and the system includes:

[0097] The question parsing module is used to obtain the first question text, and correct and identify the first question text to obtain the second question text; add a mask to the second question text to obtain the search question text;

[0098] The sample retrieval module is used to convert the retrieval question text into a question vector; calculate the similarity between the question vector and each question sample vector, and take the original question, answer, and table structure corresponding to the first K question sample vectors with the highest similarity as the retrieval result;

[0099] The data query module constructs prompt words based on the second question text and the search results, inputs the prompt words into the pre-trained generative model to obtain a structured query language; and obtains data query results according to the structured query language.

[0100] In summary, the present invention gives full play to the contextual learning ability of the pre-trained generative model. In the process of constructing the prompt words, it is necessary to retrieve the K samples that are most similar to the current question as examples for the current question. The pre-trained generative model uses the K samples as a reference to generate the answer to the current question. In terms of practicality, the user only needs to give the query target, and the system can automatically perform problem analysis and data retrieval, which improves the convenience of data retrieval. In terms of scalability, the retrieval process is decoupled from the pre-trained generative model, and there are no additional requirements for the specific model of the pre-trained generative model. At the same time, the change of the retrieval data source can be completed by updating the question sample library, which facilitates the migration between different business data of the present invention.

[0101] The present specification also provides a computer-readable storage medium, which stores a computer program, and the computer program can be used to execute the above-mentioned data synchronization method.

[0102] This manual also provides Figure 6 The schematic structure diagram of the electronic device shown in FIG. Figure 6 As mentioned above, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory and a non-volatile memory, and may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to implement the above data synchronization method.

[0103] Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the executor of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0104] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages ​​and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.

[0105] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.

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

[0107] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0108] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0109] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0110] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0111] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0112] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0113] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0114] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0115] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0116] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

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

[0118] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0119] The above description is only an embodiment of the present specification and is not intended to limit the present specification. For those skilled in the art, the present specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification shall be included in the scope of the claims of the present specification.

Claims

1. A query method based on retrieval enhancement generation, characterized in that: The method comprises: Obtaining a first question text, and correcting and recognizing the first question text to obtain a second question text; adding a mask to the second question text to obtain a search question text; Convert the search question text into a question vector; calculate the similarity between the question vector and each question sample vector, and take the original question, answer, and table structure corresponding to the first K question sample vectors with the highest similarity as the search result; A prompt word is constructed based on the second question text and the search result, and the prompt word is input into the pre-trained generative model to obtain a structured query language; and a data query result is obtained according to the structured query language.

2. A query method based on retrieval enhancement generation according to claim 1, characterized in that: The process of correcting and recognizing the first question text includes: Performing word correction on the first question text, identifying non-standard terms in the first question text, and converting the non-standard terms into standard terms according to a word library; wherein the word library includes non-standard terms, standard terms, and a conversion relationship between the non-standard terms and standard terms; The content including time, unit name, indicator name, and question intention in the first question text is identified through word segmentation and part-of-speech tagging. The first question text is regenerated based on the identified content, and the order of appearance of the content including time, unit name, indicator name, and question intention is adjusted to generate a standard second question text.

3. A query method based on retrieval enhancement generation according to claim 1 or 2, characterized in that: The process of adding a mask to the second question text to obtain the search question text includes: The time and unit name in the second question text are replaced with different masks to generate a search question text.

4. The query method based on retrieval enhancement generation according to claim 1, characterized in that: The process of calculating the similarity between the question vector and each question sample vector and taking the original question, answer, and table structure corresponding to the first K question sample vectors with the highest similarity as the retrieval result includes: Obtain a sample question library, where each sample in the sample question library is a triple including a question, an answer, and a table structure; Adding a mask to each question sample in the sample question library; Perform text embedding representation on all the masked question samples to obtain the question sample vector corresponding to each question sample; Calculate the similarity between the question vector and each question sample vector, and obtain the top K question sample vectors with the highest similarity; The questions, answers, and table structures corresponding to the first K question sample vectors with the highest similarity in the sample question library are taken as retrieval results.

5. The query method based on retrieval enhancement generation according to claim 1, characterized in that: The prompt words include: The first instruction is used to describe an example of the search result; The second instruction is used to describe the generation of answers to standard questions.

6. A query method based on retrieval enhancement generation according to claim 1 or 5, characterized in that: The prompt words are: / *Given the following questions, answers, and table structure examples* / [mth question, mth answer, table structure] [nth question, nth answer, table structure] …… / *Give the answer to the following question: [Second question text]* / .

7. A query system based on retrieval enhancement generation, characterized in that: The system is used to implement the query method based on retrieval enhancement generation as described in any one of claims 1 to 6, comprising: The question parsing module is used to obtain the first question text, and correct and identify the first question text to obtain the second question text; add a mask to the second question text to obtain the search question text; The sample retrieval module is used to convert the retrieval question text into a question vector; calculate the similarity between the question vector and each question sample vector, and take the original question, answer, and table structure corresponding to the first K question sample vectors with the highest similarity as the retrieval result; The data query module constructs prompt words based on the second question text and the search results, inputs the prompt words into the pre-trained generative model to obtain a structured query language; and obtains data query results according to the structured query language.

8. An electronic device, comprising a memory and a processor, characterized in that: The memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the query method based on retrieval enhancement generation as described in any one of claims 1-6 above.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the query method based on retrieval enhancement generation as described in any one of claims 1 to 6 is implemented.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the query method based on retrieval enhancement generation described in any one of claims 1-6 is implemented.

Citation Information

Patent Citations

  • Method and device for processing unanswered questions of smart customer service and computer equipment

    CN112015878A

  • SQL statement automatic generation method and related equipment

    CN116595029A

  • Database query method and device based on natural language, electronic equipment and medium

    CN118093631A

  • Data trend analysis method and device, equipment, storage medium and program product

    CN118227742A

  • Knowledge retrieval enhancement generation method and system based on large language model

    CN118394890A